Views
No views yet
1model_id = "llm-jp/llm-jp-3-13b"
2adapter_id = "sam-murayama/llm-jp-3-13b-it_03_lora"
3
4HF_TOKEN = "Your Token" #@param {type:"string"}
5
6dtype = None
7load_in_4bit = True
8
9model, tokenizer = FastLanguageModel.from_pretrained(
10 model_name=model_id,
11 dtype=dtype,
12 load_in_4bit=load_in_4bit,
13 trust_remote_code=True,
14)
15
16model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
17
18datasets = []
19with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
20 item = ""
21 for line in f:
22 line = line.strip()
23 item += line
24 if item.endswith("}"):
25 datasets.append(json.loads(item))
26 item = ""
27
28FastLanguageModel.for_inference(model)
29
30results = []
31for dt in tqdm(datasets):
32 input = dt["input"]
33
34 prompt = f"""### 指示\n{input}\n### 回答\n"""
35
36 inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
37
38 outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
39 prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
40
41 results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
42
43json_file_id = re.sub(".*/", "", adapter_id)
44with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
45 for result in results:
46 json.dump(result, f, ensure_ascii=False)
47 f.write('\n')