Skip to content

[HunYuanVL] Stop rewriting the static NTK-alpha RoPE frequencies - #48960

Open
Mi-Jiazhi wants to merge 1 commit into
huggingface:mainfrom
Mi-Jiazhi:fix-hunyuanvl
Open

Mi-Jiazhi wants to merge 1 commit into
huggingface:mainfrom
Mi-Jiazhi:fix-hunyuanvl

Conversation

@Mi-Jiazhi

@Mi-Jiazhi Mi-Jiazhi commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

CPU CI GPU run-slow

HunYuanVLTextConfig maps rope_type "xdrope" onto "dynamic" so that HunYuanDenseV1RotaryEmbedding.init takes the NTK-alpha branch, where base = rope_theta * alpha ** (d / (d - 2)) is folded into inv_freq once at init. Those frequencies are static; "dynamic" is only used here to select the formula.

The generated forward, however, inherited @dynamic_rope_update from LlamaRotaryEmbedding. Once a sequence passes max_position_embeddings the decorator recomputes inv_freq through ROPE_INIT_FUNCTIONS["dynamic"], which reads rope_theta and factor and never looks at alpha. For tencent/HunyuanOCR (alpha=1000.0, factor=1.0 - the latter only present to satisfy rope validation) this moves the high-frequency end of inv_freq by ~250x, so long inputs silently get a corrupted frequency table. The check that guards the update also compares a CUDA tensor against a Python int on every forward, which forces a device-to-host sync and makes the module impossible to capture in a CUDA graph.

Declare the decorator stack explicitly on the override so the modular converter no longer copies Llama's, and add a regression test asserting inv_freq survives positions beyond max_position_embeddings.

@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: hunyuan_vl

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 35487942516
Result: failure | Grafana metrics are not available yet.

@zucchini-nlp zucchini-nlp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, can you also fix the prev hunyuan which i think uses the same rope type?

Comment on lines +574 to 577
# Explicit decorator replaces Llama's inherited `@dynamic_rope_update`. HunYuan VL keeps
# `rope_type="dynamic"` for the NTK-alpha init path, but those frequencies are static.
@torch.no_grad()
def forward(self, x, position_ids):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow, i didn't notice that model has special scaling. That means we fix it in Hunyuan-v2-dense as well no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants