Update README.md
Browse files
README.md
CHANGED
@@ -20,3 +20,70 @@ language:
|
|
20 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
+
### 使用したdataset
|
27 |
+
下記からランダムに5000データを抽出
|
28 |
+
- DeL-TaiseiOzaki/Tengentoppa-sft-v1.0
|
29 |
+
- llm-jp/magpie-sft-v1.0
|
30 |
+
|
31 |
+
|
32 |
+
### 実行コード
|
33 |
+
|
34 |
+
|
35 |
+
```:Python
|
36 |
+
from tqdm import tqdm
|
37 |
+
import os
|
38 |
+
import json
|
39 |
+
|
40 |
+
import torch
|
41 |
+
from unsloth import FastLanguageModel
|
42 |
+
|
43 |
+
from transformers import (
|
44 |
+
AutoTokenizer,
|
45 |
+
AutoModelForCausalLM,
|
46 |
+
BitsAndBytesConfig,
|
47 |
+
)
|
48 |
+
|
49 |
+
HF_TOKEN = "your-token"
|
50 |
+
model_name = "ikedachin/llm-jp-3-13b-finetune-2"
|
51 |
+
|
52 |
+
# QLoRAの設定
|
53 |
+
bnb_config = BitsAndBytesConfig(
|
54 |
+
load_in_4bit=True,
|
55 |
+
bnb_4bit_quant_type="nf4",
|
56 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
57 |
+
bnb_4bit_use_double_quant=False,
|
58 |
+
|
59 |
+
)
|
60 |
+
|
61 |
+
# modelのダウンロード
|
62 |
+
model = AutoModelForCausalLM.from_pretrained(
|
63 |
+
model_name,
|
64 |
+
quantization_config=bnb_config,
|
65 |
+
device_map="auto",
|
66 |
+
token = HF_TOKEN
|
67 |
+
)
|
68 |
+
|
69 |
+
# tokenizerのダウンロード
|
70 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, token = HF_TOKEN)
|
71 |
+
|
72 |
+
|
73 |
+
prompt = "<ここに入力を入れる>"
|
74 |
+
|
75 |
+
# トークン化
|
76 |
+
tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
|
77 |
+
|
78 |
+
# 推論
|
79 |
+
with torch.no_grad():
|
80 |
+
outputs = model.generate(
|
81 |
+
tokenized_input,
|
82 |
+
max_new_tokens=300,
|
83 |
+
do_sample=False,
|
84 |
+
repetition_penalty=1.2
|
85 |
+
)[0]
|
86 |
+
|
87 |
+
# トークンから言葉にデコード
|
88 |
+
output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
|
89 |
+
```
|