azula.nn.layers¶
Common layers.
Classes¶
Creates a layer that standardizes features along a dimension. |
|
Creates a layer that normalizes features along a dimension. |
|
Creates a ReLU² activation layer. |
|
Creates a sinusoidal positional encoding. |
|
Creates a SwiGLU activation layer. |
Functions¶
Returns an N-dimensional convolutional layer. |
|
Returns a patch-to-channel layer. |
|
Returns a channel-to-patch layer. |
Descriptions¶
- azula.nn.layers.ConvNd(in_channels, out_channels, spatial=2, identity_init=False, **kwargs)¶[source]
Returns an N-dimensional convolutional layer.
- Parameters:
in_channels (int) – The number of input channels \(C_i\).
out_channels (int) – The number of output channels \(C_o\).
spatial (int) – The number of spatial dimensions \(N\).
identity_init (bool) – Initialize the convolution as a (pseudo-)identity.
kwargs – Keyword arguments passed to
torch.nn.Conv2d.
- class azula.nn.layers.LayerNorm(dim, eps=1e-05)¶[source]
Creates a layer that standardizes features along a dimension.
\[y = \frac{x - \mathbb{E}[x]}{\sqrt{\mathbb{V}[x] + \epsilon}}\]References
Layer Normalization (Lei Ba et al., 2016)- Parameters:
- azula.nn.layers.Patchify(patch_shape, channel_last=False)¶[source]
Returns a patch-to-channel layer.
- class azula.nn.layers.RMSNorm(dim, eps=1e-05)¶[source]
Creates a layer that normalizes features along a dimension.
\[y = \frac{x}{\sqrt{\mathbb{E}[x^2] + \epsilon}}\]References
Root Mean Square Layer Normalization (Zhang et al., 2019)- Parameters:
- class azula.nn.layers.ReLU2(*args, **kwargs)¶[source]
Creates a ReLU² activation layer.
\[y = \max(x, 0)^2\]References
Primer: Searching for Efficient Transformers for Language Modeling (So et al., 2021)
- class azula.nn.layers.SineEncoding(features, omega=10000.0)¶[source]
Creates a sinusoidal positional encoding.
\[\begin{split}e_{2i} & = \sin \left( x \times \omega^\frac{-2i}{D} \right) \\ e_{2i+1} & = \cos \left( x \times \omega^\frac{-2i}{D} \right)\end{split}\]References
Attention Is All You Need (Vaswani et al., 2017)- Parameters: