Update README.md
Browse files
README.md
CHANGED
@@ -125,46 +125,49 @@ import torch
|
|
125 |
|
126 |
# Load tokenizer and model
|
127 |
model_name = "snuh/hari-q2.5"
|
128 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
129 |
-
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
|
130 |
-
model.eval()
|
131 |
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
messages = [
|
134 |
-
{
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
146 |
]
|
147 |
|
148 |
-
|
149 |
-
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
150 |
-
|
151 |
-
# Tokenize input
|
152 |
-
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
153 |
-
|
154 |
-
# Generate model output
|
155 |
-
with torch.no_grad():
|
156 |
-
outputs = model.generate(
|
157 |
-
**inputs,
|
158 |
-
max_new_tokens=128,
|
159 |
-
do_sample=True,
|
160 |
-
temperature=0.7,
|
161 |
-
top_p=0.9,
|
162 |
-
eos_token_id=tokenizer.eos_token_id,
|
163 |
-
)
|
164 |
-
|
165 |
-
# Decode and display response
|
166 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
167 |
-
print("π§ Model Response:\n")
|
168 |
print(response)
|
169 |
````
|
170 |
|
|
|
125 |
|
126 |
# Load tokenizer and model
|
127 |
model_name = "snuh/hari-q2.5"
|
|
|
|
|
|
|
128 |
|
129 |
+
model = AutoModelForCausalLM.from_pretrained(
|
130 |
+
model_name,
|
131 |
+
torch_dtype="auto",
|
132 |
+
device_map="auto"
|
133 |
+
)
|
134 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
135 |
+
|
136 |
+
prompt = '''
|
137 |
+
### Instruction:
|
138 |
+
λΉμ μ μμ μ§μμ κ°μΆ μ λ₯νκ³ μ λ’°ν μ μλ νκ΅μ΄ κΈ°λ° μλ£ μ΄μμ€ν΄νΈμ
λλ€.
|
139 |
+
μ¬μ©μμ μ§λ¬Έμ λν΄ μ ννκ³ μ μ€ν μμ μΆλ‘ μ λ°νμΌλ‘ μ§λ¨ κ°λ₯μ±μ μ μν΄ μ£ΌμΈμ.
|
140 |
+
λ°λμ νμμ μ°λ Ή, μ¦μ, κ²μ¬ κ²°κ³Ό, ν΅μ¦ λΆμ λ± λͺ¨λ λ¨μλ₯Ό μ’
ν©μ μΌλ‘ κ³ λ €νμ¬ μΆλ‘ κ³Όμ κ³Ό μ§λ¨λͺ
μ μ μν΄μΌ ν©λλ€.
|
141 |
+
μνμ μΌλ‘ μ νν μ©μ΄λ₯Ό μ¬μ©νλ, νμνλ€λ©΄ μΌλ°μΈμ΄ μ΄ν΄νκΈ° μ¬μ΄ μ©μ΄λ λ³νν΄ μ€λͺ
ν΄ μ£ΌμΈμ.
|
142 |
+
|
143 |
+
### Question:
|
144 |
+
60μΈ λ¨μ±μ΄ 볡ν΅κ³Ό λ°μ΄μ νΈμνλ©° λ΄μνμμ΅λλ€.
|
145 |
+
νμ‘ κ²μ¬ κ²°κ³Ό λ°±νꡬ μμΉκ° μμΉνκ³ , μ°μΈ‘ νλ³΅λΆ μν΅μ΄ νμΈλμμ΅λλ€.
|
146 |
+
κ°μ₯ κ°λ₯μ±μ΄ λμ μ§λ¨λͺ
μ 무μμΈκ°μ?
|
147 |
+
|
148 |
+
### Reasoning:
|
149 |
+
'''.strip()
|
150 |
+
|
151 |
messages = [
|
152 |
+
{"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
|
153 |
+
{"role": "user", "content": prompt}
|
154 |
+
]
|
155 |
+
text = tokenizer.apply_chat_template(
|
156 |
+
messages,
|
157 |
+
tokenize=False,
|
158 |
+
add_generation_prompt=True
|
159 |
+
)
|
160 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
161 |
+
|
162 |
+
generated_ids = model.generate(
|
163 |
+
**model_inputs,
|
164 |
+
max_new_tokens=512
|
165 |
+
)
|
166 |
+
generated_ids = [
|
167 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
168 |
]
|
169 |
|
170 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
print(response)
|
172 |
````
|
173 |
|