Giter Site home page Giter Site logo

Comments (7)

trevorcai avatar trevorcai commented on May 21, 2024

You can see an example implementation of MultiHeadAttention here:
https://github.com/deepmind/dm-haiku/blob/5457f4b0bf199c336be9021cb3010a1efd2d95da/examples/transformer/model.py#L26

I'd recommend forking that & modifying/simplifying it for your use case.

To explain our thought process a little more:

Since we're on the hook for maintaining modules we put into Haiku, we try to be careful about making sure that the modules inside are canonical and generally agreed upon (at least within DeepMind).

Admittedly, MultiHeadAttention as used in transformers is pretty canonical (except initialization). But any architecture changes people make to attention (e.g. Transformer-XL, sparse attention, all-attention) require changes to the module.

Because most people using transformers at DeepMind want to experiment with changes like these to attention, we think consumption of the canonical MHA will be low (unlike e.g. an LSTM, which very few people are modifying these days).

We've similarly discussed whether we should promote a transformer implementation to hk.nets, like we have for ResNet-50.
The annoying thing about transformers is that people's idea of what "canonical" is varies based on their use case - where does the layer norm go (residual or main path?); how should we initialize, etc.

Overall, we think there's sufficient movement in the field re: ideal transformer architecture and attention mechanisms and sufficient diversity re: expected canonical implementation that we've decided not to make a canonical one. Instead, we recommend folks to fork from our examples, or other existing codebases.

Does that make sense? WDYT?

from dm-haiku.

cgarciae avatar cgarciae commented on May 21, 2024

I think this makes sense to not to make it official until its stable, yet given PyTorch and Tensorflow Addons (I contributed this one) do have at least placeholder implementations it would be good to provide something. Maybe consider an hk.experimental module or a haiku-addons repo?

from dm-haiku.

trevorcai avatar trevorcai commented on May 21, 2024

Thanks for the feedback - I appreciate it!

I'm personally onboard with the value proposition of tensorflow-addons - but I don't think either Tom or I have bandwidth to support a Haiku equivalent right now.
(My understanding is that maintaining tf.contrib was quite a bit of work for the TF team.)

It seems like forking (or directly importing from) the examples hits 90% efficacy for our core use case (supporting deep learning research in JAX), so I'm inclined to keep the status quo here.

Please reopen if you think this is misguided!

from dm-haiku.

trevorcai avatar trevorcai commented on May 21, 2024

I've been convinced by helpful colleagues that my thinking on this is misguided! We're standing by the "no canonical transformer" thinking, but are open to having a MHA implementation in core Haiku.

from dm-haiku.

cgarciae avatar cgarciae commented on May 21, 2024

@trevorcai Nice! Can I start a PR with this?

from dm-haiku.

trevorcai avatar trevorcai commented on May 21, 2024

We have some well-proven implementations internally. When I get the chance, I'll move one into Haiku core.

from dm-haiku.

trevorcai avatar trevorcai commented on May 21, 2024

Sorry for the wait, we upstreamed one here:
https://github.com/deepmind/dm-haiku/blob/610a574c54c78ca71a9a1213bdaff9de189555d4/haiku/_src/attention.py

from dm-haiku.

Related Issues (20)

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.