mirror of
https://github.com/labmlai/annotated_deep_learning_paper_implementations.git
synced 2025-08-14 01:13:00 +08:00
144 lines
6.8 KiB
HTML
144 lines
6.8 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
<meta name="description" content="This is a collection of PyTorch implementations/tutorials of transformers and related techniques."/>
|
|
|
|
<meta name="twitter:card" content="summary"/>
|
|
<meta name="twitter:image:src" content="https://avatars1.githubusercontent.com/u/64068543?s=400&v=4"/>
|
|
<meta name="twitter:title" content="Transformers"/>
|
|
<meta name="twitter:description" content="This is a collection of PyTorch implementations/tutorials of transformers and related techniques."/>
|
|
<meta name="twitter:site" content="@labmlai"/>
|
|
<meta name="twitter:creator" content="@labmlai"/>
|
|
|
|
<meta property="og:url" content="https://nn.labml.ai/transformers/index.html"/>
|
|
<meta property="og:title" content="Transformers"/>
|
|
<meta property="og:image" content="https://avatars1.githubusercontent.com/u/64068543?s=400&v=4"/>
|
|
<meta property="og:site_name" content="LabML Neural Networks"/>
|
|
<meta property="og:type" content="object"/>
|
|
<meta property="og:title" content="Transformers"/>
|
|
<meta property="og:description" content="This is a collection of PyTorch implementations/tutorials of transformers and related techniques."/>
|
|
|
|
<title>Transformers</title>
|
|
<link rel="shortcut icon" href="/icon.png"/>
|
|
<link rel="stylesheet" href="../pylit.css">
|
|
<link rel="canonical" href="https://nn.labml.ai/transformers/index.html"/>
|
|
<!-- Global site tag (gtag.js) - Google Analytics -->
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id=G-4V3HC8HBLH"></script>
|
|
<script>
|
|
window.dataLayer = window.dataLayer || [];
|
|
|
|
function gtag() {
|
|
dataLayer.push(arguments);
|
|
}
|
|
|
|
gtag('js', new Date());
|
|
|
|
gtag('config', 'G-4V3HC8HBLH');
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id='container'>
|
|
<div id="background"></div>
|
|
<div class='section'>
|
|
<div class='docs'>
|
|
<p>
|
|
<a class="parent" href="/">home</a>
|
|
<a class="parent" href="index.html">transformers</a>
|
|
</p>
|
|
<p>
|
|
|
|
<a href="https://github.com/lab-ml/labml_nn/tree/master/labml_nn/transformers/__init__.py">
|
|
<img alt="Github"
|
|
src="https://img.shields.io/github/stars/lab-ml/nn?style=social"
|
|
style="max-width:100%;"/></a>
|
|
<a href="https://join.slack.com/t/labforml/shared_invite/zt-egj9zvq9-Dl3hhZqobexgT7aVKnD14g/"
|
|
rel="nofollow">
|
|
<img alt="Join Slact"
|
|
src="https://img.shields.io/badge/slack-chat-green.svg?logo=slack"
|
|
style="max-width:100%;"/></a>
|
|
<a href="https://twitter.com/labmlai"
|
|
rel="nofollow">
|
|
<img alt="Twitter"
|
|
src="https://img.shields.io/twitter/follow/labmlai?style=social"
|
|
style="max-width:100%;"/></a>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div class='section' id='section-0'>
|
|
<div class='docs doc-strings'>
|
|
<div class='section-link'>
|
|
<a href='#section-0'>#</a>
|
|
</div>
|
|
<h1>Transformers</h1>
|
|
<p>This module contains <a href="https://pytorch.org/">PyTorch</a>
|
|
implementations and explanations of original transformer
|
|
from paper <a href="https://arxiv.org/abs/1706.03762">Attention Is All You Need</a>,
|
|
and derivatives and enhancements of it.</p>
|
|
<ul>
|
|
<li><a href="mha.html">Multi-head attention</a></li>
|
|
<li><a href="models.html">Transformer Encoder and Decoder Models</a></li>
|
|
<li><a href="positional_encoding.html">Fixed positional encoding</a></li>
|
|
</ul>
|
|
<h2><a href="xl/index.html">Transformer XL</a></h2>
|
|
<p>This implements Transformer XL model using
|
|
<a href="xl/relative_mha.html">relative multi-head attention</a></p>
|
|
<h2><a href="gpt">GPT Architecture</a></h2>
|
|
<p>This is an implementation of GPT-2 architecture.</p>
|
|
<h2><a href="glu_variants/simple.html">GLU Variants</a></h2>
|
|
<p>This is an implementation of the paper
|
|
<a href="https://arxiv.org/abs/2002.05202">GLU Variants Improve Transformer</a>.</p>
|
|
<h2><a href="knn">kNN-LM</a></h2>
|
|
<p>This is an implementation of the paper
|
|
<a href="https://arxiv.org/abs/1911.00172">Generalization through Memorization: Nearest Neighbor Language Models</a>.</p>
|
|
<h2><a href="feedback">Feedback Transformer</a></h2>
|
|
<p>This is an implementation of the paper
|
|
<a href="https://arxiv.org/abs/2002.09402">Accessing Higher-level Representations in Sequential Transformers with Feedback Memory</a>.</p>
|
|
<h2><a href="switch">Switch Transformer</a></h2>
|
|
<p>This is a miniature implementation of the paper
|
|
<a href="https://arxiv.org/abs/2101.03961">Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity</a>.
|
|
Our implementation only has a few million parameters and doesn’t do model parallel distributed training.
|
|
It does single GPU training but we implement the concept of switching as described in the paper.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre><span class="lineno">52</span><span></span><span class="kn">from</span> <span class="nn">.configs</span> <span class="kn">import</span> <span class="n">TransformerConfigs</span>
|
|
<span class="lineno">53</span><span class="kn">from</span> <span class="nn">.models</span> <span class="kn">import</span> <span class="n">TransformerLayer</span><span class="p">,</span> <span class="n">Encoder</span><span class="p">,</span> <span class="n">Decoder</span><span class="p">,</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">EncoderDecoder</span>
|
|
<span class="lineno">54</span><span class="kn">from</span> <span class="nn">.mha</span> <span class="kn">import</span> <span class="n">MultiHeadAttention</span>
|
|
<span class="lineno">55</span><span class="kn">from</span> <span class="nn">labml_nn.transformers.xl.relative_mha</span> <span class="kn">import</span> <span class="n">RelativeMultiHeadAttention</span></pre></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML">
|
|
</script>
|
|
<!-- MathJax configuration -->
|
|
<script type="text/x-mathjax-config">
|
|
MathJax.Hub.Config({
|
|
tex2jax: {
|
|
inlineMath: [ ['$','$'] ],
|
|
displayMath: [ ['$$','$$'] ],
|
|
processEscapes: true,
|
|
processEnvironments: true
|
|
},
|
|
// Center justify equations in code and markdown cells. Elsewhere
|
|
// we use CSS to left justify single line equations in code cells.
|
|
displayAlign: 'center',
|
|
"HTML-CSS": { fonts: ["TeX"] }
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
</body>
|
|
</html> |