OpenFlowLM-Next icon indicating copy to clipboard operation
OpenFlowLM-Next copied to clipboard

Support Hy-MT2-7B (HunYuan dense) on the open kernels

Open Cyronius opened this issue 2 months ago • 0 comments

Someone asked whether Hy-MT2-7B can run on the open XDNA2 kernels. It can, and it is close to free, because the model is shaped exactly like the Llama 3.1 8B point we already run.

What the model is

tencent/Hy-MT2-7B is Tencent's HunYuan V1 dense translation model — 33 languages, plus a handful of Chinese dialect and minority-language pairs. Architecture hunyuan_v1_dense (HunYuanDenseV1ForCausalLM), GGUF architecture hunyuan-dense.

Its config.json lines up with Llama 3.1 8B almost field for field:

Hy-MT2-7B Llama 3.1 8B
hidden / layers 4096 / 32 4096 / 32
query heads / kv heads / head dim 32 / 8 / 128 32 / 8 / 128
FFN width 14336 14336
activation / norm SiLU / RMSNorm, eps 1e-5 SiLU / RMSNorm, eps 1e-5
vocabulary 128167, tied head 128256, its own head

So the dense recipe needs no new GEMV width, no new norm width and no new band split. Every kernel point it asks for is already in the catalogue's validated set, and per_call lands on 1 for the same reason Llama's does — the 14336-wide activation table is 32 KB.

What is actually different

Three things, and none of them is a shape.

The q/k RMSNorm weight is applied after the rotary embedding, not before. HunYuan computes query_layernorm(apply_rotary_pos_emb(q)); Qwen3 and our attn.h normalize first. This matters because RoPE rotates the pairs (i, i + d/2) and those two positions generally carry different norm weights, so the multiply does not commute with the rotation. It does not change the scale, though — RoPE is orthogonal and the rotary dimension here is the whole head, so the RMS comes out the same either way. In other words, one multiply has to move to the other side of the rotation. That is the only kernel change, and it needs a hardware comparison before the new point can enter the catalogue.

The RoPE scaling looks dynamic and is not. The config asks for {"type": "dynamic", "alpha": 1000}, which both transformers and llama.cpp resolve once at load into a single stretched base, rope_theta * alpha^(d/(d-2)) = 11158839.925. Nothing reaches the kernel but a different position table.

The vocabulary is not a whole number of head bands. 128167 is not a multiple of 64, and the q4 head is split into 64-row bands. Padding the spec itself would be wrong: the manifest's vocab_size would then disagree with the model's own config.json and the engine would refuse the model at startup. Only the head should be rounded up.

What it needs

  • A hunyuan family in the dense recipe, with the norm order as a family property rather than a ModelSpec field (adding a field would rehash every existing spec and force a rebuild of four families' kernels for no behavioural difference).
  • Spec derivation from both config.json and GGUF metadata, folding the NTK alpha.
  • A converter: FastFlowLM ships no NPU2 container for this model, so utilities/q4nx-build has to build one from tencent/Hy-MT2-7B-GGUF.
  • The usual family gate: a layer slice against the fp64 replica, the same through the resident engine, and a full-model run.

One thing worth flagging up front: translation is more sensitive to 4-bit quantization than chat is. A correlation against the fp64 replica proves the kernels, not the quantization, so the two questions should be kept separate when judging whether the result is good.

Cyronius avatar Sep 06 '26 14:09 Cyronius