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, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("tencent/Youtu-LLM-2B") model = AutoModelForMultimodalLM.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
Use rsplit properly (#1)
Browse files- Use rsplit properly (95afe0c798b6191e8e96b9dc285c98f0b73e11e2)
Co-authored-by: Sigbjørn Skjæret <CISCai@users.noreply.huggingface.co>
- chat_template.jinja +1 -1
chat_template.jinja
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% set ns = namespace(is_first=false, is_tool=false, is_tool_message=false, first_tool_index=messages|length, is_output_first=true, system_prompt='', is_first_sp=true, is_last_user=false) %}{% for message in messages %}{% if message['role'] == 'system' %}{% if ns.is_first_sp %}{% set ns.system_prompt = ns.system_prompt + message['content'] %}{% set ns.is_first_sp = false %}{% else %}{% set ns.system_prompt = ns.system_prompt + '\n\n' + message['content'] %}{% endif %}{% endif %}{% if not ns.is_tool_message and (message['role'] == 'tool' or (message['role'] == 'user' and message['content'].startswith('<tool_response>') and message['content'].endswith('</tool_response>'))) %}{% set ns.is_tool_message = true %}{% set ns.first_tool_index = loop.index0 %}{% endif %}{% endfor %}{% if tools is defined and tools is not none %}{% set tool_ns = namespace(text='<|begin_of_tool_description|>Tool calling capabilities.\nYou may call one or more functions to assist with the user query. You have the following functions available:', return_text='For tool call returns, you MUST use the following format:\n<tool_call>{\"name\": \"function-name\", \"arguments\": {\"param1\": \"value1\", \"param2\": \"value2\"}}</tool_call>\n<|end_of_tool_description|>') %}{% for tool in tools %}{% set tool_ns.text = tool_ns.text + '\n```json\n' + (tool | tojson) + '\n```' %}{% endfor %}{% set tool_ns.text = tool_ns.text + '\n' + tool_ns.return_text %}{% if ns.system_prompt == '' %}{% set ns.system_prompt = tool_ns.text %}{% else %}{% set ns.system_prompt = ns.system_prompt + '\n\n' + tool_ns.text %}{% endif %}{% endif %}{{ bos_token }}{{ ns.system_prompt }}{% for message in messages %}{% set content = message['content'] %}{% if message['role'] == 'user' %}{% set ns.is_tool = false %}{% set ns.is_first = false %}{% set ns.is_last_user = true %}{{ '<|User|>' + content }}{% endif %}{% if message['role'] == 'assistant' %}{% if '</think>' in content and not loop.last and loop.index0 < (ns.first_tool_index - 1) %}{% set content = content.rsplit('</think>')[-1].lstrip('\n') %}{% endif %}{% if '<think>' not in content and '</think>' not in content and loop.last %}{% set content = '<think>\n\n</think>\n\n' + content %}{% endif %}{% endif %}{% if message['role'] == 'assistant' and message['tool_calls'] is defined and message['tool_calls'] is not none %}{% set ns.is_last_user = false %}{{ '<|Assistant|>' }}{% if content is not none %}{{ content }}{% endif %}{% set ns.is_first = false %}{% set ns.is_tool = false %}{% set ns.is_output_first = true %}{% for tool in message['tool_calls'] %}{% if tool['function']['arguments'] is string %}{% set tool_call_str = '{\"name\": \"' + tool['function']['name'] + '\", \"arguments\": ' + tool['function']['arguments'] + '}' %}{% else %}{% set tool_call_str = '{\"name\": \"' + tool['function']['name'] + '\", \"arguments\": ' + tool['function']['arguments']|tojson + '}' %}{% endif %}{% if not ns.is_first %}{{ '<tool_call>' + tool_call_str + '</tool_call>' }}{% set ns.is_first = true %}{% else %}{{ '\n' + '<tool_call>' + tool_call_str + '</tool_call>' }}{% endif %}{% endfor %}{{ '<|end_of_text|>' }}{% endif %}{% if message['role'] == 'assistant' and (message['tool_calls'] is not defined or message['tool_calls'] is none)%}{% set ns.is_last_user = false %}{% set ns.is_tool = false %}{% set ns.is_output_first = true %}{{ '<|Assistant|>' + content + '<|end_of_text|>' }}{% endif %}{% if message['role'] == 'tool' %}{% set ns.is_last_user = false %}{% set ns.is_tool = true %}{% if ns.is_output_first %}{{ '<|User|><tool_response>' + content + '</tool_response>' }}{% set ns.is_output_first = false %}{% else %}{{ '\n<tool_response>' + content + '</tool_response>' }}{% endif %}{% endif %}{% endfor %}{% if add_generation_prompt and (ns.is_last_user or ns.is_tool) %}{{ '<|Assistant|>' }}{% if enable_thinking is defined and enable_thinking is false %}{{ '<think>\n\n</think>\n\n' }}{% elif forced_thinking is defined and forced_thinking is true %}{{ '<think>\n' }}{% endif %}{% endif %}
|
|
|
|
| 1 |
+
{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% set ns = namespace(is_first=false, is_tool=false, is_tool_message=false, first_tool_index=messages|length, is_output_first=true, system_prompt='', is_first_sp=true, is_last_user=false) %}{% for message in messages %}{% if message['role'] == 'system' %}{% if ns.is_first_sp %}{% set ns.system_prompt = ns.system_prompt + message['content'] %}{% set ns.is_first_sp = false %}{% else %}{% set ns.system_prompt = ns.system_prompt + '\n\n' + message['content'] %}{% endif %}{% endif %}{% if not ns.is_tool_message and (message['role'] == 'tool' or (message['role'] == 'user' and message['content'].startswith('<tool_response>') and message['content'].endswith('</tool_response>'))) %}{% set ns.is_tool_message = true %}{% set ns.first_tool_index = loop.index0 %}{% endif %}{% endfor %}{% if tools is defined and tools is not none %}{% set tool_ns = namespace(text='<|begin_of_tool_description|>Tool calling capabilities.\nYou may call one or more functions to assist with the user query. You have the following functions available:', return_text='For tool call returns, you MUST use the following format:\n<tool_call>{\"name\": \"function-name\", \"arguments\": {\"param1\": \"value1\", \"param2\": \"value2\"}}</tool_call>\n<|end_of_tool_description|>') %}{% for tool in tools %}{% set tool_ns.text = tool_ns.text + '\n```json\n' + (tool | tojson) + '\n```' %}{% endfor %}{% set tool_ns.text = tool_ns.text + '\n' + tool_ns.return_text %}{% if ns.system_prompt == '' %}{% set ns.system_prompt = tool_ns.text %}{% else %}{% set ns.system_prompt = ns.system_prompt + '\n\n' + tool_ns.text %}{% endif %}{% endif %}{{ bos_token }}{{ ns.system_prompt }}{% for message in messages %}{% set content = message['content'] %}{% if message['role'] == 'user' %}{% set ns.is_tool = false %}{% set ns.is_first = false %}{% set ns.is_last_user = true %}{{ '<|User|>' + content }}{% endif %}{% if message['role'] == 'assistant' %}{% if '</think>' in content and not loop.last and loop.index0 < (ns.first_tool_index - 1) %}{% set content = content.rsplit('</think>', 1)[-1].lstrip('\n') %}{% endif %}{% if '<think>' not in content and '</think>' not in content and loop.last %}{% set content = '<think>\n\n</think>\n\n' + content %}{% endif %}{% endif %}{% if message['role'] == 'assistant' and message['tool_calls'] is defined and message['tool_calls'] is not none %}{% set ns.is_last_user = false %}{{ '<|Assistant|>' }}{% if content is not none %}{{ content }}{% endif %}{% set ns.is_first = false %}{% set ns.is_tool = false %}{% set ns.is_output_first = true %}{% for tool in message['tool_calls'] %}{% if tool['function']['arguments'] is string %}{% set tool_call_str = '{\"name\": \"' + tool['function']['name'] + '\", \"arguments\": ' + tool['function']['arguments'] + '}' %}{% else %}{% set tool_call_str = '{\"name\": \"' + tool['function']['name'] + '\", \"arguments\": ' + tool['function']['arguments']|tojson + '}' %}{% endif %}{% if not ns.is_first %}{{ '<tool_call>' + tool_call_str + '</tool_call>' }}{% set ns.is_first = true %}{% else %}{{ '\n' + '<tool_call>' + tool_call_str + '</tool_call>' }}{% endif %}{% endfor %}{{ '<|end_of_text|>' }}{% endif %}{% if message['role'] == 'assistant' and (message['tool_calls'] is not defined or message['tool_calls'] is none)%}{% set ns.is_last_user = false %}{% set ns.is_tool = false %}{% set ns.is_output_first = true %}{{ '<|Assistant|>' + content + '<|end_of_text|>' }}{% endif %}{% if message['role'] == 'tool' %}{% set ns.is_last_user = false %}{% set ns.is_tool = true %}{% if ns.is_output_first %}{{ '<|User|><tool_response>' + content + '</tool_response>' }}{% set ns.is_output_first = false %}{% else %}{{ '\n<tool_response>' + content + '</tool_response>' }}{% endif %}{% endif %}{% endfor %}{% if add_generation_prompt and (ns.is_last_user or ns.is_tool) %}{{ '<|Assistant|>' }}{% if enable_thinking is defined and enable_thinking is false %}{{ '<think>\n\n</think>\n\n' }}{% elif forced_thinking is defined and forced_thinking is true %}{{ '<think>\n' }}{% endif %}{% endif %}
|