Update README.md
Browse files
README.md
CHANGED
@@ -20,3 +20,50 @@ tags:
|
|
20 |
This qwen2 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 qwen2 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 |
+
### 🤗 Hugging Face Transformers
|
25 |
+
|
26 |
+
Qwen2.5-Math can be deployed and infered in the same way as [Qwen2.5](https://github.com/QwenLM/Qwen2.5). Here we show a code snippet to show you how to use the chat model with `transformers`:
|
27 |
+
|
28 |
+
```python
|
29 |
+
|
30 |
+
from unsloth import FastLanguageModel
|
31 |
+
import torch
|
32 |
+
max_seq_length = 4096 # Choose any! We auto support RoPE Scaling internally!
|
33 |
+
dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
|
34 |
+
load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
|
35 |
+
|
36 |
+
|
37 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
38 |
+
model_name = "thanhkt/Qwen2.5-1.5B-MathInstruct",
|
39 |
+
max_seq_length = max_seq_length,
|
40 |
+
dtype = dtype,
|
41 |
+
load_in_4bit = load_in_4bit,
|
42 |
+
# token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
|
43 |
+
)
|
44 |
+
alpaca_prompt = """Below...
|
45 |
+
|
46 |
+
### Instruct:
|
47 |
+
{}
|
48 |
+
|
49 |
+
### Input:
|
50 |
+
{}
|
51 |
+
|
52 |
+
### Output:
|
53 |
+
{}"""
|
54 |
+
|
55 |
+
FastLanguageModel.for_inference(model) # Enable native 2x faster inference
|
56 |
+
inputs = tokenizer(
|
57 |
+
[
|
58 |
+
alpaca_prompt.format(
|
59 |
+
"""You are a teacher , you can explain the complex things with simple word""", # instruction
|
60 |
+
"What is word 2 vec", # input
|
61 |
+
"", # output - leave this blank for generation!
|
62 |
+
)
|
63 |
+
], return_tensors = "pt").to("cuda")
|
64 |
+
|
65 |
+
from transformers import TextStreamer
|
66 |
+
text_streamer = TextStreamer(tokenizer)
|
67 |
+
_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 512)
|
68 |
+
```
|
69 |
+
|