Code Monkey home page Code Monkey logo

functional-transformer's People

Contributors

awf avatar

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

functional-transformer's Issues

Make value heads nonsquare and add back head concatenation

As noted in #6 the model does not match the original code, or indeed the original transformer paper. I therefore consider this a "transformer variant", but of course it would be sensible to make it match and check if that improves/disimproves performance.

Initialization of positional encodings?

Hi there. Great work!

I shared this with a colleague and they were concerned that your example does not seem to initialize the positional encodings beyond zeros.

Should there be a comment or an implementation of setting up the positional encoding?

Implementation of Attention is wrong.

image

Mistake 1. The attention heads are all summed together; they should be concatenated (see code and image of attention equation).

Mistake 2. After the missing concatenation there should have been another linear layer (see code and image of attention equation).

Note. Using a for-loop for heads doesn't seem to be efficiently compiled by Jax.

Note. The weight initialization is different to minGPT.

Code: https://github.com/awf/functional-transformer/blob/e44f4606efd663b0c6454d81010f536966dbd990/transformer.py#L161C9-L180C69

# Multi-head self-attention
for head in layer.heads:

    # Project into this head's query/key space
    query = linear(head.query, t1)                  # L x Dk
    key = linear(head.key, t1)                      # L x Dk

    # Compute L x L attention matrix
    score = query @ key.T + mask                    # L x L
    attn = jax.nn.softmax(cfg.tau * score, axis=1)  # L x L

    value = linear(head.value, t1)                  # L x Dm
    self_attn = attn @ value                        # L x Dm

    # Add this head's contribution into embeddings
    embeddings += self_attn                         # L x Dm     <---- sum instead of concatenate
    
# <-- after concatenating all attention heads there should be another linear layer here. 

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.