-
Notifications
You must be signed in to change notification settings - Fork 31.5k
adds jais2 model support #42684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ArthurZucker
merged 21 commits into
huggingface:main
from
sarathc-cerebras:add-jais2-model
Dec 17, 2025
Merged
adds jais2 model support #42684
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c65baec
adds jais2 model support
sarathc-cerebras ce372f4
updates tests
sarathc-cerebras e6ad269
addresses review comment
sarathc-cerebras 5ae5c35
review comments addressed
sarathc-cerebras a2df8cd
addresses test review comments
sarathc-cerebras 18adadc
fixes date
sarathc-cerebras afc73f5
format issue fix
sarathc-cerebras 63f1262
Update src/transformers/models/jais2/__init__.py
sarathc-cerebras aa63e5c
Update src/transformers/models/jais2/modular_jais2.py
sarathc-cerebras 78924e1
Update tests/models/jais2/test_modeling_jais2.py
sarathc-cerebras ce62466
Update src/transformers/models/jais2/modular_jais2.py
sarathc-cerebras a553d2b
Update src/transformers/models/jais2/modular_jais2.py
sarathc-cerebras 8223e31
Update src/transformers/models/jais2/modular_jais2.py
sarathc-cerebras 36fb5f5
Update src/transformers/models/jais2/modular_jais2.py
sarathc-cerebras 8348b3f
Update src/transformers/models/jais2/modular_jais2.py
sarathc-cerebras 5c60f4a
fixes tests as per review comment
sarathc-cerebras 506d4fd
updates layernorm setup
sarathc-cerebras 6ec0bc6
Apply suggestions from code review
sarathc-cerebras a29243e
addressed review comments and updated tests as recomended
sarathc-cerebras c25937e
fixup tests
vasqu 8860cb4
Merge branch 'main' into add-jais2-model
vasqu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <!--Copyright 2024 The HuggingFace Team. All rights reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations under the License. | ||
|
|
||
| ⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be | ||
| rendered properly in your Markdown viewer. | ||
|
|
||
| --> | ||
| *This model was released on 2025-12-09 and added to Hugging Face Transformers on 2025-12-16.* | ||
|
|
||
| # Jais2 | ||
|
|
||
| ## Overview | ||
|
|
||
| Jais2 a next-generation Arabic open-weight LLM trained on the richest Arabic-first dataset to date. Built from the ground up with 8B and 70B parameters, Jais 2 understands Arabic the way it's truly spoken across dialects, cuulutre, and modern expression. It is developed by MBZUAI, Inception and Cerebras Systems and based on the transformer architecture with modifications including: | ||
|
|
||
| - LayerNorm instead of RMSNorm | ||
| - ReLU² activation function | ||
| - Rotary Position Embeddings (RoPE) | ||
|
|
||
| ## Jais2Config | ||
|
|
||
| [[autodoc]] Jais2Config | ||
|
|
||
| ## Jais2Model | ||
|
|
||
| [[autodoc]] Jais2Model | ||
| - forward | ||
|
|
||
| ## Jais2ForCausalLM | ||
|
|
||
| [[autodoc]] Jais2ForCausalLM | ||
| - forward |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vasqu marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Copyright 2025 The HuggingFace Team. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from ...utils import _LazyModule | ||
| from ...utils.import_utils import define_import_structure | ||
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| from .configuration_jais2 import * | ||
| from .modeling_jais2 import * | ||
| else: | ||
| import sys | ||
|
|
||
| _file = globals()["__file__"] | ||
| sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 | ||
| # This file was automatically generated from src/transformers/models/jais2/modular_jais2.py. | ||
| # Do NOT edit this file manually as any edits will be overwritten by the generation of | ||
| # the file from the modular. If any change should be done, please apply the change to the | ||
| # modular_jais2.py file directly. One of our CI enforces this. | ||
| # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 | ||
| # coding=utf-8 | ||
| # Copyright 2025 the HuggingFace Team. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from ...configuration_utils import PreTrainedConfig | ||
| from ...modeling_rope_utils import RopeParameters | ||
|
|
||
|
|
||
| class Jais2Config(PreTrainedConfig): | ||
| r""" | ||
| This is the configuration class to store the configuration of a [`Jais2Model`]. It is used to instantiate a Jais2 | ||
| model according to the specified arguments, defining the model architecture. | ||
| [inceptionai/Jais-2-8B-Chat](https://huggingface.co/inceptionai/Jais-2-8B-Chat). | ||
|
|
||
| Configuration objects inherit from [`PreTrainedConfig`] and can be used to control the model outputs. Read the | ||
| documentation from [`PreTrainedConfig`] for more information. | ||
|
|
||
| Args: | ||
| vocab_size (`int`, *optional*, defaults to 150272): | ||
| Vocabulary size of the Jais2 model. | ||
| hidden_size (`int`, *optional*, defaults to 3328): | ||
| Dimension of the hidden representations. | ||
| intermediate_size (`int`, *optional*, defaults to 26624): | ||
| Dimension of the MLP representations. | ||
| num_hidden_layers (`int`, *optional*, defaults to 32): | ||
| Number of hidden layers in the Transformer decoder. | ||
| num_attention_heads (`int`, *optional*, defaults to 26): | ||
| Number of attention heads for each attention layer. | ||
| num_key_value_heads (`int`, *optional*): | ||
| Number of key_value heads for Grouped Query Attention. | ||
| hidden_act (`str`, *optional*, defaults to `"relu2"`): | ||
| The non-linear activation function in the decoder. | ||
| max_position_embeddings (`int`, *optional*, defaults to 8192): | ||
| The maximum sequence length. | ||
| initializer_range (`float`, *optional*, defaults to 0.02): | ||
| The standard deviation of the truncated_normal_initializer. | ||
| layer_norm_eps (`float`, *optional*, defaults to 1e-05): | ||
| The epsilon used by the normalization layers. | ||
| use_cache (`bool`, *optional*, defaults to `True`): | ||
| Whether to return last key/values attentions. | ||
| pad_token_id (`int`, *optional*): | ||
| Padding token id. | ||
| bos_token_id (`int`, *optional*, defaults to 0): | ||
| Beginning of stream token id. | ||
| eos_token_id (`int`, *optional*, defaults to 150024): | ||
| End of stream token id. | ||
| tie_word_embeddings (`bool`, *optional*, defaults to `False`): | ||
| Whether to tie weight embeddings. | ||
| attention_bias (`bool`, *optional*, defaults to `True`): | ||
| Whether to use a bias in the query, key, value and output projection layers. | ||
| attention_dropout (`float`, *optional*, defaults to 0.0): | ||
| The dropout ratio for the attention probabilities. | ||
| mlp_bias (`bool`, *optional*, defaults to `True`): | ||
| Whether to use a bias in up_proj, down_proj and gate_proj layers. | ||
| head_dim (`int`, *optional*): | ||
| The attention head dimension. | ||
| rope_parameters (`dict`, *optional*): | ||
| The RoPE parameters. | ||
| """ | ||
|
|
||
| model_type = "jais2" | ||
| keys_to_ignore_at_inference = ["past_key_values"] | ||
|
|
||
| base_model_tp_plan = { | ||
| "layers.*.self_attn.q_proj": "colwise", | ||
| "layers.*.self_attn.k_proj": "colwise", | ||
| "layers.*.self_attn.v_proj": "colwise", | ||
| "layers.*.self_attn.o_proj": "rowwise", | ||
| "layers.*.mlp.up_proj": "colwise", | ||
| "layers.*.mlp.down_proj": "rowwise", | ||
| } | ||
| base_model_pp_plan = { | ||
| "embed_tokens": (["input_ids"], ["inputs_embeds"]), | ||
| "layers": (["hidden_states", "attention_mask"], ["hidden_states"]), | ||
| "norm": (["hidden_states"], ["hidden_states"]), | ||
| } | ||
|
|
||
| def __init__( | ||
| self, | ||
| vocab_size: Optional[int] = 150272, | ||
| hidden_size: Optional[int] = 3328, | ||
| intermediate_size: Optional[int] = 26624, | ||
| num_hidden_layers: Optional[int] = 32, | ||
| num_attention_heads: Optional[int] = 26, | ||
| num_key_value_heads: Optional[int] = None, | ||
| hidden_act: Optional[str] = "relu2", | ||
| max_position_embeddings: Optional[int] = 8192, | ||
| initializer_range: Optional[float] = 0.02, | ||
| layer_norm_eps: Optional[float] = 1e-5, | ||
| use_cache: Optional[bool] = True, | ||
| pad_token_id: Optional[int] = None, | ||
| bos_token_id: Optional[int] = 0, | ||
| eos_token_id: Optional[int] = 150024, | ||
| tie_word_embeddings: Optional[bool] = False, | ||
| attention_bias: Optional[bool] = True, | ||
| attention_dropout: Optional[float] = 0.0, | ||
| mlp_bias: Optional[bool] = True, | ||
| head_dim: Optional[int] = None, | ||
| rope_parameters: Optional[RopeParameters | dict[str, RopeParameters]] = None, | ||
| **kwargs, | ||
| ): | ||
| self.vocab_size = vocab_size | ||
| self.max_position_embeddings = max_position_embeddings | ||
| self.hidden_size = hidden_size | ||
| self.intermediate_size = intermediate_size | ||
| self.num_hidden_layers = num_hidden_layers | ||
| self.num_attention_heads = num_attention_heads | ||
|
|
||
| # for backward compatibility | ||
| if num_key_value_heads is None: | ||
| num_key_value_heads = num_attention_heads | ||
|
|
||
| self.num_key_value_heads = num_key_value_heads | ||
| self.hidden_act = hidden_act | ||
| self.initializer_range = initializer_range | ||
| self.use_cache = use_cache | ||
| self.attention_bias = attention_bias | ||
| self.attention_dropout = attention_dropout | ||
| self.mlp_bias = mlp_bias | ||
| self.head_dim = head_dim if head_dim is not None else self.hidden_size // self.num_attention_heads | ||
| self.rope_parameters = rope_parameters | ||
|
|
||
| super().__init__( | ||
| pad_token_id=pad_token_id, | ||
| bos_token_id=bos_token_id, | ||
| eos_token_id=eos_token_id, | ||
| tie_word_embeddings=tie_word_embeddings, | ||
| **kwargs, | ||
| ) | ||
| self.layer_norm_eps = layer_norm_eps | ||
|
|
||
|
|
||
| __all__ = ["Jais2Config"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.