Views
No views yet
1pip install unsloth
2pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
3pip install -U torch
4pip install -U peft1from unsloth import FastLanguageModel
2from peft import PeftModel
3import torch
4import json
5from tqdm import tqdm
6import re
7model_id = "llm-jp/llm-jp-3-13b"
8adapter_id = "baxin/llm-jp-3-13b-it-seq-r-la_lora_test"
9
10HF_TOKEN=""
11
12dtype = None
13load_in_4bit = True
14
15model, tokenizer = FastLanguageModel.from_pretrained(
16 model_name=model_id,
17 dtype=dtype,
18 load_in_4bit=load_in_4bit,
19 trust_remote_code=True,
20)
21
22model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
23
24# load elyza-tasks-100-TV jsonl
25datasets = []
26with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
27 item = ""
28 for line in f:
29 line = line.strip()
30 item += line
31 if item.endswith("}"):
32 datasets.append(json.loads(item))
33 item = ""
34
35FastLanguageModel.for_inference(model)
36
37system_prompt = "あなたは指示に注意深く従う親切なアシスタントです。指示をステップバイステップで理解し、回答してください。"
38
39results = []
40for dt in tqdm(datasets):
41 input = dt["input"]
42
43 prompt = f"""{system_prompt}\n\n### 指示\n{input}\n### 回答\n"""
44
45 inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
46
47 outputs = model.generate(**inputs, max_new_tokens = 3072, use_cache = True, do_sample=False, repetition_penalty=1.2)
48 prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
49
50 results.append({"task_id": dt["task_id"], "input": input, "output": prediction})