概述|快速安装|亚麻是什么样的? |文档
Flax NNX于2024年发布,是一种新的简化亚麻API,旨在使创建,检查,调试和分析JAX中的神经网络更容易。它通过添加对Python参考语义的一流支持来实现这一目标。这允许用户使用常规的Python对象表达其模型,从而实现参考共享和变异性。
亚麻NNX源自亚麻亚麻API,该API于2020年由Google Brain与JAX团队密切合作于2020年发布。
您可以在专用亚麻文档网站上了解有关亚麻NNX的更多信息。确保您退房:
注意:亚麻亚麻的文档具有自己的网站。
亚麻小组的使命是为不断增长的JAX神经网络研究生态系统服务 - 在字母内和更广泛的社区,并探索JAX闪耀的用例。我们将GitHub用于几乎所有的协调和计划,以及我们讨论即将进行的设计变化的地方。我们欢迎对我们的任何讨论,发出和拉请求线程的反馈。
您可以提出功能请求,让我们知道您在做什么,报告问题,在我们的亚麻github讨论论坛中提出问题。
我们期望改善亚麻,但我们预计核心API不会发生重大的破坏变化。如果可能,我们使用ChangElog条目和折旧警告。
如果您想直接与我们联系,我们访问[email protected]。
亚麻是一个高性能的神经网络库和JAX的生态系统,是为灵活性而设计的:通过分叉示例和修改训练环,而不是在框架中添加功能来尝试新形式的培训形式。
Flax正在与JAX团队密切合作开发,并提供您开始研究所需的一切,包括:
神经网络API ( flax.nnx
):包括Linear
, Conv
, BatchNorm
, LayerNorm
, GroupNorm
,注意力( MultiHeadAttention
), LSTMCell
,GRUCELL, GRUCell
, Dropout
。
实用程序和模式:复制的培训,序列化和检查点,指标,预取设备。
教育示例:使用Gemma语言模型(变压器),Transformer LM1B进行推理/采样。
亚麻使用JAX,因此请查看CPU,GPU和TPU上的JAX安装说明。
您将需要python 3.8或更高版本。从PYPI安装亚麻:
pip install flax
要升级到最新版本的亚麻,您可以使用:
pip install --upgrade git+https://github.com/google/flax.git
要安装一些需要但不包括某些依赖项所需的其他依赖项(例如matplotlib
),您可以使用:
pip install " flax[all] "
我们使用亚麻API提供了三个示例:一个简单的多层感知器,CNN和一个自动编码器。
要了解有关Module
抽象的更多信息,请查看我们的文档,该文档是模块抽象的广泛介绍。有关最佳实践的其他具体演示,请参阅我们的指南和开发人员笔记。
MLP的示例:
class MLP ( nnx . Module ):
def __init__ ( self , din : int , dmid : int , dout : int , * , rngs : nnx . Rngs ):
self . linear1 = Linear ( din , dmid , rngs = rngs )
self . dropout = nnx . Dropout ( rate = 0.1 , rngs = rngs )
self . bn = nnx . BatchNorm ( dmid , rngs = rngs )
self . linear2 = Linear ( dmid , dout , rngs = rngs )
def __call__ ( self , x : jax . Array ):
x = nnx . gelu ( self . dropout ( self . bn ( self . linear1 ( x ))))
return self . linear2 ( x )
CNN的示例:
class CNN ( nnx . Module ):
def __init__ ( self , * , rngs : nnx . Rngs ):
self . conv1 = nnx . Conv ( 1 , 32 , kernel_size = ( 3 , 3 ), rngs = rngs )
self . conv2 = nnx . Conv ( 32 , 64 , kernel_size = ( 3 , 3 ), rngs = rngs )
self . avg_pool = partial ( nnx . avg_pool , window_shape = ( 2 , 2 ), strides = ( 2 , 2 ))
self . linear1 = nnx . Linear ( 3136 , 256 , rngs = rngs )
self . linear2 = nnx . Linear ( 256 , 10 , rngs = rngs )
def __call__ ( self , x ):
x = self . avg_pool ( nnx . relu ( self . conv1 ( x )))
x = self . avg_pool ( nnx . relu ( self . conv2 ( x )))
x = x . reshape ( x . shape [ 0 ], - 1 ) # flatten
x = nnx . relu ( self . linear1 ( x ))
x = self . linear2 ( x )
return x
自动编码器的示例:
Encoder = lambda rngs : nnx . Linear ( 2 , 10 , rngs = rngs )
Decoder = lambda rngs : nnx . Linear ( 10 , 2 , rngs = rngs )
class AutoEncoder ( nnx . Module ):
def __init__ ( self , rngs ):
self . encoder = Encoder ( rngs )
self . decoder = Decoder ( rngs )
def __call__ ( self , x ) -> jax . Array :
return self . decoder ( self . encoder ( x ))
def encode ( self , x ) -> jax . Array :
return self . encoder ( x )
引用这个存储库:
@software{flax2020github,
author = {Jonathan Heek and Anselm Levskaya and Avital Oliver and Marvin Ritter and Bertrand Rondepierre and Andreas Steiner and Marc van {Z}ee},
title = {{F}lax: A neural network library and ecosystem for {JAX}},
url = {http://github.com/google/flax},
version = {0.10.2},
year = {2024},
}
在上面的Bibtex条目中,名称按字母顺序排列,版本编号的目的是从flax/version.py中使用,这一年对应于项目的开源版本。
亚麻是由Google DeepMind的专门团队维护的开源项目,但不是官方的Google产品。