Update README.md
Browse files
README.md
CHANGED
|
@@ -4,78 +4,38 @@ base_model:
|
|
| 4 |
- llm-jp/llm-jp-3-13b
|
| 5 |
---
|
| 6 |
|
| 7 |
-
## 環境準備
|
| 8 |
-
|
| 9 |
-
### 必要なライブラリのインストール
|
| 10 |
-
|
| 11 |
-
```bash
|
| 12 |
-
pip install transformers torch accelerate peft bitsandbytes
|
| 13 |
-
```
|
| 14 |
-
|
| 15 |
## モデルのロードと推論
|
| 16 |
|
| 17 |
### Pythonスクリプト例
|
| 18 |
|
| 19 |
```python
|
| 20 |
-
from
|
| 21 |
-
from peft import PeftModel
|
| 22 |
-
import torch
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
model_id = "your-huggingface-username/llm-jp-3-13b-finetune"
|
| 27 |
|
| 28 |
-
|
| 29 |
-
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
device_map="auto"
|
| 36 |
-
)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
model = model.merge_and_unload()
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
# 推論
|
| 53 |
-
outputs = model.generate(
|
| 54 |
-
input_ids=inputs.input_ids,
|
| 55 |
-
attention_mask=inputs.attention_mask,
|
| 56 |
-
max_new_tokens=100,
|
| 57 |
-
do_sample=False,
|
| 58 |
-
repetition_penalty=1.2
|
| 59 |
-
)
|
| 60 |
-
|
| 61 |
-
# デコード
|
| 62 |
-
response = tokenizer.decode(
|
| 63 |
-
outputs[0][inputs.input_ids.size(1):],
|
| 64 |
-
skip_special_tokens=True
|
| 65 |
-
)
|
| 66 |
-
|
| 67 |
-
return response
|
| 68 |
|
| 69 |
-
|
| 70 |
-
prompt = "日本の首都について教えてください。"
|
| 71 |
-
print(generate_response(prompt))
|
| 72 |
-
```
|
| 73 |
-
|
| 74 |
-
## 注意事項
|
| 75 |
-
|
| 76 |
-
- このモデルは `CC-BY-NC-SA` ライセンスの下で提供されています
|
| 77 |
-
- 非営利目的での使用に限定されます
|
| 78 |
-
- 元のデータセットと同様のライセンス条件が適用されます
|
| 79 |
|
| 80 |
## 引用情報
|
| 81 |
|
|
@@ -84,16 +44,8 @@ print(generate_response(prompt))
|
|
| 84 |
- "ichikara-instruction: LLMのための日本語インストラクションデータの構築"
|
| 85 |
- 言語処理学会第30回年次大会 (2024)
|
| 86 |
|
| 87 |
-
##
|
| 88 |
-
|
| 89 |
-
1. CUDA out of memory エラー
|
| 90 |
-
- `device_map="auto"` を `device_map="balanced"` に変更
|
| 91 |
-
- バッチサイズを減らす
|
| 92 |
-
- より大きなGPUを使用
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
- torch: 2.0以降
|
| 98 |
-
- accelerate: 最新版
|
| 99 |
-
- peft: 最新版
|
|
|
|
| 4 |
- llm-jp/llm-jp-3-13b
|
| 5 |
---
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
## モデルのロードと推論
|
| 8 |
|
| 9 |
### Pythonスクリプト例
|
| 10 |
|
| 11 |
```python
|
| 12 |
+
from tqdm import tqdm
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
results = []
|
| 15 |
+
for data in tqdm(datasets):
|
|
|
|
| 16 |
|
| 17 |
+
input = data["input"]
|
|
|
|
| 18 |
|
| 19 |
+
prompt = f"""### 指示
|
| 20 |
+
{input}
|
| 21 |
+
### 回答
|
| 22 |
+
"""
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
|
| 25 |
+
attention_mask = torch.ones_like(tokenized_input)
|
|
|
|
| 26 |
|
| 27 |
+
with torch.no_grad():
|
| 28 |
+
outputs = model.generate(
|
| 29 |
+
tokenized_input,
|
| 30 |
+
attention_mask=attention_mask,
|
| 31 |
+
max_new_tokens=100,
|
| 32 |
+
do_sample=False,
|
| 33 |
+
repetition_penalty=1.2,
|
| 34 |
+
pad_token_id=tokenizer.eos_token_id
|
| 35 |
+
)[0]
|
| 36 |
+
output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
results.append({"task_id": data["task_id"], "input": input, "output": output})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
## 引用情報
|
| 41 |
|
|
|
|
| 44 |
- "ichikara-instruction: LLMのための日本語インストラクションデータの構築"
|
| 45 |
- 言語処理学会第30回年次大会 (2024)
|
| 46 |
|
| 47 |
+
## モデルの情報
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
- 開発者情報: YAI
|
| 50 |
+
- ライセンス: cc-by-nc-sa-4.0
|
| 51 |
+
- Finetuned from model : llm-jp/llm-jp-3-13b
|
|
|
|
|
|
|
|
|