--- language: - en - zh library_name: transformers license: other license_name: tencent-hy-license license_link: https://huggingface.co/tencent/Hy4/blob/main/LICENSE pipeline_tag: image-text-to-text tags: - nvfp4 - fp4 - vllm - llm-compressor - compressed-tensors - hunyuan - hy4 - moe base_model: tencent/Hy4 --- # Hy4-NVFP4 ## Model Overview - **Model Architecture:** HYV4VLForConditionalGeneration - **Input:** Text, Image, Video - **Output:** Text - **Model Optimizations:** - **Weight quantization:** FP4 - **Activation quantization:** FP4 - **Format:** compressed-tensors - **Base model:** [tencent/Hy4](https://huggingface.co/tencent/Hy4) This is an NVFP4 checkpoint derived from [tencent/Hy4](https://huggingface.co/tencent/Hy4). It is optimized for Blackwell inference with NVFP4 weights and activations while retaining higher precision where needed for model quality. ### Model Optimizations This model uses NVFP4 FP4 (E2M1) weights and activations with two-level scaling (FP8 E4M3 scales per 16 elements plus a per-tensor FP32 global scale) for the routed experts of all 77 MoE layers. Layers outside of routed experts are left unquantized in BF16: attention and the DSA indexer, the dense first layer, shared experts, routers, the vision encoder and adapter, `lm_head`, and the DFly2 speculative-decoding drafter. This reduces the checkpoint from about 1.55 TB to about 479 GB (447 GiB). The checkpoint uses [LLM Compressor](https://github.com/vllm-project/llm-compressor)'s compressed-tensors NVFP4 format and keeps the tensor names and config of the original checkpoint. ## Deployment ### vLLM Serving ``` vllm serve RedHatAI/Hy4-NVFP4 \ --served-model-name hy4 \ --tensor-parallel-size 4 \ --dtype bfloat16 \ --limit-mm-per-prompt '{"image":1,"video":0}' \ --enable-auto-tool-choice \ --reasoning-parser hy_v4 \ --tool-call-parser hy_v4 \ --attention-backend FLASHMLA_SPARSE ``` Recommended sampling parameters are `temperature=0.9`, `top_p=1.0`. Reasoning effort accepts `"no_think"` and `"high"` (default) through `chat_template_kwargs`. The BF16 DFly2 drafter weights are included in the checkpoint. Using them with `--speculative-config '{"method":"dfly","num_speculative_tokens":5}'` requires [vllm-project/vllm#69274](https://github.com/vllm-project/vllm/pull/69274), which is not merged yet. ## Creation The source model was compressed with [LLM Compressor](https://github.com/vllm-project/llm-compressor) using the NVFP4 scheme on the routed experts, calibrated on 512 samples of [`mlabonne/open-perfectblend`](https://huggingface.co/datasets/mlabonne/open-perfectblend) with a maximum sequence length of 2048, distributed over 4 GPUs. Expert weights use the `nvfp4_expanded_imatrix` observer. Transformers' reverse weight-name conversion for `hy_v4_vl` is lossy, so the compressed model was saved with Transformers' internal names and then converted back to the original checkpoint layout (tensor names, `config.json`, tokenizer and processor files). The conversion was verified tensor by tensor: every non-expert tensor is bitwise identical to the base checkpoint. The DFly2 drafter, which Transformers does not model, was copied unchanged from the base checkpoint.
Creation script ```python import os from datetime import timedelta import torch from transformers import AutoProcessor, HYV4VLForConditionalGeneration from llmcompressor import oneshot from llmcompressor.modifiers.quantization import QuantizationModifier from llmcompressor.utils import load_context MODEL_ID = "tencent/Hy4" # torchrun --nproc-per-node=4