dhruvramani / transformers-rl Goto Github PK
View Code? Open in Web Editor NEWAn easy PyTorch implementation of "Stabilizing Transformers for Reinforcement Learning"
License: MIT License
An easy PyTorch implementation of "Stabilizing Transformers for Reinforcement Learning"
License: MIT License
A question about the function update_memory in layers.py line269
May I ask, is there any difference between writing this way by cat and appending the hidden_states directly to the new_memory?
Maybe it’s a detail somewhere I didn’t notice,Thanks.
with torch.no_grad():
new_memory = []
end_idx = mem_len + seq_len
beg_idx = max(0, end_idx - mem_len)
for m, h in zip(previous_memory, hidden_states):
cat = torch.cat([m, h], dim=0)
new_memory.append(cat[beg_idx:end_idx].detach())
with torch.no_grad():
new_memory = []
for h in hidden_states:
new_memory.append(h.detach())
If my observation is an image of shape (4, 84, 84), and action dim is 3, so how to modify the code below?
if __name__ == '__main__':
states = torch.randn(1,1, 4) # seq_size, batch_size, dim - better if dim % 2 == 0
print("=> Testing Policy")
policy = TransformerGaussianPolicy(state_dim=states.shape[-1], act_dim=4)
for i in range(10):
act = policy(states)
action = act[0].sample()
print(torch.isnan(action).any(), action.shape)
At first, thanks for the great implementation.
I found that this initialization is somewhat critical:
Line 256 in fc3d8af
It may occur that self.u and self.v will be initialized containing nan. Eventually, this leads to everything becoming nan.
I found 2 bugs in transformer-xl code layers.py
.
Lines 261 to 268 in 337d84a
def init_memory(self, device=torch.device("cpu")):
return [
torch.empty(0, dtype=torch.float).to(device)
for _ in range(self.n_layers + 1)
]
Lines 280 to 288 in 337d84a
new_memory = []
end_idx = mem_len + seq_len
# self.mem_len is the length of memory retention length. It is different with mem_len.
beg_idx = max(0, end_idx - self.mem_len)
After fixing these bugs above, the memory mechanism still caused incorrect values. I compared the output of the transformer with and without the memory mechanism, and they are totally different.
I tried another stable-transformer code from this repo. If anyone wants to fix this further, he can refer to this code.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.