Google JAX

Google JAX,是Google开发的用于变换数值函数的Python机器学习框架[3][4][5]。它结合了修改版本的Autograd(自动通过函数的微分获得其梯度函数)[6],和TensorFlow的XLA(加速线性代数[7]。它被设计为尽可能的遵从NumPy的结构和工作流程,并协同工作于各种现存的框架如TensorFlowPyTorch[8][9]

JAX
開發者Google
首次发布2019年10月31日,​4年前​(2019-10-31[1]
当前版本
  • 0.4.24 (2024年2月6日;穩定版本)[2]
編輯維基數據鏈接
源代码库github.com/google/jax
编程语言Python, C++
操作系统Linux, macOS, Windows
平台Python, NumPy
类型机器学习
许可协议Apache 2.0
网站jax.readthedocs.io/en/latest/ 编辑维基数据

主要功能编辑

JAX的主要功能是[3]

grad编辑

下面的代码演示grad函数的自动微分。

# 导入库from jax import gradimport jax.numpy as jnp# 定义logistic函数def logistic(x):      return jnp.exp(x) / (jnp.exp(x) + 1)# 获得logistic函数的梯度函数grad_logistic = grad(logistic)# 求值logistic函数在x = 1处的梯度 grad_log_out = grad_logistic(1.0)   print(grad_log_out)

最终的输出为:

0.19661194

jit编辑

下面的代码演示jit函数的优化。

# 导入库from jax import jitimport jax.numpy as jnp# 定义cube函数def cube(x):    return x * x * x# 生成数据x = jnp.ones((10000, 10000))# 创建cube函数的jit版本jit_cube = jit(cube)# 应用cube函数和jit_cube函数于相同数据来比较其速度cube(x)jit_cube(x)

可见jit_cube的运行时间显著的短于cube

vmap编辑

下面的代码展示vmap函数的通过SIMD的向量化。

# 导入库from functools import partialfrom jax import vmapimport jax.numpy as jnp# 定义函数def grads(self, inputs):    in_grad_partial = partial(self._net_grads, self._net_params)    grad_vmap = vmap(in_grad_partial)    rich_grads = grad_vmap(inputs)    flat_grads = np.asarray(self._flatten_batch(rich_grads))    assert flat_grads.ndim == 2 and flat_grads.shape[0] == inputs.shape[0]    return flat_grads

pmap编辑

下面的代码展示pmap函数的对矩阵乘法的并行化。

# 从JAX导入pmap和random;导入JAX NumPyfrom jax import pmap, randomimport jax.numpy as jnp# 生成2个维度为5000 x 6000的随机数矩阵,每设备一个random_keys = random.split(random.PRNGKey(0), 2)matrices = pmap(lambda key: random.normal(key, (5000, 6000)))(random_keys)# 没有数据传输,并行的在每个CPU/GPU上进行局部矩阵乘法 outputs = pmap(lambda x: jnp.dot(x, x.T))(matrices)# 没有数据传输,并行的在每个CPU/GPU上分别求取这两个矩阵的均值means = pmap(jnp.mean)(outputs)print(means)

最终的输出为:

[1.1566595 1.1805978]

使用JAX的库编辑

一些Python库使用JAX作为后端,这包括:

参见编辑

引用编辑

  1. ^ jax-v0.1.49. 
  2. ^ https://github.com/google/jax/releases/tag/jax-v0.4.24.
  3. ^ 3.0 3.1 Bradbury, James; Frostig, Roy; Hawkins, Peter; Johnson, Matthew James; Leary, Chris; MacLaurin, Dougal; Necula, George; Paszke, Adam; Vanderplas, Jake; Wanderman-Milne, Skye; Zhang, Qiao, JAX: Autograd and XLA, Astrophysics Source Code Library (Google), 2022-06-18 [2022-06-18], Bibcode:2021ascl.soft11002B, (原始内容存档于2022-06-18) 
  4. ^ Frostig, Roy; Johnson, Matthew James; Leary, Chris. Compiling machine learning programs via high-level tracing (PDF). MLsys. 2018-02-02: 1–3. (原始内容存档 (PDF)于2022-06-21). 
  5. ^ Using JAX to accelerate our research. www.deepmind.com. [2022-06-18]. (原始内容存档于2022-06-18) (英语). 
  6. ^ autograd. [2023-09-23]. (原始内容存档于2022-07-18). 
  7. ^ XLA. [2023-09-23]. (原始内容存档于2022-09-01). 
  8. ^ Lynley, Matthew. Google is quietly replacing the backbone of its AI product strategy after its last big push for dominance got overshadowed by Meta. Business Insider. [2022-06-21]. (原始内容存档于2022-06-21) (美国英语). 
  9. ^ Why is Google's JAX so popular?. Analytics India Magazine. 2022-04-25 [2022-06-18]. (原始内容存档于2022-06-18) (美国英语). 
  10. ^ Flax: A neural network library and ecosystem for JAX designed for flexibility, Google, 2022-07-29 [2022-07-29], (原始内容存档于2022-09-03) 
  11. ^ Kidger, Patrick, Equinox, 2022-07-29 [2022-07-29], (原始内容存档于2023-09-19) 
  12. ^ Kidger, Patrick, Diffrax, 2023-08-05 [2023-08-08], (原始内容存档于2023-08-10) 
  13. ^ Optax, DeepMind, 2022-07-28 [2022-07-29], (原始内容存档于2023-06-07) 
  14. ^ Lineax, Google, 2023-08-08 [2023-08-08], (原始内容存档于2023-08-10) 
  15. ^ RLax, DeepMind, 2022-07-29 [2022-07-29], (原始内容存档于2023-04-26) 
  16. ^ Jraph - A library for graph neural networks in jax., DeepMind, 2023-08-08 [2023-08-08], (原始内容存档于2022-11-23) 
  17. ^ jaxtyping, Google, 2023-08-08 [2023-08-08], (原始内容存档于2023-08-10) 
  18. ^ NumPyro - Probabilistic programming with NumPy powered by JAX for autograd and JIT compilation to GPU/TPU/CPU. [2022-08-31]. (原始内容存档于2022-08-31). 
  19. ^ Brax - Massively parallel rigidbody physics simulation on accelerator hardware. [2022-08-31]. (原始内容存档于2022-08-31). 

外部链接编辑


🔥 Top keywords: Baike: 首页Special:搜索九龍城寨之圍城胖猫跳江事件Energy (組合)淚之女王背着善宰跑逆天奇案2金智媛习近平郭葦昀金秀賢 (男演員)不夠善良的我們九龍寨城邊佑錫伍允龍春色寄情人劉俊謙 (香港)張書偉怪獸8號虽然不是英雄葉乃文謝坤達神耆小子六四事件我的婆婆怎麼那麼可愛排球少年!!角色列表唐振剛2024年湯姆斯盃Seventeen (組合)蕭景鴻排球少年!!WIND BREAKER—防風少年—安東尼·愛德華茲 (籃球運動員)ILLIT中华人民共和国中華民國BABYMONSTER與鳳行張文傑BOYNEXTDOOR彭丽媛笑看風雲日本母亲节习明泽金惠奫徐巧芯從Lv2開始開外掛的前勇者候補過著悠哉異世界生活德雷克 (歌手)搜查班長1958支配物种乘風2024張員瑛承欢记嚴爵香港梅龍高速公路塌陷事故柯建銘葬送的芙莉蓮迷宮飯轉生貴族憑鑑定技能扭轉人生~繼承弱小領土後,招募優秀人才打造最強領土~为人民服务 (2022年电影)黃道十二宮IVE (組合)草榴社区歐倩怡沒有秘密周雨彤柯佳嬿無職轉生~到了異世界就拿出真本事~謝京穎埃马纽埃尔·马克龙破墓周處除三害 (電影)許瑋甯Twitter五月天打天下2逆天奇案李主儐大谷翔平家族榮耀之繼承者胡子彤郭晉安毛泽东Baike: 分類索引沈伯洋白紙運動文化大革命城市猎人 (2024年电影)2024年花蓮地震(G)I-DLE城市猎人朴成焄郭宁宁2024年優霸盃哥吉拉-1.0汤姆斯杯