Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
base_model: llm-jp/llm-jp-3-13b
|
3 |
tags:
|
@@ -19,4 +32,86 @@ language:
|
|
19 |
|
20 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
base_model: llm-jp/llm-jp-3-13b
|
3 |
+
tags:
|
4 |
+
- text-generation-inference
|
5 |
+
- transformers
|
6 |
+
- unsloth
|
7 |
+
- llama
|
8 |
+
- trl
|
9 |
+
license: apache-2.0
|
10 |
+
language:
|
11 |
+
- ja
|
12 |
+
---
|
13 |
+
|
14 |
---
|
15 |
base_model: llm-jp/llm-jp-3-13b
|
16 |
tags:
|
|
|
32 |
|
33 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
34 |
|
35 |
+
|
36 |
+
# LLM-JP-3-13B 推論テンプレート
|
37 |
+
|
38 |
+
LLM-JP-3-13Bモデルを使用し、
|
39 |
+
GoogleColaboratoryで推論を行うためのテンプレート。
|
40 |
+
Unslothを使用。
|
41 |
+
|
42 |
+
## インストール
|
43 |
+
|
44 |
+
```bash
|
45 |
+
pip install unsloth
|
46 |
+
pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
47 |
+
pip install -U torch
|
48 |
+
pip install -U peft
|
49 |
+
```
|
50 |
+
必要なライブラリは適宜保存してください。
|
51 |
+
|
52 |
+
## 使用方法
|
53 |
+
|
54 |
+
1. Hugging Faceのトークンを設定します
|
55 |
+
```python
|
56 |
+
HF_TOKEN = "your_token_here"
|
57 |
+
```
|
58 |
+
|
59 |
+
2. ベースモデルとLoRAアダプターのIDを指定します
|
60 |
+
```python
|
61 |
+
model_id = "llm-jp/llm-jp-3-13b"
|
62 |
+
adapter_id = "154teru/llm-jp-3-13b-it15a4_fullset_lora"
|
63 |
+
```
|
64 |
+
|
65 |
+
3. モデルとトークナイザーをロードします
|
66 |
+
```python
|
67 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
68 |
+
model_name=model_id,
|
69 |
+
dtype=None,
|
70 |
+
load_in_4bit=True,
|
71 |
+
trust_remote_code=True,
|
72 |
+
)
|
73 |
+
```
|
74 |
+
|
75 |
+
4. LoRAアダプターを統合します
|
76 |
+
```python
|
77 |
+
model = PeftModel.from_pretrained(model, adapter_id, token=HF_TOKEN)
|
78 |
+
```
|
79 |
+
|
80 |
+
5. 入力データを準備します
|
81 |
+
- JSONLフォーマットで、以下の構造を持つファイルを用意します:
|
82 |
+
```json
|
83 |
+
{
|
84 |
+
"task_id": "タスクID",
|
85 |
+
"input": "入力テキスト"
|
86 |
+
}
|
87 |
+
```
|
88 |
+
|
89 |
+
6. 推論を実行します
|
90 |
+
```python
|
91 |
+
FastLanguageModel.for_inference(model)
|
92 |
+
results = []
|
93 |
+
for dt in tqdm(datasets):
|
94 |
+
input = dt["input"]
|
95 |
+
prompt = f"""### 指示\n{input}\n### 回答\n"""
|
96 |
+
# 推論処理
|
97 |
+
```
|
98 |
+
|
99 |
+
7. 結果を保存します
|
100 |
+
```python
|
101 |
+
json_file_id = re.sub(".*/", "", adapter_id)
|
102 |
+
with open(f"{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
103 |
+
for result in results:
|
104 |
+
json.dump(result, f, ensure_ascii=False)
|
105 |
+
f.write('\n')
|
106 |
+
```
|
107 |
+
|
108 |
+
## 出力フォーマット
|
109 |
+
|
110 |
+
結果は以下の形式のJSONLファイルとして保存されます:
|
111 |
+
```json
|
112 |
+
{
|
113 |
+
"task_id": "タスクID",
|
114 |
+
"input": "入力テキスト",
|
115 |
+
"output": "モデルの出力"
|
116 |
+
}
|
117 |
+
```
|