Transformers documentation

InternLM3

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

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

FlashAttention SDPA

InternLM3

InternLM3 は、Shanghai AI Laboratory によって開発された 8B パラメータの指示チューニング済み言語モデルです。そのアーキテクチャは Llama と同じです。設定ファイルでは、クエリ、キー、バリューの射影のバイアスを qkv_bias、アテンション出力の射影および MLP 層のバイアスを bias と呼びます。InternLM3Config はこれらを attention_bias および mlp_bias として読み込み、公開されているチェックポイントではこれらが等しいため、等しいことを要求します。

auto クラスは Llama の実装(LlamaModel と LlamaForCausalLM)で読み込むため、InternLM3 に固有なのは InternLM3Config のみです。

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

from transformers import AutoModelForCausalLM, AutoTokenizer


tokenizer = AutoTokenizer.from_pretrained("internlm/internlm3-8b-instruct")
model = AutoModelForCausalLM.from_pretrained("internlm/internlm3-8b-instruct", device_map="auto")

messages = [{"role": "user", "content": "Explain the Pythagorean theorem in one sentence."}]
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=64)
print(tokenizer.decode(output[0][inputs["input_ids"].shape[1] :], skip_special_tokens=True))

InternLM3Config

クラス transformers.InternLM3Config

< >

( 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 = 128512hidden_size: int = 4096intermediate_size: int = 10240num_hidden_layers: int = 48num_attention_heads: int = 32num_key_value_heads: int | None = 2hidden_act: str = 'silu'max_position_embeddings: int = 32768initializer_range: float = 0.02rms_norm_eps: float = 1e-05use_cache: bool = Truepad_token_id: int | None = 2bos_token_id: int | None = 1eos_token_id: int | list[int] | None = 2tie_word_embeddings: bool = Falserope_parameters: transformers.modeling_rope_utils.RopeParameters | dict | None = Noneattention_bias: bool = Falseattention_dropout: float | int = 0.0mlp_bias: bool = Falsehead_dim: int | None = 128 )

パラメータ

  • vocab_size (int、任意、デフォルトは128512) — モデルの語彙サイズです。input_idsで表現できるトークンの種類数を定義します。
  • hidden_size (int、任意、デフォルトは 4096) — 隠れ表現の次元数。
  • intermediate_size (int、任意、デフォルトは 10240) — MLP 表現の次元数。
  • num_hidden_layers (int、任意、デフォルトは 48) — Transformer デコーダーの隠れ層の数。
  • num_attention_heads (int、任意、デフォルトは 32) — Transformer デコーダーの各アテンション層におけるアテンションヘッドの数。
  • num_key_value_heads (int、任意、デフォルトは 2) — 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-05) — RMS正規化レイヤーで使用するepsilonです。
  • use_cache (bool、任意、デフォルトは True) — モデルが最後のキー/バリューの注意を返すかどうか(すべてのモデルで利用されるわけではありません)。config.is_decoder=True の場合、またはモデルがデコーダー専用の生成モデルである場合にのみ関連します。
  • pad_token_id (int、任意、デフォルトは 2) — 語彙内でパディングに使用されるトークン ID。
  • bos_token_id (int、任意、デフォルトは 1) — 語彙におけるストリーム開始に使用されるトークン ID。
  • eos_token_id (Union[int, list[int]]、任意、デフォルトは 2) — 語彙内でストリーム終了に使用されるトークン ID。
  • tie_word_embeddings (bool、任意、デフォルトは False) — モデルの 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) — アテンション確率のドロップアウト率です。
  • mlp_bias (bool、任意、デフォルトはFalse) — MLP層のup_proj、down_proj、gate_proj層でバイアスを使用するかどうかを指定します。
  • head_dim (int、任意、デフォルトは128) — アテンションヘッドの次元です。None の場合、hidden_size // num_attention_heads がデフォルトとして使用されます。

これはLlamaModelの設定を保存するための設定クラスです。指定された引数に基づいてInternlm3モデルをインスタンス化し、モデルのアーキテクチャを定義するために使用されます。デフォルト値で設定をインスタンス化すると、internlm/internlm3-8b-instructと類似した設定が得られます。

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

>>> from transformers import AutoModelForCausalLM, InternLM3Config

>>> # Initializing an InternLM3-8B style configuration
>>> configuration = InternLM3Config()

>>> # Initializing a model (which uses the Llama implementation) from that configuration
>>> model = AutoModelForCausalLM.from_config(configuration)

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