--- base_model: llm-jp/llm-jp-3-13b tags: - text-generation-inference - transformers - unsloth - llama - trl license: apache-2.0 language: - en --- # llm-jp-3-13b-it-v6_lora このモデルは、llm-jp-3-13bをベースに、Ichikara Instructionのデータセットでファインチューニングを行ったLoRAアダプタです。 ## 動作環境 - GPU: NVIDIA L4(24GB)以上のGPUメモリ - RAM: 16GB以上推奨 - Python 3.10以上 ## モデルの概要 - ベースモデル: llm-jp/llm-jp-3-13b - 学習データ: ichikara-instruction-003-001-1 - 手法: QLoRA(unslothを使用) - コンテキスト長: 512トークン ## データセット前処理 学習データは以下の手順で前処理を行いました: 1. データセットの読み込みと変換: ```python from datasets import load_dataset # データセットの読み込み dataset = load_dataset("json", data_files="ichikara-instruction-003-001-1.json") # プロンプトフォーマットの定義 prompt = """### 指示 {} ### 回答 {}""" # フォーマット変換関数 def formatting_prompts_func(examples): input = examples["text"] output = examples["output"] text = prompt.format(input, output) + tokenizer.eos_token return {"formatted_text": text} # データの変換 dataset = dataset.map( formatting_prompts_func, num_proc=4, ) ``` 2. データセットの統計情報: - 総サンプル数: 1,729 - instruction/outputの組み合わせを保持 - 日本語のインストラクションデータ ## 出力の再現性について 本READMEの手順に従うことで、提出したjsonlファイルと同様の出力を再現することができます。再現性を確保するため、以下の点に注意してください: - モデルの推論設定(repetition_penalty=1.2, do_sample=False など)を変更しない - 入力プロンプトのフォーマット(### 指示\n...\n### 回答\n)を維持する - 乱数シードは3407に設定 - PyTorchのバージョンは2.5.1以上を推奨 ## ベンチマーク出力方法 ELYZA-tasks-100-TVのベンチマーク出力を生成するための手順: 1. 環境準備 ```python import os import torch import json from tqdm import tqdm from unsloth import FastLanguageModel # 必要なパッケージのインストール !pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git" !pip install --upgrade torch xformers ``` 2. モデルとトークナイザーの準備 ```python # GPU設定の確認 device = torch.device("cuda" if torch.cuda.is_available() else "cpu") # モデルとトークナイザーの読み込み model_id = "llm-jp/llm-jp-3-13b" max_seq_length = 512 model, tokenizer = FastLanguageModel.from_pretrained( model_name=model_id, dtype=None, load_in_4bit=True, trust_remote_code=True, ) # 推論モードに設定 FastLanguageModel.for_inference(model) ``` 3. 評価用データの読み込みと推論実行、出力生成 ```python # データセットの読み込み datasets = [] with open("elyza-tasks-100-TV_0.jsonl", "r") as f: item = "" for line in f: line = line.strip() item += line if item.endswith("}"): datasets.append(json.loads(item)) item = "" # 推論実行 results = [] for dt in tqdm(datasets): input = dt["input"] prompt = f"""### 指示\n{input}\n### 回答\n""" inputs = tokenizer([prompt], return_tensors="pt").to(device) outputs = model.generate( **inputs, max_new_tokens=512, use_cache=True, do_sample=False, repetition_penalty=1.2 ) prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1] results.append({ "task_id": dt["task_id"], "input": input, "output": prediction }) # 結果をjsonl形式で保存 with open("llm-jp-3-13b-it-v6_output.jsonl", 'w', encoding='utf-8') as f: for result in results: json.dump(result, f, ensure_ascii=False) f.write('\n') ``` 必要なファイル: - elyza-tasks-100-TV_0.jsonl(評価用データ) 出力ファイル: - llm-jp-3-13b-it-v6_output.jsonl(ベンチマークの出力結果) ## 学習設定 モデルは以下の設定で学習を行いました: - ライブラリ: unsloth - rank (r): 32 - lora_alpha: 32 - lora_dropout: 0.05 - target_modules: ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"] - バッチサイズ: 2 - 勾配累積ステップ: 4 - エポック数: 1 - 学習率: 2e-4 - warmup_steps: 10 - max_seq_length: 512 ## ライセンス このモデルは、元のllm-jp-3-13bおよびIchikara Instructionデータセットのライセンスに従います。商用利用の際は、各ライセンスをご確認ください。 ## 引用 このモデルを使用する場合は、以下を引用してください: ```bibtex @misc{llm-jp-3-13b-it-v6, author = {[YOUR_NAME]}, title = {llm-jp-3-13b-it-v6: Instruction-tuned LLM-JP-3-13B with QLoRA}, year = {2024}, publisher = {Hugging Face}, journal = {Hugging Face Hub}, howpublished = {\url{https://huggingface.co/[YOUR_USERNAME]/llm-jp-3-13b-it-v6}}, } @inproceedings{sekine-etal-2024-ichikara, title = {ichikara-instruction: LLMのための日本語インストラクションデータの構築}, author = {関根 聡 and 安藤 まや and 後藤 美知子 and 鈴木 久美 and 河原 大輔 and 井之上 直也 and 乾 健太郎}, booktitle = {言語処理学会第30回年次大会}, year = {2024} } ``` # Uploaded model - **Developed by:** sabia0080 - **License:** apache-2.0 - **Finetuned from model :** llm-jp/llm-jp-3-13b This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library. [](https://github.com/unslothai/unsloth)