Update README.md
#1
by
tomofusa
- opened
README.md
CHANGED
@@ -8,7 +8,7 @@ tags:
|
|
8 |
- trl
|
9 |
license: apache-2.0
|
10 |
language:
|
11 |
-
-
|
12 |
---
|
13 |
|
14 |
# Uploaded model
|
@@ -20,3 +20,109 @@ 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
- trl
|
9 |
license: apache-2.0
|
10 |
language:
|
11 |
+
- ja
|
12 |
---
|
13 |
|
14 |
# Uploaded model
|
|
|
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 |
+
# How to use
|
27 |
+
|
28 |
+
There are the normal steps from sample codes.
|
29 |
+
|
30 |
+
0. ready to (you can skip this step in Google Colaboratry. )
|
31 |
+
|
32 |
+
```shell
|
33 |
+
# conda環境の構築
|
34 |
+
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
|
35 |
+
|
36 |
+
# このコマンドではいくつか質問があるので答えて下さい。おそらくインストール先のデフォルトは/root/miniforge3かと思います
|
37 |
+
bash Miniforge3-$(uname)-$(uname -m).sh
|
38 |
+
|
39 |
+
# 以下、インストール先が/root/miniforge3であることを前提とします
|
40 |
+
export PATH=/root/miniforge3/bin:$PATH
|
41 |
+
conda init
|
42 |
+
|
43 |
+
# ここで一度、terminalを立ち上げ直す必要があります。
|
44 |
+
# 以下のリンク先に従い環境を作ります。
|
45 |
+
# https://docs.unsloth.ai/get-started/installation/conda-install
|
46 |
+
conda create --name unsloth_env python=3.10 pytorch-cuda=12.1 pytorch cudatoolkit xformers -c pytorch -c nvidia -c xformers -y
|
47 |
+
conda activate unsloth_env
|
48 |
+
pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
49 |
+
pip install --no-deps "trl<0.9.0" peft accelerate bitsandbytes
|
50 |
+
|
51 |
+
# jupyter notebook用のセットアップ。
|
52 |
+
conda install -c conda-forge ipykernel
|
53 |
+
python -m ipykernel install --user --name=unsloth_env --display-name "Python (unsloth_env)"
|
54 |
+
```
|
55 |
+
|
56 |
+
## Follow these steps, run in the notebook:
|
57 |
+
|
58 |
+
1. load model
|
59 |
+
```shell
|
60 |
+
%%capture
|
61 |
+
!pip install unsloth
|
62 |
+
!pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
63 |
+
```
|
64 |
+
|
65 |
+
```python
|
66 |
+
from unsloth import FastLanguageModel
|
67 |
+
import torch
|
68 |
+
import json
|
69 |
+
|
70 |
+
model_name = "tomofusa/llm-jp-3-13b-finetune-2"
|
71 |
+
|
72 |
+
max_seq_length = 2048
|
73 |
+
dtype = None
|
74 |
+
load_in_4bit = True
|
75 |
+
|
76 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
77 |
+
model_name = model_name,
|
78 |
+
max_seq_length = max_seq_length,
|
79 |
+
dtype = dtype,
|
80 |
+
load_in_4bit = load_in_4bit,
|
81 |
+
# token = "hf-token", # In the Google Colab case, it call from ENV. If you want to write the token directly, please comment it out.
|
82 |
+
)
|
83 |
+
FastLanguageModel.for_inference(model)
|
84 |
+
```
|
85 |
+
|
86 |
+
3. Set up datasets and run inference.
|
87 |
+
|
88 |
+
- Upload elyza-tasks-100-TV_0.jsonl to your workspace in manual.
|
89 |
+
|
90 |
+
```python
|
91 |
+
datasets = []
|
92 |
+
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
93 |
+
item = ""
|
94 |
+
for line in f:
|
95 |
+
line = line.strip()
|
96 |
+
item += line
|
97 |
+
if item.endswith("}"):
|
98 |
+
datasets.append(json.loads(item))
|
99 |
+
item = ""
|
100 |
+
```
|
101 |
+
|
102 |
+
```python
|
103 |
+
from tqdm import tqdm
|
104 |
+
|
105 |
+
# inference
|
106 |
+
results = []
|
107 |
+
for dt in tqdm(datasets):
|
108 |
+
input = dt["input"]
|
109 |
+
|
110 |
+
prompt = f"""### 指示\n{input}\n### 回答\n"""
|
111 |
+
|
112 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
113 |
+
|
114 |
+
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
115 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
116 |
+
|
117 |
+
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
118 |
+
```
|
119 |
+
|
120 |
+
4. Save results to jsonl.
|
121 |
+
|
122 |
+
```python
|
123 |
+
file_name = model_name.replace("/", "_") + "_output.jsonl"
|
124 |
+
with open(f"./{file_name}", 'w', encoding='utf-8') as f:
|
125 |
+
for result in results:
|
126 |
+
json.dump(result, f, ensure_ascii=False)
|
127 |
+
f.write('\n')
|
128 |
+
```
|