# IQuestCoder

[IQuest-Coder-V1](https://huggingface.co/IQuestLab/IQuest-Coder-V1-40B-Instruct) は、[IQuest Lab](https://huggingface.co/IQuestLab) によって開発されたコード言語モデルのファミリーです。7B、14B、40B のサイズがあり、base、instruct、thinking の各バリエーションが用意されています。そのアーキテクチャは [Llama](./llama) と同じです。

> [!NOTE]
> ループ型`IQuest-Coder-V1-*-Loop-*`チェックポイントは異なるアーキテクチャを使用しており、このモデルではサポートされていません。

> [!WARNING]
> トークナイザーは、チェックポイントのSentencePieceモデルから構築されます。その多くのピースが同じスコアを共有しており、SentencePieceはそれらの同点（タイ）を位置によって解決しますが、`tokenizers`ライブラリではこれを再現できません。そのため、元のリモートコードとは異なる方法でトークン化されるテキストがわずかに存在します。

auto クラスは Llama の実装（[LlamaModel](/docs/transformers/v5.23.0/ja/model_doc/llama2#transformers.LlamaModel) および [LlamaForCausalLM](/docs/transformers/v5.23.0/ja/model_doc/llama2#transformers.LlamaForCausalLM)）で読み込むため、IQuestCoder に固有なのは [IQuestCoderConfig](/docs/transformers/v5.23.0/ja/model_doc/iquestcoder#transformers.IQuestCoderConfig) のみです。

以下の例は、[AutoModelForCausalLM](/docs/transformers/v5.23.0/ja/model_doc/auto#transformers.AutoModelForCausalLM) クラスを使用してテキストを生成する方法を示しています。

```python
from transformers import AutoModelForCausalLM, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("IQuestLab/IQuest-Coder-V1-7B-Instruct")
model = AutoModelForCausalLM.from_pretrained("IQuestLab/IQuest-Coder-V1-7B-Instruct", device_map="auto")

messages = [{"role": "user", "content": "Write a Python function that checks whether a number is prime."}]
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=128)
print(tokenizer.decode(output[0][inputs["input_ids"].shape[1] :], skip_special_tokens=True))
```

## IQuestCoderConfig[[transformers.IQuestCoderConfig]]

#### transformers.IQuestCoderConfig[[transformers.IQuestCoderConfig]]

```python
transformers.IQuestCoderConfig(transformers_version: str | None = None, architectures: list[str] | None = None, output_hidden_states: bool | None = False, return_dict: bool | None = True, dtype: str | torch.dtype | None = None, chunk_size_feed_forward: int = 0, is_encoder_decoder: bool = False, id2label: dict[int, str] | dict[str, str] | None = None, label2id: dict[str, int] | dict[str, str] | None = None, problem_type: Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = None, vocab_size: int = 76800, hidden_size: int = 5120, intermediate_size: int = 27648, num_hidden_layers: int = 80, num_attention_heads: int = 40, num_key_value_heads: int | None = 8, hidden_act: str = 'silu', max_position_embeddings: int = 131072, initializer_range: float = 0.02, rms_norm_eps: float = 1e-05, use_cache: bool = True, pad_token_id: int | None = None, bos_token_id: int | None = 1, eos_token_id: int | list[int] | None = 2, tie_word_embeddings: bool = False, rope_parameters: transformers.modeling_rope_utils.RopeParameters | dict | None = None, attention_bias: bool = False, attention_dropout: float | int = 0.0, mlp_bias: bool = False, head_dim: int | None = 128)
```

[ソース](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/models/iquestcoder/configuration_iquestcoder.py#L30)

**パラメータ:**

vocab_size (`int`、*任意*、デフォルトは`76800`) : モデルの語彙サイズ。`input_ids`で表現できるトークンの種類数を定義します。

hidden_size (`int`、*任意*、デフォルトは`5120`) : 隠れ表現の次元数。

intermediate_size (`int`、*optional*、デフォルトは`27648`) : MLP表現の次元数。

num_hidden_layers (`int`、*optional*、デフォルトは`80`) : Transformer デコーダーの隠れ層の数。

num_attention_heads (`int`、*任意*、デフォルトは `40`) : Transformer デコーダーの各アテンション層におけるアテンションヘッドの数。

num_key_value_heads (`int`, *optional*, デフォルトは `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 ヘッドは、そのグループ内の元のすべてのヘッドを平均プーリングして構築する必要があります。詳細については、[この論文](https://huggingface.co/papers/2305.13245)を参照してください。指定されない場合、デフォルトで `num_attention_heads` が使用されます。

hidden_act (`str`、*任意*、デフォルトは`silu`) : デコーダーで使用する非線形活性化関数（関数または文字列）。例えば、`"gelu"`、`"relu"`、`"silu"`など。

max_position_embeddings (`int`、*任意*、デフォルトは `131072`) : このモデルが使用される可能性のある最大シーケンス長です。

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`, *任意*) : 語彙内でパディングに使用されるトークン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]`, *optional*) : 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の設定を保存するための設定クラスです。指定された引数に基づいてIquestcoderモデルをインスタンス化し、モデルのアーキテクチャを定義するために使用されます。デフォルト値で設定をインスタンス化すると、[IQuestLab/IQuest-Coder-V1-40B-Instruct](https://huggingface.co/IQuestLab/IQuest-Coder-V1-40B-Instruct)と類似した設定が得られます。

設定オブジェクトは [PreTrainedConfig](/docs/transformers/v5.23.0/ja/main_classes/configuration#transformers.PreTrainedConfig) を継承し、モデルの出力を制御するために使用できます。詳細については、[PreTrainedConfig](/docs/transformers/v5.23.0/ja/main_classes/configuration#transformers.PreTrainedConfig) のドキュメントを参照してください。

```python
>>> from transformers import AutoModelForCausalLM, IQuestCoderConfig

>>> # Initializing an IQuest-Coder-V1-40B style configuration
>>> configuration = IQuestCoderConfig()

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

>>> # Accessing the model configuration
>>> configuration = model.config
```

