Instructions to use HawkonLi/Hunyuan-A52B-Instruct-2bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HawkonLi/Hunyuan-A52B-Instruct-2bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="HawkonLi/Hunyuan-A52B-Instruct-2bit", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("HawkonLi/Hunyuan-A52B-Instruct-2bit", trust_remote_code=True, device_map="auto") - MLX
How to use HawkonLi/Hunyuan-A52B-Instruct-2bit with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("HawkonLi/Hunyuan-A52B-Instruct-2bit") prompt = "Write a story about Einstein" messages = [{"role": "user", "content": prompt}] prompt = tokenizer.apply_chat_template( messages, add_generation_prompt=True ) text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- vLLM
How to use HawkonLi/Hunyuan-A52B-Instruct-2bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "HawkonLi/Hunyuan-A52B-Instruct-2bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "HawkonLi/Hunyuan-A52B-Instruct-2bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/HawkonLi/Hunyuan-A52B-Instruct-2bit
- SGLang
How to use HawkonLi/Hunyuan-A52B-Instruct-2bit 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 "HawkonLi/Hunyuan-A52B-Instruct-2bit" \ --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": "HawkonLi/Hunyuan-A52B-Instruct-2bit", "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 "HawkonLi/Hunyuan-A52B-Instruct-2bit" \ --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": "HawkonLi/Hunyuan-A52B-Instruct-2bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - MLX LM
How to use HawkonLi/Hunyuan-A52B-Instruct-2bit with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "HawkonLi/Hunyuan-A52B-Instruct-2bit"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "HawkonLi/Hunyuan-A52B-Instruct-2bit" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "HawkonLi/Hunyuan-A52B-Instruct-2bit", "messages": [ {"role": "user", "content": "Hello"} ] }' - Docker Model Runner
How to use HawkonLi/Hunyuan-A52B-Instruct-2bit with Docker Model Runner:
docker model run hf.co/HawkonLi/Hunyuan-A52B-Instruct-2bit
- Atomic Chat
File size: 1,305 Bytes
0a69ebf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
#
# Licensed under the TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://github.com/Tencent/Tencent-Hunyuan-Large/blob/main/License.docx
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# test tokenizer encode & decode consistency
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained('/tokenizer_exp/other_tokenizer_vocab/hy', local_files_only=True, trust_remote_code=True)
test_data = [line.strip() for line in open('/tokenizer_exp/data/test.txt', 'r').readlines()]
num_origi_len = 0
num_token_len = 0
for d in test_data:
a = tokenizer.encode(d)
num_origi_len += len(d)
num_token_len += len(a)
b = tokenizer.decode(a)
assert b == d, f"encode & decode not consistent: {d} vs {b}"
print(f" original length: {num_origi_len}")
print(f" token length: {num_token_len}")
|