hotaru14 commited on
Commit
9cc5c38
·
verified ·
1 Parent(s): 867893f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +87 -0
README.md CHANGED
@@ -20,3 +20,90 @@ 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
+ # Google colaboratory
26
+ ---
27
+
28
+ !pip install -U bitsandbytes
29
+ !pip install -U transformers
30
+ !pip install -U accelerate
31
+ !pip install -U datasets
32
+ !pip install ipywidgets --upgrade
33
+ from transformers import (
34
+ AutoModelForCausalLM,
35
+ AutoTokenizer,
36
+ BitsAndBytesConfig,
37
+ )
38
+ import torch
39
+ from tqdm import tqdm
40
+ import json
41
+ import os
42
+ from google.colab import userdata
43
+ os.environ["HF_TOKEN"] = userdata.get("HF_TOKEN")
44
+ HF_TOKEN = os.environ["HF_TOKEN"]
45
+
46
+ # My model and tokenizer
47
+ model_name = "hotaru14/llm-jp-3-13b-finetune-2-LoRA"
48
+ tokenizer_name = "hotaru14/llm-jp-3-13b-finetune-tokenizer"
49
+
50
+ # QLoRA config
51
+ bnb_config = BitsAndBytesConfig(
52
+ load_in_4bit=True,
53
+ bnb_4bit_quant_type="nf4",
54
+ bnb_4bit_compute_dtype=torch.bfloat16,
55
+ bnb_4bit_use_double_quant=False,
56
+ )
57
+
58
+ # Load model
59
+ model = AutoModelForCausalLM.from_pretrained(
60
+ model_name,
61
+ quantization_config=bnb_config,
62
+ device_map="auto",
63
+ token = HF_TOKEN
64
+ )
65
+
66
+ # Load tokenizer
67
+ tokenizer = AutoTokenizer.from_pretrained(tokenizer_name, trust_remote_code=True, token = HF_TOKEN)
68
+
69
+ # データセットの読み込み。
70
+ datasets = []
71
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
72
+ item = ""
73
+ for line in f:
74
+ line = line.strip()
75
+ item += line
76
+ if item.endswith("}"):
77
+ datasets.append(json.loads(item))
78
+ item = ""
79
+
80
+ results = []
81
+ for data in tqdm(datasets):
82
+
83
+ input = data["input"]
84
+
85
+ prompt = f"""### 指示
86
+ {input}
87
+ ### 回答:
88
+ """
89
+
90
+ tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
91
+ with torch.no_grad():
92
+ outputs = model.generate(
93
+ tokenized_input,
94
+ max_new_tokens=100,
95
+ do_sample=False,
96
+ repetition_penalty=1.2
97
+ )[0]
98
+ output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
99
+
100
+ results.append({"task_id": data["task_id"], "input": input, "output": output})
101
+
102
+ import re
103
+ model_name = re.sub(".*/", "", model_name)
104
+ with open(f"./{model_name}-outputs.jsonl", 'w', encoding='utf-8') as f:
105
+ for result in results:
106
+ json.dump(result, f, ensure_ascii=False) # ensure_ascii=False for handling non-ASCII characters
107
+ f.write('\n')
108
+
109
+ ---