Instructions to use tencent/Hunyuan-7B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tencent/Hunyuan-7B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tencent/Hunyuan-7B-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tencent/Hunyuan-7B-Instruct") model = AutoModelForCausalLM.from_pretrained("tencent/Hunyuan-7B-Instruct") 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
- vLLM
How to use tencent/Hunyuan-7B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tencent/Hunyuan-7B-Instruct" # 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/Hunyuan-7B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/tencent/Hunyuan-7B-Instruct
- SGLang
How to use tencent/Hunyuan-7B-Instruct 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/Hunyuan-7B-Instruct" \ --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/Hunyuan-7B-Instruct", "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/Hunyuan-7B-Instruct" \ --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/Hunyuan-7B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use tencent/Hunyuan-7B-Instruct with Docker Model Runner:
docker model run hf.co/tencent/Hunyuan-7B-Instruct
hunyuan-1.8b 转换onnx 模型时 BitShift算子出现这个 tensor(int32)无效 是layers.31网络层出现什么问题吗?
Traceback (most recent call last):
File "/opt/conda/bin/optimum-cli", line 7, in
sys.exit(main())
File "/opt/conda/lib/python3.9/site-packages/optimum/commands/optimum_cli.py", line 208, in main
service.run()
File "/opt/conda/lib/python3.9/site-packages/optimum/commands/export/onnx.py", line 276, in run
main_export(
File "/opt/conda/lib/python3.9/site-packages/optimum/exporters/onnx/main.py", line 418, in main_export
onnx_export_from_model(
File "/opt/conda/lib/python3.9/site-packages/optimum/exporters/onnx/convert.py", line 1186, in onnx_export_from_model
_, onnx_outputs = export_models(
File "/opt/conda/lib/python3.9/site-packages/optimum/exporters/onnx/convert.py", line 770, in export_models
export(
File "/opt/conda/lib/python3.9/site-packages/optimum/exporters/onnx/convert.py", line 903, in export
config.fix_dynamic_axes(output, device=device, input_shapes=input_shapes, dtype=dtype)
File "/opt/conda/lib/python3.9/site-packages/optimum/exporters/onnx/base.py", line 235, in fix_dynamic_axes
session = InferenceSession(model_path.as_posix(), providers=providers, sess_options=session_options)
File "/opt/conda/lib/python3.9/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 419, in init
self._create_inference_session(providers, provider_options, disabled_optimizers)
File "/opt/conda/lib/python3.9/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 480, in _create_inference_session
sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model)
onnxruntime.capi.onnxruntime_pybind11_state.InvalidGraph: [ONNXRuntimeError] : 10 : INVALID_GRAPH : Load model from hunyuan_tflite_float32/model.onnx failed:This is an invalid model. Type Error: Type 'tensor(int32)' of input parameter (/model/layers.31/mlp/up_proj/Expand_output_0) of operator (BitShift) in node (/model/layers.31/mlp/up_proj/BitShift) is invalid.