tehiro commited on
Commit
4175b2c
·
verified ·
1 Parent(s): f726b5f
Files changed (1) hide show
  1. README.md +61 -0
README.md CHANGED
@@ -20,3 +20,64 @@ 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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Sample use
26
+ # 以下は、elyza-tasks-100-TV.jsonlの回答のためのコードです。
27
+
28
+ """python, Google Colab
29
+ %%capture
30
+ !pip install unsloth
31
+ !pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
32
+
33
+ from unsloth import FastLanguageModel
34
+ import torch
35
+ import json
36
+
37
+ model_name = "YOUR_ACCOUNT/llm-jp-3-13b-finetune-2"
38
+
39
+ max_seq_length = 2048
40
+ dtype = None
41
+ load_in_4bit = True
42
+
43
+ model, tokenizer = FastLanguageModel.from_pretrained(
44
+ model_name = model_name,
45
+ max_seq_length = max_seq_length,
46
+ dtype = dtype,
47
+ load_in_4bit = load_in_4bit,
48
+ token = "HF_TOKEN",
49
+ )
50
+ FastLanguageModel.for_inference(model)
51
+
52
+ # データセットの読み込み。
53
+ datasets = []
54
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
55
+ item = ""
56
+ for line in f:
57
+ line = line.strip()
58
+ item += line
59
+ if item.endswith("}"):
60
+ datasets.append(json.loads(item))
61
+ item = ""
62
+
63
+ from tqdm import tqdm
64
+
65
+ # 推論
66
+ results = []
67
+ for dt in tqdm(datasets):
68
+ input = dt["input"]
69
+
70
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
71
+
72
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
73
+
74
+ outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
75
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
76
+
77
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
78
+
79
+ with open(f"/content/{model_name}_output.jsonl", 'w', encoding='utf-8') as f:
80
+ for result in results:
81
+ json.dump(result, f, ensure_ascii=False)
82
+ f.write('\n')
83
+ """