tatsurou commited on
Commit
c9008b7
·
verified ·
1 Parent(s): 3ee5c59

Update README

Browse files
Files changed (1) hide show
  1. README.md +77 -0
README.md CHANGED
@@ -11,6 +11,83 @@ language:
11
  - en
12
  ---
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  # Uploaded model
15
 
16
  - **Developed by:** tatsurou
 
11
  - en
12
  ---
13
 
14
+ # How to output
15
+ LLMでの出力方法
16
+
17
+ ```python3
18
+ from transformers import (
19
+ AutoModelForCausalLM,
20
+ AutoTokenizer,
21
+ BitsAndBytesConfig,
22
+ )
23
+ import torch
24
+ from tqdm import tqdm
25
+ import json
26
+
27
+ HF_TOKEN = "HF_TOKEN"
28
+ model_name = "tatsurou/llm-jp-3-13b-ft-20241123"
29
+
30
+ # QLoRA config
31
+ bnb_config = BitsAndBytesConfig(
32
+ load_in_4bit=True,
33
+ bnb_4bit_quant_type="nf4",
34
+ bnb_4bit_compute_dtype=torch.bfloat16,
35
+ bnb_4bit_use_double_quant=False,
36
+ )
37
+
38
+ # Load model
39
+ model = AutoModelForCausalLM.from_pretrained(
40
+ model_name,
41
+ quantization_config=bnb_config,
42
+ device_map="auto",
43
+ token = HF_TOKEN
44
+ )
45
+
46
+ # Load tokenizer
47
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, token = HF_TOKEN)
48
+
49
+ # データセットの読み込み。
50
+ datasets = []
51
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
52
+ item = ""
53
+ for line in f:
54
+ line = line.strip()
55
+ item += line
56
+ if item.endswith("}"):
57
+ datasets.append(json.loads(item))
58
+ item = ""
59
+ results = []
60
+ for data in tqdm(datasets):
61
+
62
+ input = data["input"]
63
+
64
+ prompt = f"""### 指示
65
+ {input}
66
+ ### 回答:
67
+ """
68
+
69
+ tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
70
+ with torch.no_grad():
71
+ outputs = model.generate(
72
+ tokenized_input,
73
+ max_new_tokens=300,
74
+ do_sample=False,
75
+ repetition_penalty=1.2
76
+ )[0]
77
+ output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
78
+
79
+ results.append({"task_id": data["task_id"], "input": input, "output": output})
80
+
81
+ import re
82
+ model_name = re.sub(".*/", "", model_name)
83
+ with open(f"./{model_name}-my-original-outputs.jsonl", 'w', encoding='utf-8') as f:
84
+ for result in results:
85
+ json.dump(result, f, ensure_ascii=False) # ensure_ascii=False for handling non-ASCII characters
86
+ f.write('\n')
87
+
88
+ ```
89
+
90
+
91
  # Uploaded model
92
 
93
  - **Developed by:** tatsurou