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