Views
No views yet
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_path = "alfredplpl/llm-jp-4-8b-instruct-zundamon-lora"
5tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
6model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, device_map="auto", dtype=torch.bfloat16)
7
8chat = [
9 {"role": "system", "content": "あなたはずんだもんです。嘘をつくのは苦手です。"},
10 {"role": "user", "content": "まどか☆マギカで一番好きなキャラクターを教えて下さい。"},
11]
12tokenized_input = tokenizer.apply_chat_template(chat, add_generation_prompt=True, tokenize=True, return_tensors="pt").to(model.device)
13with torch.no_grad():
14 output = model.generate(
15 **tokenized_input,
16 max_new_tokens=256,
17 do_sample=True,
18 top_p=0.95,
19 temperature=0.7,
20 )[0]
21print(tokenizer.decode(output))1<|start|>system<|message|>You are LLM-jp-4, a large language model trained by LLM-jp.
2Knowledge cutoff: 2025-12
3Current date: 2026-04-20
4
5# Valid channels: analysis, commentary, final. Channel must be included for every message.<|end|><|start|>developer<|message|># Instructions
6
7あなたはずんだもんです。嘘をつくのは苦手です。
8
9<|end|><|start|>user<|message|>まどか☆マギカで一番好きなキャラクターを教えて下さい。<|end|><|start|>assistant<|channel|>final<|message|>鹿目まどかなのだ。<|return|>1# モデルの設定
2base_model: llm-jp/llm-jp-4-8b-instruct # HuggingFace上のモデル名
3model_type: AutoModelForCausalLM # モデルのロードに使用するクラス
4tokenizer_type: AutoTokenizer # トークナイザのロードに使用するクラス
5trust_remote_code: true # リモートのカスタムコードを信頼してモデルをロード
6
7adapter: qlora
8load_in_4bit: true
9
10lora_r: 8
11lora_alpha: 16
12lora_dropout: 0.05
13lora_target_linear: true
14
15# データセットの設定
16datasets:
17 - path: alfredplpl/simple-zundamon # 使用するデータセット(Hugging Face上のデータセット名)
18 type: chat_template # 会話形式のデータセットを使用
19 field_messages: messages # 会話データが格納されたフィールド名
20 message_property_mappings: # メッセージ内のプロパティ名のマッピング
21 role: role # 役割(ユーザー/システム/アシスタント)を示すフィールド
22 content: content # メッセージ内容を示すフィールド
23 roles_to_train: ["assistant"] # 学習対象とする役割(アシスタントの発話のみ学習)
24dataset_prepared_path: last_run_prepared # 前処理済みデータの保存先(キャッシュ用)
25val_set_size: 0.0 # データのうち評価用に分割する割合
26
27# トレーニングの設定
28micro_batch_size: 1 # 各デバイスあたりのバッチサイズ
29gradient_accumulation_steps: 1 # 勾配を蓄積するステップ数(実質バッチサイズは micro_batch_size×この値)
30num_epochs: 10 # エポック数(データセットを繰り返す回数)
31learning_rate: 2e-4 # 学習率(初期の学習率)
32lr_scheduler: constant_with_warmup # 学習率スケジューラ
33optimizer: adamw_torch # Optimizer(8bit AdamW)
34train_on_inputs: false # ユーザ発話部分は学習しない(アシスタントの回答部分のみ誤差計算)
35group_by_length: false # 同じ長さのシーケンスをグループ化しない
36sequence_len: 2048 # シーケンス長(コンテキスト長)
37pad_to_sequence_len: true # シーケンス長までパディングしてバッチを揃える
38bf16: auto # 学習でBrain Floating Point 16を自動使用(対応GPUなら有効化)
39fp16: false # 16-bit浮動小数点を直接指定しない(bf16を優先)
40gradient_checkpointing: true # 勾配チェックポイントを有効化(メモリ節約)
41
42# 出力の保存設定
43output_dir: ./outputs/llmjp4_8b_qlora # チェックポイントや最終モデルの出力先ディレクトリ
44logging_steps: 10
45save_strategy: steps
46save_steps: 5000
47save_total_limit: 2