Update README.md
Browse files
README.md
CHANGED
|
@@ -9,4 +9,24 @@ base_model:
|
|
| 9 |
- HuggingFaceTB/SmolLM2-360M-Instruct
|
| 10 |
pipeline_tag: text-generation
|
| 11 |
---
|
| 12 |
-
v1: SFT -- 7658aab7702e56d9f5fa3b33bf7adcdae92f536b
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
- HuggingFaceTB/SmolLM2-360M-Instruct
|
| 10 |
pipeline_tag: text-generation
|
| 11 |
---
|
| 12 |
+
v1: SFT -- 7658aab7702e56d9f5fa3b33bf7adcdae92f536b
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
|
| 17 |
+
rom transformers import AutoModelForCausalLM, AutoTokenizer
|
| 18 |
+
checkpoint = "HuggingFaceTB/SmolLM2-360M-Instruct"
|
| 19 |
+
|
| 20 |
+
device = "cuda" # for GPU usage or "cpu" for CPU usage
|
| 21 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
| 22 |
+
# for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`
|
| 23 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
|
| 24 |
+
|
| 25 |
+
messages = [{"role": "user", "content": "What is the capital of France."}]
|
| 26 |
+
input_text=tokenizer.apply_chat_template(messages, tokenize=False)
|
| 27 |
+
print(input_text)
|
| 28 |
+
inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
|
| 29 |
+
outputs = model.generate(inputs, max_new_tokens=50, temperature=0.2, top_p=0.9, do_sample=True)
|
| 30 |
+
print(tokenizer.decode(outputs[0]))
|
| 31 |
+
|
| 32 |
+
```
|