hikahika commited on
Commit
ac202b2
·
verified ·
1 Parent(s): e9ee614

Update README.md

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