Image-Text-to-Text
Transformers
Safetensors
English
Chinese
hy_v4_vl
nvfp4
fp4
vllm
llm-compressor
compressed-tensors
hunyuan
hy4
Mixture of Experts
conversational
8-bit precision
Instructions to use RedHatAI/Hy4-NVFP4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use RedHatAI/Hy4-NVFP4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="RedHatAI/Hy4-NVFP4") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("RedHatAI/Hy4-NVFP4") model = AutoModelForMultimodalLM.from_pretrained("RedHatAI/Hy4-NVFP4", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.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=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use RedHatAI/Hy4-NVFP4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "RedHatAI/Hy4-NVFP4" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "RedHatAI/Hy4-NVFP4", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/RedHatAI/Hy4-NVFP4
- SGLang
How to use RedHatAI/Hy4-NVFP4 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 "RedHatAI/Hy4-NVFP4" \ --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": "RedHatAI/Hy4-NVFP4", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "RedHatAI/Hy4-NVFP4" \ --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": "RedHatAI/Hy4-NVFP4", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use RedHatAI/Hy4-NVFP4 with Docker Model Runner:
docker model run hf.co/RedHatAI/Hy4-NVFP4
Add model card
Browse files
README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ggingface.co/tencent/Hy4/blob/main/LICENSE
|
| 9 |
+
pipeline_tag: image-text-to-text
|
| 10 |
+
tags:
|
| 11 |
+
- nvfp4
|
| 12 |
+
- fp4
|
| 13 |
+
- vllm
|
| 14 |
+
- llm-compressor
|
| 15 |
+
- compressed-tensors
|
| 16 |
+
- hunyuan
|
| 17 |
+
- hy4
|
| 18 |
+
- moe
|
| 19 |
+
base_model: tencent/Hy4
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
# Hy4-NVFP4
|
| 23 |
+
|
| 24 |
+
## Model Overview
|
| 25 |
+
- **Model Architecture:** HYV4VLForConditionalGeneration
|
| 26 |
+
- **Input:** Text, Image, Video
|
| 27 |
+
- **Output:** Text
|
| 28 |
+
- **Model Optimizations:**
|
| 29 |
+
- **Weight quantization:** FP4
|
| 30 |
+
- **Activation quantization:** FP4
|
| 31 |
+
- **Format:** compressed-tensors
|
| 32 |
+
- **Base model:** [tencent/Hy4](https://huggingface.co/tencent/Hy4)
|
| 33 |
+
|
| 34 |
+
This is an NVFP4 checkpoint derived from [tencent/Hy4](https://huggingface.co/tencent/Hy4).
|
| 35 |
+
It is optimized for Blackwell inference with NVFP4 weights and activations while retaining higher
|
| 36 |
+
precision where needed for model quality.
|
| 37 |
+
|
| 38 |
+
### Model Optimizations
|
| 39 |
+
|
| 40 |
+
This model uses NVFP4 FP4 (E2M1) weights and activations with two-level scaling (FP8 E4M3 scales
|
| 41 |
+
per 16 elements plus a per-tensor FP32 global scale) for the routed experts of all 77 MoE layers.
|
| 42 |
+
Layers outside of routed experts are left unquantized in BF16: attention and the DSA indexer, the
|
| 43 |
+
dense first layer, shared experts, routers, the vision encoder and adapter, `lm_head`, and the
|
| 44 |
+
DFly2 speculative-decoding drafter. This reduces the checkpoint from about 1.55 TB to about
|
| 45 |
+
447 GB.
|
| 46 |
+
|
| 47 |
+
The checkpoint uses [LLM Compressor](https://github.com/vllm-project/llm-compressor)'s
|
| 48 |
+
compressed-tensors NVFP4 format and keeps the tensor names and config of the original checkpoint.
|
| 49 |
+
|
| 50 |
+
## Deployment
|
| 51 |
+
|
| 52 |
+
### vLLM Serving
|
| 53 |
+
|
| 54 |
+
```
|
| 55 |
+
vllm serve RedHatAI/Hy4-NVFP4 \
|
| 56 |
+
--served-model-name hy4 \
|
| 57 |
+
--tensor-parallel-size 4 \
|
| 58 |
+
--dtype bfloat16 \
|
| 59 |
+
--limit-mm-per-prompt '{"image":1,"video":0}' \
|
| 60 |
+
--enable-auto-tool-choice \
|
| 61 |
+
--reasoning-parser hy_v4 \
|
| 62 |
+
--tool-call-parser hy_v4 \
|
| 63 |
+
--attention-backend FLASHMLA_SPARSE
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
Recommended sampling parameters are `temperature=0.9`, `top_p=1.0`. Reasoning effort accepts
|
| 67 |
+
`"no_think"` and `"high"` (default) through `chat_template_kwargs`.
|
| 68 |
+
|
| 69 |
+
The BF16 DFly2 drafter weights are included in the checkpoint. vLLM currently enables
|
| 70 |
+
`--speculative-config '{"method":"dfly",...}'` only for FP8 and MXFP4 Hy4 checkpoints.
|
| 71 |
+
|
| 72 |
+
## Creation
|
| 73 |
+
|
| 74 |
+
The source model was compressed with [LLM Compressor](https://github.com/vllm-project/llm-compressor)
|
| 75 |
+
using the NVFP4 scheme on the routed experts, calibrated on 512 samples of
|
| 76 |
+
[`mlabonne/open-perfectblend`](https://huggingface.co/datasets/mlabonne/open-perfectblend)
|
| 77 |
+
with a maximum sequence length of 2048, distributed over 4 GPUs. Expert weights use the
|
| 78 |
+
`nvfp4_expanded_imatrix` observer.
|
| 79 |
+
|
| 80 |
+
Transformers' reverse weight-name conversion for `hy_v4_vl` is lossy, so the compressed model was
|
| 81 |
+
saved with Transformers' internal names and then converted back to the original checkpoint layout
|
| 82 |
+
(tensor names, `config.json`, tokenizer and processor files). The conversion was verified tensor by
|
| 83 |
+
tensor: every non-expert tensor is bitwise identical to the base checkpoint. The DFly2 drafter, which
|
| 84 |
+
Transformers does not model, was copied unchanged from the base checkpoint.
|
| 85 |
+
|
| 86 |
+
<details>
|
| 87 |
+
<summary>Creation script</summary>
|
| 88 |
+
|
| 89 |
+
```python
|
| 90 |
+
import torch
|
| 91 |
+
from transformers import AutoProcessor, HYV4VLForConditionalGeneration
|
| 92 |
+
|
| 93 |
+
from llmcompressor import oneshot
|
| 94 |
+
from llmcompressor.modifiers.quantization import QuantizationModifier
|
| 95 |
+
from llmcompressor.utils import load_context
|
| 96 |
+
|
| 97 |
+
MODEL_ID = "tencent/Hy4"
|
| 98 |
+
|
| 99 |
+
# launched with torchrun --nproc-per-node=4; the default process group is initialized
|
| 100 |
+
# with a long timeout because rank 0 loads the full checkpoint before sharing it
|
| 101 |
+
with load_context(HYV4VLForConditionalGeneration):
|
| 102 |
+
model = HYV4VLForConditionalGeneration.from_pretrained(
|
| 103 |
+
MODEL_ID,
|
| 104 |
+
dtype=torch.bfloat16,
|
| 105 |
+
device_map="auto_offload",
|
| 106 |
+
max_memory={"cpu": "700GiB"},
|
| 107 |
+
offload_folder="offload_folder",
|
| 108 |
+
)
|
| 109 |
+
processor = AutoProcessor.from_pretrained(MODEL_ID)
|
| 110 |
+
|
| 111 |
+
recipe = QuantizationModifier(
|
| 112 |
+
targets=[r"re:.*mlp\.experts\.\d+\.(gate_proj|up_proj|down_proj)$"],
|
| 113 |
+
scheme="NVFP4",
|
| 114 |
+
ignore=["lm_head"],
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
oneshot(
|
| 118 |
+
model=model,
|
| 119 |
+
processor=processor.tokenizer,
|
| 120 |
+
dataset="perfectblend",
|
| 121 |
+
splits="train[:512]",
|
| 122 |
+
recipe=recipe,
|
| 123 |
+
max_seq_length=2048,
|
| 124 |
+
num_calibration_samples=512,
|
| 125 |
+
batch_size=4,
|
| 126 |
+
shuffle_calibration_samples=False,
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
model.save_pretrained("Hy4-NVFP4-raw", save_compressed=True, save_original_format=False)
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
</details>
|
| 133 |
+
|
| 134 |
+
## Evaluation
|
| 135 |
+
|
| 136 |
+
This model was evaluated on GSM8K Platinum and GPQA Diamond using
|
| 137 |
+
[lighteval](https://github.com/huggingface/lighteval). Evaluation was run on a vLLM server hosted
|
| 138 |
+
on 4xB300 with tensor parallelism 4, the `hy_v4` reasoning parser and default (`high`) reasoning
|
| 139 |
+
effort. Generation used temperature 0.9, top_p 1.0, one seed. NVFP4 and the
|
| 140 |
+
[tencent/Hy4-FP8](https://huggingface.co/tencent/Hy4-FP8) baseline used the same serving stack and
|
| 141 |
+
harness. Recovery is relative to the FP8 baseline.
|
| 142 |
+
|
| 143 |
+
### Accuracy
|
| 144 |
+
|
| 145 |
+
<table>
|
| 146 |
+
<thead>
|
| 147 |
+
<tr>
|
| 148 |
+
<th>Category</th>
|
| 149 |
+
<th>Benchmark</th>
|
| 150 |
+
<th>RedHatAI/Hy4-NVFP4</th>
|
| 151 |
+
<th>tencent/Hy4-FP8</th>
|
| 152 |
+
<th>Recovery</th>
|
| 153 |
+
</tr>
|
| 154 |
+
</thead>
|
| 155 |
+
<tbody>
|
| 156 |
+
<tr>
|
| 157 |
+
<td rowspan="2"><b>Reasoning</b></td>
|
| 158 |
+
<td>GSM8K Platinum (strict-match)</td>
|
| 159 |
+
<td>96.28%</td>
|
| 160 |
+
<td>96.77%</td>
|
| 161 |
+
<td>99.5%</td>
|
| 162 |
+
</tr>
|
| 163 |
+
<tr>
|
| 164 |
+
<td>GPQA Diamond (pass@1)</td>
|
| 165 |
+
<td>89.90%</td>
|
| 166 |
+
<td>91.41%</td>
|
| 167 |
+
<td>98.3%</td>
|
| 168 |
+
</tr>
|
| 169 |
+
</tbody>
|
| 170 |
+
</table>
|
| 171 |
+
|
| 172 |
+
Standard errors are about 0.5 points for GSM8K Platinum and 2.1 points for GPQA Diamond (198
|
| 173 |
+
questions, one seed), so the GPQA difference is within run-to-run noise. Most GSM8K Platinum misses
|
| 174 |
+
for both models are answers that omit the requested `ANSWER:` line while stating the correct value.
|