Update README.md
Browse files
README.md
CHANGED
|
@@ -22,5 +22,82 @@ This llama model was trained 2x faster with [Unsloth](https://github.com/unsloth
|
|
| 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 |
# 24/11/24版のLoRA_template_unsloth2.ipynbを3度使用
|
| 25 |
-
ichikara-instruction-003-002-1_trans.json でSFTを行ったモデルに対し、 ichikara-instruction-003-001-2.json と ichikara-instruction-003-001-5.jsonを混合したdatasetで追加事後学習
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
# 24/11/24版のLoRA_template_unsloth2.ipynbを3度使用
|
| 25 |
+
#ichikara-instruction-003-002-1_trans.json でSFTを行ったモデルに対し、 ichikara-instruction-003-001-2.json と ichikara-instruction-003-001-5.jsonを混合したdatasetで追加事後学習
|
| 26 |
+
#その後、ichikara-instruction-003-001-1.jsonにて追加事後学習実施
|
| 27 |
+
|
| 28 |
+
#以下コードにて推論可能
|
| 29 |
+
# 必要なライブラリをインストール
|
| 30 |
+
%%capture
|
| 31 |
+
!pip install unsloth
|
| 32 |
+
!pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
| 33 |
+
!pip install -U torch
|
| 34 |
+
!pip install -U peft
|
| 35 |
+
|
| 36 |
+
# 必要なライブラリを読み込み
|
| 37 |
+
from unsloth import FastLanguageModel
|
| 38 |
+
from peft import PeftModel
|
| 39 |
+
import torch
|
| 40 |
+
import json
|
| 41 |
+
from tqdm import tqdm
|
| 42 |
+
import re
|
| 43 |
+
|
| 44 |
+
import os # osモジュールをインポート
|
| 45 |
+
# アクセストークンを設定 (プライベートリポジトリの場合)
|
| 46 |
+
os.environ["HUGGING_FACE_HUB_TOKEN"] = "my_token"
|
| 47 |
+
|
| 48 |
+
model_id = "kochan13/llm-jp-3-13b-8"
|
| 49 |
+
|
| 50 |
+
# Hugging Face Token を指定。
|
| 51 |
+
# 下記の URL から Hugging Face Token を取得できますので下記の HF_TOKEN に入れてください。
|
| 52 |
+
# https://huggingface.co/settings/tokens
|
| 53 |
+
HF_TOKEN = "" #@param {type:"string"}
|
| 54 |
+
|
| 55 |
+
# unslothのFastLanguageModelで元のモデルをロード。
|
| 56 |
+
dtype = None # Noneにしておけば自動で設定
|
| 57 |
+
load_in_4bit = True # 今回は13Bモデルを扱うためTrue
|
| 58 |
+
|
| 59 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 60 |
+
model_name=model_id,
|
| 61 |
+
dtype=dtype,
|
| 62 |
+
load_in_4bit=load_in_4bit,
|
| 63 |
+
trust_remote_code=True,
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
# タスクとなるデータの読み込み。
|
| 67 |
+
# 事前にデータをアップロードしてください。
|
| 68 |
+
datasets = []
|
| 69 |
+
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
| 70 |
+
item = ""
|
| 71 |
+
for line in f:
|
| 72 |
+
line = line.strip()
|
| 73 |
+
item += line
|
| 74 |
+
if item.endswith("}"):
|
| 75 |
+
datasets.append(json.loads(item))
|
| 76 |
+
item = ""
|
| 77 |
+
|
| 78 |
+
# モデルを用いてタスクの推論。
|
| 79 |
+
|
| 80 |
+
# 推論するためにモデルのモードを変更
|
| 81 |
+
FastLanguageModel.for_inference(model)
|
| 82 |
+
|
| 83 |
+
results = []
|
| 84 |
+
for dt in tqdm(datasets):
|
| 85 |
+
input = dt["input"]
|
| 86 |
+
|
| 87 |
+
prompt = f"""### 指示\n{input}\n### 回答\n"""
|
| 88 |
+
|
| 89 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
| 90 |
+
|
| 91 |
+
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
| 92 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
| 93 |
+
|
| 94 |
+
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
| 95 |
+
|
| 96 |
+
# 結果をjsonlで保存。
|
| 97 |
+
|
| 98 |
+
# ここではadapter_idを元にファイル名を決定しているが、ファイル名は任意で問題なし。
|
| 99 |
+
json_file_id = re.sub(".*/", "", adapter_id)
|
| 100 |
+
with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
| 101 |
+
for result in results:
|
| 102 |
+
json.dump(result, f, ensure_ascii=False)
|
| 103 |
+
f.write('\n')
|