Instructions to use tencent/Hunyuan-4B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tencent/Hunyuan-4B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tencent/Hunyuan-4B-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tencent/Hunyuan-4B-Instruct") model = AutoModelForCausalLM.from_pretrained("tencent/Hunyuan-4B-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-4B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tencent/Hunyuan-4B-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-4B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/tencent/Hunyuan-4B-Instruct
- SGLang
How to use tencent/Hunyuan-4B-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-4B-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-4B-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-4B-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-4B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use tencent/Hunyuan-4B-Instruct with Docker Model Runner:
docker model run hf.co/tencent/Hunyuan-4B-Instruct
Upload config.json with huggingface_hub
Browse files- config.json +61 -0
config.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_classification_head": false,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"HunYuanDenseV1ForCausalLM"
|
| 5 |
+
],
|
| 6 |
+
"attention_bias": false,
|
| 7 |
+
"attention_dropout": 0.0,
|
| 8 |
+
"attention_head_dim": 128,
|
| 9 |
+
"bos_token_id": 1,
|
| 10 |
+
"cla_share_factor": 2,
|
| 11 |
+
"class_num": 0,
|
| 12 |
+
"dense_list": [
|
| 13 |
+
3072,
|
| 14 |
+
0
|
| 15 |
+
],
|
| 16 |
+
"eod_token_id": 120026,
|
| 17 |
+
"eos_token_id": 120020,
|
| 18 |
+
"head_dim": 128,
|
| 19 |
+
"hidden_act": "silu",
|
| 20 |
+
"hidden_size": 3072,
|
| 21 |
+
"im_end_id": 5,
|
| 22 |
+
"im_newline_id": 11,
|
| 23 |
+
"im_start_id": 4,
|
| 24 |
+
"initializer_range": 0.02,
|
| 25 |
+
"intermediate_size": 8192,
|
| 26 |
+
"mask_init_id": 12,
|
| 27 |
+
"max_position_embeddings": 262144,
|
| 28 |
+
"mlp_bias": false,
|
| 29 |
+
"model_type": "hunyuan_v1_dense",
|
| 30 |
+
"norm_type": "rms",
|
| 31 |
+
"num_attention_heads": 32,
|
| 32 |
+
"num_hidden_layers": 36,
|
| 33 |
+
"num_key_value_heads": 8,
|
| 34 |
+
"org_vocab_size": 120818,
|
| 35 |
+
"pad_id": 120002,
|
| 36 |
+
"pad_token_id": 120002,
|
| 37 |
+
"pool_type": "last",
|
| 38 |
+
"pretraining_tp": 1,
|
| 39 |
+
"rms_norm_eps": 1e-05,
|
| 40 |
+
"rope_scaling": {
|
| 41 |
+
"alpha": 1000.0,
|
| 42 |
+
"beta_fast": 32,
|
| 43 |
+
"beta_slow": 1,
|
| 44 |
+
"factor": 1.0,
|
| 45 |
+
"mscale": 1.0,
|
| 46 |
+
"mscale_all_dim": 1.0,
|
| 47 |
+
"type": "dynamic"
|
| 48 |
+
},
|
| 49 |
+
"rope_theta": 10000.0,
|
| 50 |
+
"sep_token_id": 120007,
|
| 51 |
+
"text_end_id": 7,
|
| 52 |
+
"text_start_id": 6,
|
| 53 |
+
"tie_word_embeddings": true,
|
| 54 |
+
"torch_dtype": "bfloat16",
|
| 55 |
+
"transformers_version": "4.41.2",
|
| 56 |
+
"use_cache": true,
|
| 57 |
+
"use_cla": false,
|
| 58 |
+
"use_qk_norm": true,
|
| 59 |
+
"use_rotary_pos_emb": true,
|
| 60 |
+
"vocab_size": 120818
|
| 61 |
+
}
|