Add Hunyuan dense V1 (hunyuan_v1_dense): Hunyuan-MT-7B and Hy-MT2-7B#347
Open
beshkenadze wants to merge 1 commit into
Open
Add Hunyuan dense V1 (hunyuan_v1_dense): Hunyuan-MT-7B and Hy-MT2-7B#347beshkenadze wants to merge 1 commit into
beshkenadze wants to merge 1 commit into
Conversation
Tencent's Hunyuan dense V1 architecture (HunYuanDenseV1ForCausalLM), used by the translation models Hunyuan-MT-7B and Hy-MT2-7B. A Llama-family dense transformer, closest to the existing Qwen3 path: - Per-head QK RMSNorm, GQA, SwiGLU MLP, pre/post RMSNorm blocks. - Tied embeddings (sanitize drops the tied lm_head). - DynamicNTKAlphaRoPE: rescales the RoPE base once by alpha^(dim/(dim-2)) and reuses the existing freqs-based fast-RoPE path (no sequence-length-dependent resizing). Changes: - Libraries/MLXLMCommon/RoPEUtils.swift: DynamicNTKAlphaRoPE. - Libraries/MLXLLM/Models/Hunyuan.swift: HunyuanModel / HunyuanConfiguration (flat config decode; accepts head_dim or attention_head_dim; conditional qk-norm). - Libraries/MLXLLM/LLMModelFactory.swift: register hunyuan_v1_dense; presets hunyuan_mt_7b_4bit/8bit and hy_mt2_7b_4bit/8bit. - Tests/MLXLMTests/HunyuanTests.swift: config decode, attention_head_dim alias, sanitize, tiny forward, dynamic-RoPE alpha, presets. Validated end-to-end against the mlx-lm reference (byte-identical greedy) on locally converted 4-bit weights for both models.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds Tencent's Hunyuan dense V1 architecture (
hunyuan_v1_dense/HunYuanDenseV1ForCausalLM), used by the translation models Hunyuan-MT-7B and Hy-MT2-7B. Ported from mlx-lm'shunyuan_v1_dense.py.Architecture
A Llama-family dense transformer, closest to the existing Qwen3 path:
sanitizedrops the tiedlm_head).DynamicNTKAlphaRoPE— the one new utility: rescales the RoPE base once byalpha^(dim/(dim-2))and reuses the existing freqs-based fast-RoPE path (no sequence-length-dependent resizing). Lives alongsideYarnRoPE/Llama3RoPE/ProportionalRoPEinRoPEUtils.swift.Changes
Libraries/MLXLMCommon/RoPEUtils.swift:DynamicNTKAlphaRoPE.Libraries/MLXLLM/Models/Hunyuan.swift:HunyuanModel/HunyuanConfiguration(flat config decode; acceptshead_dimorattention_head_dim; conditional qk-norm).Libraries/MLXLLM/LLMModelFactory.swift: registerhunyuan_v1_dense; presetshunyuan_mt_7b_4bit/8bitandhy_mt2_7b_4bit/8bit.Tests/MLXLMTests/HunyuanTests.swift: config decode,attention_head_dimalias, sanitize, tiny forward, dynamic-RoPE alpha, presets.Validation
6/6 unit tests pass; package builds.
End-to-end byte-identical parity vs the mlx-lm reference (greedy) on locally-converted 4-bit weights for both models:
Prompt: Translate the following segment into Chinese, without additional explanation.\n\nIt's on the house.
HunyuanModelIdentical — validates config decode, weight loading, qk-norm, GQA, dynamic RoPE, tied embeddings, and the chat template.
MLX weights:
mlx-community/Hunyuan-MT-7B-{4bit,8bit}andmlx-community/Hy-MT2-7B-{4bit,8bit}.