Transformers documentation

Param2Moe

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.25.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

このモデルは2026年12月1日にHugging Face Transformersに貢献されました。

FlashAttention SDPA

Param2Moe

Param2Moeは、BharatGen AIが開発したMixture of Experts (MoE) 言語モデルであるParam-2-17B-MoE-A2.4Bのアーキテクチャです。総パラメータ数は17B、トークンあたりのアクティブパラメータ数は2.4Bです。英語、ヒンディー語、およびインドの21言語に対応しています。

主要なアーキテクチャ上の機能:

  • グループクエリアテンション(クエリヘッド32、キー/バリューヘッド8)にQK正規化と完全なロータリー位置埋め込みを適用。
  • Hybrid Mixture of Experts: the first layer uses a dense MLP, the remaining layers route each token to 6 of 64 experts, plus 2 shared experts that are always active.
  • Sigmoid routingは、エキスパートバイアス補正とルーティングスケーリング係数を使用します。

アーキテクチャはGLM-4-MoEと同じですが、パラメータ名と設定名が異なります。auto クラスは GLM-4-MoE の実装(Glm4MoeModel および Glm4MoeForCausalLM)で読み込むため、Param2MoeConfig だけが Param2Moe に固有です。公開されているチェックポイントは、読み込み時に GLM-4-MoE の名前に変換され、保存時に元の名前に戻されます。

以下の例は、AutoModelForCausalLM クラスを使用してテキストを生成する方法を示しています。

from transformers import AutoModelForCausalLM, AutoTokenizer


tokenizer = AutoTokenizer.from_pretrained("bharatgenai/Param2-17B-A2.4B-Thinking")
model = AutoModelForCausalLM.from_pretrained("bharatgenai/Param2-17B-A2.4B-Thinking", device_map="auto")

messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What is the BharatGen Mission?"},
]
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt", return_dict=True)
output = model.generate(**inputs.to(model.device), max_new_tokens=300, do_sample=False)
print(tokenizer.decode(output[0][inputs["input_ids"].shape[1] :], skip_special_tokens=False))

Param2MoeConfig

class transformers.Param2MoeConfig

< >

( transformers_version: str | None = Nonearchitectures: list[str] | None = Noneoutput_hidden_states: bool | None = Falsereturn_dict: bool | None = Truedtype: str | torch.dtype | None = Nonechunk_size_feed_forward: int = 0is_encoder_decoder: bool = Falseid2label: dict[int, str] | dict[str, str] | None = Nonelabel2id: dict[str, int] | dict[str, str] | None = Noneproblem_type: Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = Nonevocab_size: int = 128000hidden_size: int = 2048intermediate_size: int = 9216num_hidden_layers: int = 21num_attention_heads: int = 32num_key_value_heads: int = 8hidden_act: str = 'silu'max_position_embeddings: int = 32768initializer_range: float = 0.02rms_norm_eps: float = 1e-06use_cache: bool = Truetie_word_embeddings: bool = Truerope_parameters: transformers.modeling_rope_utils.RopeParameters | dict | None = Noneattention_bias: bool = Falseattention_dropout: float | int = 0.0moe_intermediate_size: int = 2048num_experts_per_tok: int = 6output_router_logits: bool = Falsen_shared_experts: int = 2n_routed_experts: int = 64routed_scaling_factor: float = 2.5n_group: int = 1topk_group: int = 1first_k_dense_replace: int = 1norm_topk_prob: bool = Trueuse_qk_norm: bool = Truebos_token_id: int | None = Noneeos_token_id: int | list[int] | None = 3pad_token_id: int | None = 0num_mtp_layers: int = 0head_dim: int = 64 )

パラメータ

  • vocab_size (int、任意、デフォルトは 128000) — モデルの語彙サイズ。input_ids で表現できるトークンの種類数を定義します。
  • hidden_size (int、任意、デフォルトは 2048) — 隠れ表現の次元数。
  • intermediate_size (int、任意、デフォルトは 9216) — MLP 表現の次元数。
  • num_hidden_layers (int、任意、デフォルトは21) — Transformerデコーダーの隠れ層の数。
  • num_attention_heads (int、任意、デフォルトは 32) — Transformer デコーダーの各アテンション層におけるアテンションヘッドの数。
  • num_key_value_heads (int、任意、デフォルトは8) — Grouped Query Attention の実装に使用する key_value ヘッドの数を指定します。 num_key_value_heads=num_attention_heads の場合、モデルは Multi Head Attention (MHA) を使用し、 num_key_value_heads=1 の場合は Multi Query Attention (MQA) を使用し、それ以外の場合は GQA が使用されます。 マルチヘッドのチェックポイントを GQA のチェックポイントに変換する際は、各グループの key ヘッドと value ヘッドを、そのグループ内の元のすべてのヘッドの平均プーリングによって構築する必要があります。詳細については、この論文を参照してください。指定しない場合、デフォルトで num_attention_heads が使用されます。
  • hidden_act (str、任意、デフォルトは silu) — デコーダーで使用する非線形活性化関数(関数または文字列)。例えば、"gelu"、 "relu"、"silu" など。
  • max_position_embeddings (int、任意、デフォルトは 32768) — このモデルが使用される可能性のある最大シーケンス長です。
  • initializer_range (float、任意、デフォルトは 0.02) — すべての重み行列を初期化するための truncated_normal_initializer の標準偏差です。
  • rms_norm_eps (float、任意、デフォルトは 1e-06) — RMS 正規化レイヤーで使用する epsilon。
  • use_cache (bool、任意、デフォルトは True) — モデルが最後のキー/バリューの注意を返すかどうか(すべてのモデルで利用されるわけではありません)。config.is_decoder=True の場合、またはモデルがデコーダー専用の生成モデルである場合にのみ関連します。
  • tie_word_embeddings (bool、任意、デフォルトは True) — モデルの tied_weights_keys マッピングに従って重み埋め込みを共有するかどうかを指定します。
  • rope_parameters (Union[~modeling_rope_utils.RopeParameters, dict], 省略可) — RoPE 埋め込みの設定パラメータを含む辞書です。この辞書には rope_theta の値が含まれており、より長い max_position_embeddings で RoPE を使用する場合にスケーリングに使用されるパラメータが任意で含まれます。
  • attention_bias (bool、任意、デフォルトはFalse) — 自己注意機構において、クエリ、キー、バリュー、出力の投影層にバイアスを使用するかどうかを指定します。
  • attention_dropout (Union[float, int]、任意、デフォルトは 0.0) — アテンション確率のドロップアウト率です。
  • moe_intermediate_size (int、任意、デフォルトは2048) — ルーティングされたエキスパートのMLPの中間サイズ。
  • num_experts_per_tok (int、任意、デフォルトは6) — 各トークンをルーティングするエキスパートの数です。これは、トークン選択ルーティングにおける top-k の値です。
  • output_router_logits (bool、任意、デフォルトはFalse) — モデルがルーターのロジツを返すかどうかを指定します。これを有効にすると、モデルは補助損失(ロードバランシング損失とルーターのz損失を含む)を出力できるようになります。
  • n_shared_experts (int、任意、デフォルトは 2) — 共有エキスパートの数。
  • n_routed_experts (int、任意、デフォルトは 64) — ルーティング対象のエクスパートの数。
  • routed_scaling_factor (float、任意、デフォルトは 2.5) — ルーティングされたエキスパートのスケール係数。
  • n_group (int、任意、デフォルトは 1) — ルーティングされたエキスパートのグループ数。
  • topk_group (int、任意、デフォルトは 1) — 各トークンについて選択されるグループの数(各トークンにおいて、選択されるエキスパートがtopk_group個のグループ内にのみ含まれることを保証します)。
  • first_k_dense_replace (int、任意、デフォルトは 1) — 浅い層(embed->dense->moe->moe…->lm_head)における dense 層の数。 --k dense layers—/
  • norm_topk_prob (bool、任意、デフォルトは True) — ルーティングされたエキスパートの重みを正規化するかどうかを指定します。
  • use_qk_norm (bool、省略可能、デフォルトはTrue) — アテンションでクエリ・キー正規化を使用するかどうか。
  • bos_token_id (int, 省略可) — 語彙におけるストリーム開始に使用されるトークン ID。
  • eos_token_id (Union[int, list[int]]、任意、デフォルトは 3) — 語彙内でストリーム終了に使用されるトークン ID。
  • pad_token_id (int、任意、デフォルトは 0) — 語彙内でパディングに使用されるトークン ID。
  • num_mtp_layers (int、任意、デフォルトは 0) — ベースの Transformer モデルの後に追加できる Multi-Token Prediction (MTP) モジュールの数です。公開されているチェックポイントには MTP の重みは含まれていません。
  • head_dim (int、任意、デフォルトは64) — アテンションヘッドの次元です。None の場合、hidden_size // num_attention_heads がデフォルトとして使用されます。

これは Glm4MoeModel の設定を保存するための設定クラスです。指定された引数に基づいて Param2Moe モデルをインスタンス化し、モデルのアーキテクチャを定義するために使用されます。デフォルト値で設定をインスタンス化すると、bharatgenai/Param2-17B-A2.4B-Thinking と同様の設定が得られます。

設定オブジェクトはPreTrainedConfigを継承し、モデルの出力を制御するために使用できます。詳細については、PreTrainedConfigのドキュメントを参照してください。

例:

>>> from transformers import AutoModelForCausalLM, Param2MoeConfig

>>> # Initializing a Param2-17B-A2.4B style configuration
>>> configuration = Param2MoeConfig()

>>> # Initializing a model (which uses the GLM-4-MoE implementation) from that configuration
>>> model = AutoModelForCausalLM.from_config(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config
Update on GitHub