Text Generation
Transformers
Safetensors
English
qwen2
unsloth
conversational
text-generation-inference
Instructions to use unsloth/Qwen2-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use unsloth/Qwen2-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="unsloth/Qwen2-7B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("unsloth/Qwen2-7B") model = AutoModelForCausalLM.from_pretrained("unsloth/Qwen2-7B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use unsloth/Qwen2-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "unsloth/Qwen2-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "unsloth/Qwen2-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/unsloth/Qwen2-7B
- SGLang
How to use unsloth/Qwen2-7B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "unsloth/Qwen2-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "unsloth/Qwen2-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "unsloth/Qwen2-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "unsloth/Qwen2-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio
How to use unsloth/Qwen2-7B with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/Qwen2-7B to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/Qwen2-7B to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for unsloth/Qwen2-7B to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="unsloth/Qwen2-7B", max_seq_length=2048, ) - Docker Model Runner
How to use unsloth/Qwen2-7B with Docker Model Runner:
docker model run hf.co/unsloth/Qwen2-7B
Upload tokenizer
Browse files- added_tokens.json +1 -0
- special_tokens_map.json +1 -7
- tokenizer.json +9 -0
- tokenizer_config.json +9 -1
added_tokens.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
{
|
|
|
|
| 2 |
"<|endoftext|>": 151643,
|
| 3 |
"<|im_end|>": 151645,
|
| 4 |
"<|im_start|>": 151644
|
|
|
|
| 1 |
{
|
| 2 |
+
"<|PAD_TOKEN|>": 151646,
|
| 3 |
"<|endoftext|>": 151643,
|
| 4 |
"<|im_end|>": 151645,
|
| 5 |
"<|im_start|>": 151644
|
special_tokens_map.json
CHANGED
|
@@ -10,11 +10,5 @@
|
|
| 10 |
"rstrip": false,
|
| 11 |
"single_word": false
|
| 12 |
},
|
| 13 |
-
"pad_token":
|
| 14 |
-
"content": "<|endoftext|>",
|
| 15 |
-
"lstrip": false,
|
| 16 |
-
"normalized": false,
|
| 17 |
-
"rstrip": false,
|
| 18 |
-
"single_word": false
|
| 19 |
-
}
|
| 20 |
}
|
|
|
|
| 10 |
"rstrip": false,
|
| 11 |
"single_word": false
|
| 12 |
},
|
| 13 |
+
"pad_token": "<|PAD_TOKEN|>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
}
|
tokenizer.json
CHANGED
|
@@ -29,6 +29,15 @@
|
|
| 29 |
"rstrip": false,
|
| 30 |
"normalized": false,
|
| 31 |
"special": true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
],
|
| 34 |
"normalizer": {
|
|
|
|
| 29 |
"rstrip": false,
|
| 30 |
"normalized": false,
|
| 31 |
"special": true
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"id": 151646,
|
| 35 |
+
"content": "<|PAD_TOKEN|>",
|
| 36 |
+
"single_word": false,
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"rstrip": false,
|
| 39 |
+
"normalized": false,
|
| 40 |
+
"special": true
|
| 41 |
}
|
| 42 |
],
|
| 43 |
"normalizer": {
|
tokenizer_config.json
CHANGED
|
@@ -24,6 +24,14 @@
|
|
| 24 |
"rstrip": false,
|
| 25 |
"single_word": false,
|
| 26 |
"special": true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
},
|
| 29 |
"additional_special_tokens": [
|
|
@@ -36,7 +44,7 @@
|
|
| 36 |
"eos_token": "<|endoftext|>",
|
| 37 |
"errors": "replace",
|
| 38 |
"model_max_length": 32768,
|
| 39 |
-
"pad_token": "<|
|
| 40 |
"padding_side": "left",
|
| 41 |
"split_special_tokens": false,
|
| 42 |
"tokenizer_class": "Qwen2Tokenizer",
|
|
|
|
| 24 |
"rstrip": false,
|
| 25 |
"single_word": false,
|
| 26 |
"special": true
|
| 27 |
+
},
|
| 28 |
+
"151646": {
|
| 29 |
+
"content": "<|PAD_TOKEN|>",
|
| 30 |
+
"lstrip": false,
|
| 31 |
+
"normalized": false,
|
| 32 |
+
"rstrip": false,
|
| 33 |
+
"single_word": false,
|
| 34 |
+
"special": true
|
| 35 |
}
|
| 36 |
},
|
| 37 |
"additional_special_tokens": [
|
|
|
|
| 44 |
"eos_token": "<|endoftext|>",
|
| 45 |
"errors": "replace",
|
| 46 |
"model_max_length": 32768,
|
| 47 |
+
"pad_token": "<|PAD_TOKEN|>",
|
| 48 |
"padding_side": "left",
|
| 49 |
"split_special_tokens": false,
|
| 50 |
"tokenizer_class": "Qwen2Tokenizer",
|