Views
No views yet
llm-jp/llm-jp-3-13bをベースモデルとして、ichikara-instructionデータとELYZA-tasks-100を用いてファインチューニングを行っています。
| Language | Dataset | Description |
|---|---|---|
| Japanese | ichikara-instruction-003-001-1.json | 日本語指示データセット |
| Japanese | ichikara-instruction-003-003-1.fixed.json | ichikara-instruction-003-003-1.json の無効なエスケープシーケンスを手動修正したデータセット |
| Japanese | elyza/ELYZA-tasks-100 | 日本語多目的タスク用データセット |
1!pip install -U unsloth
2!pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
3!pip install -U torch
4!pip install -U peft1from unsloth import FastLanguageModel
2from peft import PeftModel
3import torch
4import json
5from tqdm import tqdm
6import reHF_TOKEN = "YOUR-HF-TOKEN"1# ベースモデルと学習済みLoRAアダプタ(Hugging FaceのIDを指定)。
2model_id = "llm-jp/llm-jp-3-13b"
3adapter_id = "KKFurudate/llm-jp-3-13b-v6_lora"1# unslothのFastLanguageModelでベースのモデルをロード。
2dtype = None
3load_in_4bit = True
4
5model, tokenizer = FastLanguageModel.from_pretrained(
6 model_name=model_id,
7 dtype=dtype,
8 load_in_4bit=load_in_4bit,
9 trust_remote_code=True,
10)1# ベースモデルに学習済みLoRAのアダプタを統合。
2model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)1datasets = []
2with open("./YOUR-DATA.jsonl", "r") as f:
3 item = ""
4 for line in f:
5 line = line.strip()
6 item += line
7 if item.endswith("}"):
8 datasets.append(json.loads(item))
9 item = ""1# 統合モデルを用いてタスクの推論。
2FastLanguageModel.for_inference(model)
3
4results = []
5for dt in tqdm(datasets):
6 input = dt["input"]
7
8 prompt = f"""### 指示\n{input}\n### 回答\n"""
9
10 inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
11
12 outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
13 prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
14
15 results.append({"task_id": dt["task_id"], "input": input, "output": prediction})1# 結果をjsonlで保存。
2json_file_id = re.sub(".*/", "", adapter_id)
3with open(f"{outdir}/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
4 for result in results:
5 json.dump(result, f, ensure_ascii=False)
6 f.write('\n')