ppapppapppap commited on
Commit
2e12470
·
verified ·
1 Parent(s): 8626856

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +76 -0
README.md CHANGED
@@ -20,3 +20,79 @@ 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
+
26
+ 以下は、elyza-tasks-100-TV_0.jsonlの回答のためのコードです。
27
+
28
+
29
+ '''python
30
+ from transformers import (
31
+ AutoModelForCausalLM,
32
+ AutoTokenizer,
33
+ BitsAndBytesConfig,
34
+ )
35
+ import torch
36
+ from tqdm import tqdm
37
+ import json
38
+
39
+ HF_TOKEN = "your-token"
40
+
41
+ model_name = "ppapppapppap/llm-jp-3-13b-it"
42
+
43
+ bnb_config = BitsAndBytesConfig(
44
+ load_in_4bit=True,
45
+ bnb_4bit_quant_type="nf4",
46
+ bnb_4bit_compute_dtype=torch.bfloat16,
47
+ bnb_4bit_use_double_quant=False,
48
+ )
49
+
50
+ model = AutoModelForCausalLM.from_pretrained(
51
+ model_name,
52
+ quantization_config=bnb_config,
53
+ device_map="auto",
54
+ token = HF_TOKEN
55
+ )
56
+
57
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, token = HF_TOKEN)
58
+
59
+ datasets = []
60
+ with open("/content/elyza-tasks-100-TV_0.jsonl", "r") as f:
61
+ item = ""
62
+ for line in f:
63
+ line = line.strip()
64
+ item += line
65
+ if item.endswith("}"):
66
+ datasets.append(json.loads(item))
67
+ item = ""
68
+
69
+ results = []
70
+ for data in tqdm(datasets):
71
+
72
+ input = data["input"]
73
+
74
+ prompt = f"""### 指示
75
+ {input}
76
+ ### 回答:
77
+ """
78
+
79
+ tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
80
+ with torch.no_grad():
81
+ outputs = model.generate(
82
+ tokenized_input,
83
+ max_new_tokens=100,
84
+ do_sample=False,
85
+ repetition_penalty=1.2
86
+ )[0]
87
+ output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
88
+
89
+ results.append({"task_id": data["task_id"], "input": input, "output": output})
90
+
91
+ import re
92
+ model_name = re.sub(".*/", "", model_name)
93
+ with open(f"./{model_name}-outputs.jsonl", 'w', encoding='utf-8') as f:
94
+ for result in results:
95
+ json.dump(result, f, ensure_ascii=False) # ensure_ascii=False for handling non-ASCII characters
96
+ f.write('\n')
97
+
98
+ '''