モデル概要
このモデルは、日本語の大規模言語モデル(LLM)であるllm-jp/llm-jp-3-13bをベースにインストラクションチューニングしたLoRAアダプタです。
使用したインストラクションデータセット:
- kanhatakeyama/AutoMultiTurnByCalm3-22B
- Jaster (llm-jp-eval・CC-BY-SA-4.0のデータのみ)
- elyza/ELYZA-tasks-100
- 独自データセット
使用方法例
- 依存関係のインストール:
# 必要なライブラリをインストール
pip install -U bitsandbytes transformers accelerate datasets peft pandas
pip install -U unsloth # stable release
- モデルの読み込み(Unslothというライブラリを使用し4bit量子化して読み込む場合の例):
from unsloth import FastLanguageModel
from peft import PeftModel
# ベースモデルID
base_model_id="llm-jp/llm-jp-3-13b"
# 本アダプタのID
adapter_id="waiyanan/automulti-jaster-myset-r64lr1e5_lora_lora"
# Huggingfaceトークン
hf_token=<有効なHuggingfaceトークン>
# unslothのFastLanguageModelで元のモデルをロード。
dtype = None # Noneにしておけば自動で設定
load_in_4bit = True # 4bit量子化する
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = base_model_id,
dtype = dtype,
load_in_4bit = load_in_4bit,
trust_remote_code=True,
token=hf_token
)
model = PeftModel.from_pretrained(model, adapter_id, token=hf_token)
- 推論(任意のプロンプトで推論する場合)
# 最大出力トークン数
max_token = 1024
prompt = "こんにちは!よろしくお願いいたします。"
FastLanguageModel.for_inference(model)
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens = max_token, use_cache = True, temperature=0.5, top_p=0.9,do_sample=False, repetition_penalty=1.2)
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(prediction)
- 評価データセット(elyza-tasks-100-TV.jsonl)の読み込みとテスト実行
import pandas as pd
from datasets import Dataset
from tqdm import tqdm
import json
datasets = []
# elyza-tasks-100-TV.jsonのファイルパス
file_path =<path_to_input_file>
# 最大出力トークン数
max_token = 1024
# データセットの読み込み
df = pd.read_json(file_path, orient='records', lines=True)
# 結果格納用配列
results = []
# モデルを推論モードにする
FastLanguageModel.for_inference(model)
for _, r in tqdm(df.iterrows(),total=len(df)):
input = r["input"]
task_id=r["task_id"]
prompt = f"""### 指示\n{input} 簡潔に回答してください \n### 回答\n"""
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens = max_token, use_cache = True, temperature=0.5, top_p=0.9,do_sample=False, repetition_penalty=1.2)
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
results.append({"task_id":task_id, "input": input, "output": prediction})
# 結果をjsonlで保存。
ourput_file_path = <path_to_output_file>
with open(ourput_file_path, 'w', encoding='utf-8') as f:
for result in results:
json.dump(result, f, ensure_ascii=False)
f.write('\n')
This llama model was trained 2x faster with Unsloth and Huggingface's TRL library.
Inference Providers
NEW
This model is not currently available via any of the supported Inference Providers.
The model cannot be deployed to the HF Inference API:
The model has no pipeline_tag.
Model tree for waiyanan/automulti-jaster-myset-r64lr1e5_lora_lora
Base model
llm-jp/llm-jp-3-13b