Skip to content
Merged
Show file tree
Hide file tree
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 Dec 7, 2025
ce372f4
updates tests
sarathc-cerebras Dec 9, 2025
e6ad269
addresses review comment
sarathc-cerebras Dec 9, 2025
5ae5c35
review comments addressed
sarathc-cerebras Dec 10, 2025
a2df8cd
addresses test review comments
sarathc-cerebras Dec 11, 2025
18adadc
fixes date
sarathc-cerebras Dec 11, 2025
afc73f5
format issue fix
sarathc-cerebras Dec 11, 2025
63f1262
Update src/transformers/models/jais2/__init__.py
sarathc-cerebras Dec 12, 2025
aa63e5c
Update src/transformers/models/jais2/modular_jais2.py
sarathc-cerebras Dec 12, 2025
78924e1
Update tests/models/jais2/test_modeling_jais2.py
sarathc-cerebras Dec 12, 2025
ce62466
Update src/transformers/models/jais2/modular_jais2.py
sarathc-cerebras Dec 12, 2025
a553d2b
Update src/transformers/models/jais2/modular_jais2.py
sarathc-cerebras Dec 12, 2025
8223e31
Update src/transformers/models/jais2/modular_jais2.py
sarathc-cerebras Dec 12, 2025
36fb5f5
Update src/transformers/models/jais2/modular_jais2.py
sarathc-cerebras Dec 12, 2025
8348b3f
Update src/transformers/models/jais2/modular_jais2.py
sarathc-cerebras Dec 12, 2025
5c60f4a
fixes tests as per review comment
sarathc-cerebras Dec 12, 2025
506d4fd
updates layernorm setup
sarathc-cerebras Dec 12, 2025
6ec0bc6
Apply suggestions from code review
sarathc-cerebras Dec 16, 2025
a29243e
addressed review comments and updated tests as recomended
sarathc-cerebras Dec 16, 2025
c25937e
fixup tests
vasqu Dec 16, 2025
8860cb4
Merge branch 'main' into add-jais2-model
vasqu Dec 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/source/en/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@
title: HunYuanMoEV1
- local: model_doc/ibert
title: I-BERT
- local: model_doc/jais2
title: Jais2
- local: model_doc/jamba
title: Jamba
- local: model_doc/jetmoe
Expand Down
40 changes: 40 additions & 0 deletions docs/source/en/model_doc/jais2.md
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
2 changes: 2 additions & 0 deletions src/transformers/models/auto/configuration_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
("instructblipvideo", "InstructBlipVideoConfig"),
("internvl", "InternVLConfig"),
("internvl_vision", "InternVLVisionConfig"),
("jais2", "Jais2Config"),
("jamba", "JambaConfig"),
("janus", "JanusConfig"),
("jetmoe", "JetMoeConfig"),
Expand Down Expand Up @@ -659,6 +660,7 @@
("instructblipvideo", "InstructBlipVideo"),
("internvl", "InternVL"),
("internvl_vision", "InternVLVision"),
("jais2", "Jais2"),
("jamba", "Jamba"),
("janus", "Janus"),
("jetmoe", "JetMoe"),
Expand Down
2 changes: 2 additions & 0 deletions src/transformers/models/auto/modeling_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
("instructblipvideo", "InstructBlipVideoModel"),
("internvl", "InternVLModel"),
("internvl_vision", "InternVLVisionModel"),
("jais2", "Jais2Model"),
("jamba", "JambaModel"),
("janus", "JanusModel"),
("jetmoe", "JetMoeModel"),
Expand Down Expand Up @@ -689,6 +690,7 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
("helium", "HeliumForCausalLM"),
("hunyuan_v1_dense", "HunYuanDenseV1ForCausalLM"),
("hunyuan_v1_moe", "HunYuanMoEV1ForCausalLM"),
("jais2", "Jais2ForCausalLM"),
("jamba", "JambaForCausalLM"),
("jetmoe", "JetMoeForCausalLM"),
("lfm2", "Lfm2ForCausalLM"),
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/auto/tokenization_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
("instructblip", "GPT2Tokenizer" if is_tokenizers_available() else None),
("instructblipvideo", "GPT2Tokenizer" if is_tokenizers_available() else None),
("internvl", "Qwen2TokenizerFast" if is_tokenizers_available() else None),
("jais2", "GPT2Tokenizer" if is_tokenizers_available() else None),
("jamba", "LlamaTokenizer" if is_tokenizers_available() else None),
("janus", "LlamaTokenizer" if is_tokenizers_available() else None),
("jetmoe", "LlamaTokenizer" if is_tokenizers_available() else None),
Expand Down
27 changes: 27 additions & 0 deletions src/transformers/models/jais2/__init__.py
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__)
152 changes: 152 additions & 0 deletions src/transformers/models/jais2/configuration_jais2.py
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"]
Loading