Update README.md
Browse files
README.md
CHANGED
@@ -29,4 +29,82 @@ This llama model was trained 2x faster with [Unsloth](https://github.com/unsloth
|
|
29 |
|
30 |
|
31 |
■このモデルは東京大学リスキリング講座「大規模言語モデル2024」の最終課題(コンペ)のためのものです。
|
32 |
-
「ELYZA-tasks-100-TV」というデータセットが配布され、精度を競います。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
|
31 |
■このモデルは東京大学リスキリング講座「大規模言語モデル2024」の最終課題(コンペ)のためのものです。
|
32 |
+
「ELYZA-tasks-100-TV」というデータセットが配布され、精度を競います。
|
33 |
+
|
34 |
+
# Sample Use
|
35 |
+
```python
|
36 |
+
from transformers import (
|
37 |
+
AutoModelForCausalLM,
|
38 |
+
AutoTokenizer,
|
39 |
+
BitsAndBytesConfig,
|
40 |
+
)
|
41 |
+
|
42 |
+
HF_TOKEN = "Hugging Face Token"
|
43 |
+
base_model_id = "llm-jp/llm-jp-3-13b"
|
44 |
+
adapter_id = "Namazu11/llm-jp-3-13b-sft-dpo2"
|
45 |
+
|
46 |
+
# QLoRA config
|
47 |
+
bnb_config = BitsAndBytesConfig(
|
48 |
+
load_in_4bit=True,
|
49 |
+
bnb_4bit_quant_type="nf4",
|
50 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
51 |
+
)
|
52 |
+
|
53 |
+
# Load model
|
54 |
+
model = AutoModelForCausalLM.from_pretrained(
|
55 |
+
model_id,
|
56 |
+
quantization_config=bnb_config,
|
57 |
+
device_map="auto",
|
58 |
+
token = HF_TOKEN
|
59 |
+
)
|
60 |
+
|
61 |
+
# Load tokenizer
|
62 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True, token = HF_TOKEN)
|
63 |
+
|
64 |
+
# 元のモデルにLoRAのアダプタを統合。
|
65 |
+
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
|
66 |
+
|
67 |
+
# データセットの読み込み。
|
68 |
+
datasets = []
|
69 |
+
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
70 |
+
item = ""
|
71 |
+
for line in f:
|
72 |
+
line = line.strip()
|
73 |
+
item += line
|
74 |
+
if item.endswith("}"):
|
75 |
+
datasets.append(json.loads(item))
|
76 |
+
item = ""
|
77 |
+
|
78 |
+
# 推論(llmjp)
|
79 |
+
results = []
|
80 |
+
for data in tqdm(datasets):
|
81 |
+
|
82 |
+
input = data["input"]
|
83 |
+
|
84 |
+
prompt = f"""### 指示
|
85 |
+
{input}
|
86 |
+
### 回答
|
87 |
+
"""
|
88 |
+
|
89 |
+
tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
|
90 |
+
attention_mask = torch.ones_like(tokenized_input)
|
91 |
+
with torch.no_grad():
|
92 |
+
outputs = model.generate(
|
93 |
+
tokenized_input,
|
94 |
+
attention_mask=attention_mask,
|
95 |
+
max_new_tokens=100,
|
96 |
+
do_sample=False,
|
97 |
+
repetition_penalty=1.2,
|
98 |
+
pad_token_id=tokenizer.eos_token_id
|
99 |
+
)[0]
|
100 |
+
output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
|
101 |
+
|
102 |
+
results.append({"task_id": data["task_id"], "input": input, "output": output})
|
103 |
+
|
104 |
+
# 出力結果のjsolファイル生成
|
105 |
+
import re
|
106 |
+
jsonl_id = re.sub(".*/", "", adapter_id)
|
107 |
+
with open(f"./{jsonl_id}-outputs.jsonl", 'w', encoding='utf-8') as f:
|
108 |
+
for result in results:
|
109 |
+
json.dump(result, f, ensure_ascii=False) # ensure_ascii=False for handling non-ASCII characters
|
110 |
+
f.write('\n')
|