Instructions to use tencent/Youtu-LLM-2B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tencent/Youtu-LLM-2B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tencent/Youtu-LLM-2B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tencent/Youtu-LLM-2B") model = AutoModelForCausalLM.from_pretrained("tencent/Youtu-LLM-2B") 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tencent/Youtu-LLM-2B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tencent/Youtu-LLM-2B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tencent/Youtu-LLM-2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/tencent/Youtu-LLM-2B
- SGLang
How to use tencent/Youtu-LLM-2B 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 "tencent/Youtu-LLM-2B" \ --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": "tencent/Youtu-LLM-2B", "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 "tencent/Youtu-LLM-2B" \ --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": "tencent/Youtu-LLM-2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use tencent/Youtu-LLM-2B with Docker Model Runner:
docker model run hf.co/tencent/Youtu-LLM-2B
update quickstart
#13
by hevans - opened
- README.md +11 -9
- generation_config.json +1 -0
README.md
CHANGED
|
@@ -104,7 +104,6 @@ The following example demonstrates how to load the model, enable Reasoning Mode,
|
|
| 104 |
|
| 105 |
```python
|
| 106 |
import re
|
| 107 |
-
import torch
|
| 108 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 109 |
|
| 110 |
# 1. Configure Model
|
|
@@ -123,23 +122,27 @@ prompt = "Hello"
|
|
| 123 |
messages = [{"role": "user", "content": prompt}]
|
| 124 |
|
| 125 |
# Use apply_chat_template to construct input; set enable_thinking=True to activate Reasoning Mode
|
| 126 |
-
|
| 127 |
-
messages,
|
| 128 |
-
tokenize=
|
| 129 |
-
add_generation_prompt=True,
|
| 130 |
-
return_tensors="pt",
|
| 131 |
enable_thinking=True
|
| 132 |
-
)
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
# 4. Generate Response
|
| 135 |
outputs = model.generate(
|
| 136 |
-
|
| 137 |
max_new_tokens=512,
|
| 138 |
do_sample=True,
|
| 139 |
temperature=1.0,
|
|
|
|
| 140 |
top_p=0.95,
|
| 141 |
repetition_penalty=1.05
|
| 142 |
)
|
|
|
|
| 143 |
|
| 144 |
# 5. Parse Results
|
| 145 |
full_response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
@@ -161,7 +164,6 @@ thought, final_answer = parse_reasoning(full_response)
|
|
| 161 |
|
| 162 |
print(f"\n{'='*20} Thought Process {'='*20}\n{thought}")
|
| 163 |
print(f"\n{'='*20} Final Answer {'='*20}\n{final_answer}")
|
| 164 |
-
|
| 165 |
```
|
| 166 |
|
| 167 |
### 3. Key Configuration Details
|
|
|
|
| 104 |
|
| 105 |
```python
|
| 106 |
import re
|
|
|
|
| 107 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 108 |
|
| 109 |
# 1. Configure Model
|
|
|
|
| 122 |
messages = [{"role": "user", "content": prompt}]
|
| 123 |
|
| 124 |
# Use apply_chat_template to construct input; set enable_thinking=True to activate Reasoning Mode
|
| 125 |
+
input_text = tokenizer.apply_chat_template(
|
| 126 |
+
messages,
|
| 127 |
+
tokenize=False,
|
| 128 |
+
add_generation_prompt=True,
|
|
|
|
| 129 |
enable_thinking=True
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
model_inputs = tokenizer([input_text], return_tensors="pt").to(model.device)
|
| 133 |
+
print("Input prepared. Starting generation...")
|
| 134 |
|
| 135 |
# 4. Generate Response
|
| 136 |
outputs = model.generate(
|
| 137 |
+
**model_inputs,
|
| 138 |
max_new_tokens=512,
|
| 139 |
do_sample=True,
|
| 140 |
temperature=1.0,
|
| 141 |
+
top_k=20,
|
| 142 |
top_p=0.95,
|
| 143 |
repetition_penalty=1.05
|
| 144 |
)
|
| 145 |
+
print("Generation complete!")
|
| 146 |
|
| 147 |
# 5. Parse Results
|
| 148 |
full_response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
| 164 |
|
| 165 |
print(f"\n{'='*20} Thought Process {'='*20}\n{thought}")
|
| 166 |
print(f"\n{'='*20} Final Answer {'='*20}\n{final_answer}")
|
|
|
|
| 167 |
```
|
| 168 |
|
| 169 |
### 3. Key Configuration Details
|
generation_config.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
"_from_model_config": true,
|
| 3 |
"bos_token_id": 128000,
|
| 4 |
"eos_token_id": 128001,
|
|
|
|
| 5 |
"do_sample": true,
|
| 6 |
"temperature": 1.0,
|
| 7 |
"top_k": 20,
|
|
|
|
| 2 |
"_from_model_config": true,
|
| 3 |
"bos_token_id": 128000,
|
| 4 |
"eos_token_id": 128001,
|
| 5 |
+
"pad_token_id": 128001,
|
| 6 |
"do_sample": true,
|
| 7 |
"temperature": 1.0,
|
| 8 |
"top_k": 20,
|