File size: 7,727 Bytes
c11438d 8d43197 c11438d 8d43197 c11438d fed1683 c11438d 7c38266 c11438d 1d7f00c ad7d2b7 1d7f00c c11438d 1d7f00c 8d43197 c11438d 1d7f00c c11438d 8d43197 c11438d 449f2c2 c11438d 8d43197 1d7f00c c11438d 8d43197 c11438d | 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | ---
license: apache-2.0
base_model: tencent/Hy3
base_model_relation: quantized
pipeline_tag: text-generation
library_name: vllm
tags:
- hunyuan
- hy_v3
- mixture-of-experts
- moe
- 4-bit
- int4
- w4a16
- compressed-tensors
- quantized
- vllm
- long-context
- yarn
---
# Hy3-1M — 4-bit (INT4) quantization of tencent/Hy3 for 1M context
A **4-bit weight-only (W4A16)** quantization of **[tencent/Hy3](https://huggingface.co/tencent/Hy3)**
(`HYV3ForCausalLM`, `hy_v3`) — a 295B-parameter / 21B-active Mixture-of-Experts model.
Packaged in the **`compressed-tensors`** `pack-quantized` format so it loads directly in **vLLM**.
## Why this model
- **Small.** **~146 GB** vs **~557 GB** for the original BF16 (~3.8× smaller). The whole
295B MoE now **fits on a single ≥180 GB GPU** (e.g. one B200 192 GB / B300 ~288 GB)
with KV-cache headroom — no tensor-parallel sharding required just to load it.
(Note: it does **not** fit a 141 GB H200 without offload/TP.)
- **vLLM-native.** Loads out of the box with vLLM (recent build with `hy_v3` support) using the
Marlin INT4 MoE + Linear kernels. Fast tensor-core prefill.
- **Long context via YaRN.** With YaRN RoPE scaling the context extends from the native
**262,144** up to **1,048,576 (1M)** tokens (configurable). Dense needle-in-a-haystack
retrieval is **verified past native (1M, PASS)** on a single GPU; see *Long context* below.
## Verified results (single B300, this checkpoint)
| Test | Result |
|---|---|
| **HumanEval pass@1 (greedy)** | ✅ **150/164 = 91.5%** — coding ability well-preserved at 4-bit |
| **GSM8K (0-shot CoT, greedy)** | ✅ **1265/1319 = 95.9%** — math reasoning preserved at 4-bit |
| Chat sanity | ✅ correct |
| Needle-in-a-haystack 4K / 16K / 64K / 137K (in-range) | ✅ all PASS |
| **Needle-in-a-haystack 320K/1M dense (YaRN ×4, fp8/int4 KV)** | ✅ **PASS** — retrieval works past the native 262,144 |
## Quantization details
| | |
|---|---|
| Scheme | **W4A16** — 4-bit **int**, **symmetric**, **group_size=128**, RTN (round-to-nearest, data-free) |
| Format | `compressed-tensors` **`pack-quantized`** (`quant_method: compressed-tensors`) |
| Quantized | attention `q/k/v/o_proj`, dense-layer FFN, **all 192 routed experts** + shared expert (`gate/up/down_proj`) |
| Kept in original precision | `lm_head`, router gate (`mlp.router.gate`), `eh_proj` (MTP), all norms, `embed_tokens` |
| Base dtype | bf16 (scales stored bf16) |
Produced by a direct tensor-by-tensor RTN packer (no calibration dataset). RTN keeps the
pipeline simple and lossless-format-correct; for maximum quality at 4-bit, a calibrated
GPTQ/AWQ pass would be marginally better.
## Running with vLLM
Requires a vLLM build new enough to include the `hy_v3` architecture (vLLM `main`/nightly at time of
writing). Example on a single GPU:
```bash
vllm serve /path/to/Hy3-1M \
--max-model-len 262144 \
--gpu-memory-utilization 0.9 \
--trust-remote-code
```
**NVIDIA Blackwell (sm_100/sm_103, e.g. B200/B300) note:** at the time of testing, FlashInfer's
runtime JIT could not compile for `compute_103a` with the bundled CUDA toolkit, which crashed the
default sampler/attention. Work around it with the Triton attention backend + native sampler:
```bash
VLLM_USE_FLASHINFER_SAMPLER=0 vllm serve /path/to/Hy3-1M \
--attention-backend TRITON_ATTN \
--kv-cache-dtype fp8 \
--max-model-len 262144 \
--gpu-memory-utilization 0.9 \
--trust-remote-code --enforce-eager
```
`--kv-cache-dtype fp8` halves KV memory (recommended for long context). On Hopper/Ada or with a
FlashInfer build that supports your GPU, you can drop the two workaround flags.
## Inference tuning: MoE top-K (speed vs quality)
The number of routed experts per token (`num_experts_per_tok`, native **8**) can be lowered at
**inference time** (no re-quantization) to trade quality for less expert compute, via vLLM's
`--hf-overrides '{"num_experts_per_tok": K}'`. Measured on this 4-bit checkpoint (greedy):
| top-K | HumanEval | GSM8K | routed-expert FLOPs |
|---|---|---|---|
| **8** (native) | **91.5%** | **95.9%** | 100% |
| **6** | 89.6% (−1.9) | 94.8% (−1.1) | ~75% |
| **4** | 86.6% (−4.9) | 93.5% (−2.4) | ~50% |
Degradation is **graceful** — even top-4 (half the routed-expert compute) stays coherent and
usable. **top-6** is a sweet spot (~25% less expert compute for ≈1-2 pts). Coding is a bit more
sensitive to fewer experts than math. (Default = 8; only lower it if you need the speed/energy.)
## Long context (YaRN)
The base model is `rope_type: "default"` with `max_position_embeddings: 262144`. To go beyond,
enable YaRN in `config.json`:
```json
"rope_parameters": {
"rope_theta": 11158840.0,
"rope_type": "yarn",
"factor": 4.0,
"original_max_position_embeddings": 262144
}
```
and raise `--max-model-len` (up to `262144 * factor = 1048576`).
> **This shipped `config.json` already has YaRN factor 4 enabled** (context up to 1,048,576).
> Set `rope_type` back to `"default"` if you want the native-only 262,144 behavior.
Memory on a single ~275 GB GPU (146 GB weights):
- **fp8 KV** (`--kv-cache-dtype fp8`): comfortably fits **~500K** dense tokens; fast tensor-core prefill.
- **int4 KV** (`--kv-cache-dtype int4_per_token_head`): fits **~1M** dense tokens, but its kernel is
compute-bound and much slower for long prefill.
- Full **dense 1M** is best served with **multi-GPU** (tensor-parallel) for both memory and speed.
## Verified results (single B300, this checkpoint)
| Test | Result |
|---|---|
| **HumanEval pass@1 (greedy)** | ✅ **150/164 = 91.5%** — coding ability well-preserved at 4-bit |
| **GSM8K (0-shot CoT, greedy)** | ✅ **1265/1319 = 95.9%** — math reasoning preserved at 4-bit |
| Chat sanity (`11+22+33` → 66; capital of France → Paris; first 5 primes) | ✅ correct |
| Needle-in-a-haystack 4K / 16K / 64K / 137K (in-range) | ✅ all PASS |
| **Needle-in-a-haystack 1M dense (YaRN ×4, fp8 KV)** | ✅ **PASS** — retrieval works past the native 262,144 |
<details>
<summary><b>How HumanEval was measured</b> (for reproducibility)</summary>
- **Engine/config:** this W4A16 checkpoint served by vLLM on a single B300, **as shipped**
(YaRN factor 4 enabled), `--attention-backend TRITON_ATTN --kv-cache-dtype fp8
--enforce-eager`, `VLLM_USE_FLASHINFER_SAMPLER=0`.
- **Data:** the 164 problems from `openai_humaneval` (`human-eval` package).
- **Decoding:** **greedy** (`temperature=0`), `max_tokens=768`, **pass@1** (single sample per problem).
- **Prompting:** chat template with the instruction *"Complete the following Python function.
Return the COMPLETE function in a single ```python code block. No tests, no explanations."*
The first ```python block is extracted; if it lacks the `entry_point` def, the original stub
is prepended.
- **Scoring:** each candidate is run as `candidate + test + check(entry_point)` in a subprocess
(15s timeout); exit-code 0 = pass.
- **Result:** **150/164 = 91.5%**. Note this uses a chat+extraction harness (not the canonical
raw-completion protocol), so a few of the 14 misses may be extraction artifacts — treat 91.5%
as a conservative figure.
**GSM8K:** full 1319-problem test set, **0-shot chain-of-thought**, greedy (`temperature=0`,
`max_tokens=512`), prompt *"Solve step by step… on the last line write 'The answer is <number>'"*;
the final number is compared to the gold answer (after `####`). Result: **1265/1319 = 95.9%**.
</details>
## Caveats & honesty
- This is a **community derivative**, not affiliated with or endorsed by Tencent.
## License
Apache-2.0, inheriting the license of the base model
[`tencent/Hy3`](https://huggingface.co/tencent/Hy3) (see `LICENSE`).
|