Giter Club home page Giter Club logo

transformers-rl's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

transformers-rl's Issues

A question about the function update_memory

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())

How to combine it with PPO algorithm?

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)

Bugs report about memory mechanism

I found 2 bugs in transformer-xl code layers.py.

  1. The init_mem function uses an incorrect shape.

    Transformers-RL/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)
    torch.zeros(20, 5, 8, dtype=torch.float).to(device)
    for _ in range(self.n_layers + 1)
    ]
def init_memory(self, device=torch.device("cpu")): 
     return [ 
         torch.empty(0, dtype=torch.float).to(device) 
         for _ in range(self.n_layers + 1) 
     ] 
  1. The calculation of the beginning index in update_mem is incorrect.

    Transformers-RL/layers.py

    Lines 280 to 288 in 337d84a

    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())
    return new_memory
            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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.