File size: 3,794 Bytes
5c94107 c47758e 5c94107 c47758e 5c94107 c47758e 5af5a82 ea0ae09 fdb5290 c47758e ea0ae09 c47758e 5af5a82 c47758e ea0ae09 c47758e ea0ae09 4c8f2a0 ea0ae09 c47758e 8a421a9 c47758e ea0ae09 c47758e 26dfeb9 ea0ae09 c47758e 5af5a82 0cf338b 26dfeb9 c47758e 5af5a82 26dfeb9 c47758e 5c94107 ea0ae09 5af5a82 ea0ae09 5af5a82 ea0ae09 9f42b65 ea0ae09 5af5a82 ea0ae09 5af5a82 ea0ae09 5af5a82 4c8f2a0 ea0ae09 4c8f2a0 5af5a82 5c94107 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
---
base_model: llm-jp/llm-jp-3-13b
tags:
- text-generation-inference
- transformers
- unsloth
- llama
- trl
license: cc-by-sa-4.0
language:
- ja
---
# モデル概要
このモデルは、日本語の大規模言語モデル(LLM)であるllm-jp/llm-jp-3-13bをベースにインストラクションチューニングしたLoRAアダプタです。
# 使用したインストラクションデータセット:
- [kanhatakeyama/AutoMultiTurnByCalm3-22B](https://huggingface.co/datasets/kanhatakeyama/AutoMultiTurnByCalm3-22B)
- [Jaster (llm-jp-eval・CC-BY-SA-4.0のデータのみ)](https://github.com/llm-jp/llm-jp-eval)
- [elyza/ELYZA-tasks-100](https://huggingface.co/datasets/elyza/ELYZA-tasks-100)
- 独自データセット
-
# 使用方法例
1. 依存関係のインストール:
```bash
# 必要なライブラリをインストール
pip install -U bitsandbytes transformers accelerate datasets peft pandas
pip install -U unsloth # stable release
```
2. モデルの読み込み(Unslothというライブラリを使用し4bit量子化して読み込む場合の例):
```python
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)
```
3. 推論(任意のプロンプトで推論する場合)
```python
# 最大出力トークン数
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)
```
4. 評価データセット(elyza-tasks-100-TV.jsonl)の読み込みとテスト実行
```python
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](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|