Views
No views yet
convert_pytorch_state_dict_to_flax utility function provided by Hugging Face.max_position_embeddingsmax_position_embeddings parameter in the model's configuration. The original value of {original_max_pos_embed} led to out-of-memory (OOM) errors on the hardware used for conversion. To resolve this, max_position_embeddings was adjusted to {new_max_pos_embed}.max_position_embeddings when preparing your training data.| Layer | PyTorch Shape | Flax Shape | Allclose | Max Diff | Mean Diff | Std Diff |
|---|---|---|---|---|---|---|
| model.embed_tokens.weight | (256000, 2048) | (256000, 2048) | True | 0 | 0 | 0 |
| model.layers.0.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.0.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.0.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.0.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.0.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.0.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.0.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.0.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.0.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.1.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.1.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.1.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.1.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.1.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.1.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.1.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.1.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.1.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.2.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.2.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.2.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.2.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.2.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.2.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.2.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.2.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.2.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.3.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.3.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.3.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.3.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.3.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.3.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.3.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.3.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.3.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.4.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.4.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.4.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.4.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.4.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.4.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.4.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.4.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.4.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.5.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.5.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.5.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.5.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.5.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.5.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.5.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.5.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.5.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.6.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.6.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.6.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.6.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.6.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.6.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.6.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.6.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.6.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.7.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.7.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.7.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.7.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.7.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.7.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.7.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.7.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.7.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.8.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.8.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.8.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.8.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.8.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.8.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.8.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.8.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.8.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.9.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.9.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.9.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.9.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.9.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.9.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.9.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.9.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.9.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.10.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.10.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.10.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.10.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.10.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.10.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.10.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.10.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.10.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.11.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.11.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.11.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.11.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.11.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.11.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.11.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.11.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.11.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.12.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.12.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.12.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.12.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.12.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.12.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.12.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.12.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.12.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.13.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.13.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.13.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.13.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.13.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.13.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.13.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.13.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.13.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.14.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.14.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.14.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.14.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.14.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.14.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.14.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.14.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.14.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.15.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.15.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.15.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.15.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.15.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.15.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.15.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.15.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.15.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.16.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.16.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.16.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.16.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.16.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.16.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.16.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.16.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.16.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.17.self_attn.q_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.17.self_attn.k_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.17.self_attn.v_proj.weight | (2048, 256) | (2048, 256) | True | 0 | 0 | 0 |
| model.layers.17.self_attn.o_proj.weight | (2048, 2048) | (2048, 2048) | True | 0 | 0 | 0 |
| model.layers.17.mlp.gate_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.17.mlp.up_proj.weight | (2048, 16384) | (2048, 16384) | True | 0 | 0 | 0 |
| model.layers.17.mlp.down_proj.weight | (16384, 2048) | (16384, 2048) | True | 0 | 0 | 0 |
| model.layers.17.input_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.layers.17.post_attention_layernorm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| model.norm.weight | (2048,) | (2048,) | True | 0 | 0 | 0 |
| lm_head.weight | (2048, 256000) | (2048, 256000) | True | 0 | 0 | 0 |
Allclose indicates whether the weights are approximately equal within the specified relative (rtol=1e-5) and absolute (atol=1e-3) tolerances using jnp.allclose().Max Diff, Mean Diff, and Std Diff provide further details on the differences between the weights if Allclose is False, which might be expected for some layers due to numerical precision differences between frameworks.1import jax
2import jax.numpy as jnp
3from transformers import FlaxAutoModelForCausalLM, AutoTokenizer
4
5model_name = "Erland/gemma-2b-JAX" # Replace with your repository name
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = FlaxAutoModelForCausalLM.from_pretrained(model_name, from_pt=False) # from_pt should be False since it's already flax
8
9# Example prompt
10prompt = "The quick brown fox"
11
12# Tokenize the prompt
13tokenized_prompt = tokenizer(prompt, return_tensors="np")
14
15# Generate text
16output_ids = model.generate(tokenized_prompt.input_ids, max_length=50)
17
18# Decode the generated text
19generated_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)google for their groundbreaking work in developing this powerful language model.