# Copyright 2026 RTA AI Labs. 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 transformers.configuration_utils import PretrainedConfig class NandiConfig(PretrainedConfig): r""" Configuration class for the Nandi model. Example: ```python >>> from transformers import AutoConfig, AutoModelForCausalLM >>> configuration = AutoConfig.from_pretrained("Rta-AILabs/Nandi-150M-remote", trust_remote_code=True) >>> model = AutoModelForCausalLM.from_pretrained("Rta-AILabs/Nandi-150M-remote", trust_remote_code=True) >>> configuration = model.config ``` """ model_type = "nandi" 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.gate_proj": "colwise", "layers.*.mlp.up_proj": "colwise", "layers.*.mlp.down_proj": "rowwise", } def __init__( self, vocab_size=131072, hidden_size=832, intermediate_size=2496, num_hidden_layers=16, num_attention_heads=16, num_key_value_heads=4, head_dim=None, hidden_act="silu", max_position_embeddings=2048, initializer_range=0.008, rms_norm_eps=1e-5, use_cache=True, pad_token_id=None, bos_token_id=1, eos_token_id=0, pretraining_tp=1, tie_word_embeddings=True, rope_parameters=None, attention_bias=False, attention_dropout=0.0, mlp_bias=False, factorized_embedding=True, embedding_rank=196, layer_sharing=True, layer_sharing_repeats=2, **kwargs, ): self.vocab_size = vocab_size self.hidden_size = hidden_size self.intermediate_size = intermediate_size self.num_hidden_layers = num_hidden_layers self.num_attention_heads = num_attention_heads self.num_key_value_heads = num_key_value_heads if num_key_value_heads is not None else num_attention_heads self.head_dim = head_dim if head_dim is not None else hidden_size // num_attention_heads self.hidden_act = hidden_act self.max_position_embeddings = max_position_embeddings self.initializer_range = initializer_range self.rms_norm_eps = rms_norm_eps self.use_cache = use_cache self.pretraining_tp = pretraining_tp self.rope_parameters = rope_parameters if rope_parameters is not None else {"rope_theta": 100000.0} self.attention_bias = attention_bias self.attention_dropout = attention_dropout self.mlp_bias = mlp_bias self.factorized_embedding = factorized_embedding self.embedding_rank = embedding_rank self.layer_sharing = layer_sharing self.layer_sharing_repeats = layer_sharing_repeats if layer_sharing else 1 if self.factorized_embedding and self.embedding_rank <= 0: raise ValueError( f"`embedding_rank` must be positive when `factorized_embedding=True`, got {self.embedding_rank}." ) if self.hidden_size % self.num_attention_heads != 0: raise ValueError( f"`hidden_size` ({self.hidden_size}) must be divisible by " f"`num_attention_heads` ({self.num_attention_heads})." ) if self.layer_sharing_repeats < 1: raise ValueError(f"`layer_sharing_repeats` must be >= 1, got {self.layer_sharing_repeats}.") 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, ) __all__ = ["NandiConfig"]