Repository navigation
Conversation
Before folding bailing_hybrid's MultiLatentAttention and bailing_moe_v3's GatedMlaAttention into one shared core (#3782), record their current behavior. A test-only oracle reproduces the pre-refactor MLA forward op for op on the same layer types, and each family's parity test runs its real attention module and the oracle on fixed-seed weights for a three-token prefill and two cached decode steps, requiring bit-identical outputs (max_abs_diff == 0 and equal f32 bits). Coverage: both query forms (q_lora_rank set and unset) for both families, both RoPE pair layouts and both mask sources (caller mask and the layer's causal mode) for bailing_hybrid, and the per-head output gate for bailing_moe_v3. The rotary width is 4 so the two RoPE pair layouts actually differ, and the caller mask is not plain causal so a layer that dropped it would diverge. Comparing against the oracle rather than a stored fixture keeps the check exact on every CI backend. Passes on main's implementation (CUDA, GB10). Refs #3782
bailing_moe_v3's GatedMlaAttention repeated about 80 lines of bailing_hybrid's MultiLatentAttention forward, so a fix such as #3736's embed_q layout change had to be made twice. Both now wrap a pub(crate) BailingMla in src/models/bailing_mla.rs that owns the shared fields, the loading and the forward. It is parameterized by the three places the families differ: MlaSpec::rope_traditional (hybrid reads rope_interleave, v3 is always interleaved), the FoldedMask argument (the hybrid caller mask or causal mode, v3's fixed causal mode), and MlaSpec::output_gate, the per-head sigmoid(g_proj(x)) gate applied before dense. The absorbed-plane loading stays per family through a closure: hybrid still splits a raw kv_b_proj, v3 still reads only the pre-split planes. Weight keys, supported checkpoints and public types are unchanged. sigmoid_f32_as moves into the core, and v3's KDA gate imports it from there. The hybrid prefill planner reads the layer shape through BailingMla::prefill_attention. Validation (CUDA, GB10): the parity tests from the previous commit, recorded against main's implementation, still pass bit for bit, and flipping the RoPE layout or dropping the caller mask in the core makes them fail. A one-off logit dump of both tiny models (prefill plus two decode steps, both q_lora forms for v3, two kv_lora_rank values for hybrid) was bit-identical before and after. All 146 bailing lib tests pass, and clippy passes on default features and with --features cuda. Closes #3782
10 tasks
This branch has not been deployed
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.
Summary
bailing_hybrid::MultiLatentAttentionandbailing_moe_v3::GatedMlaAttentionnow wrap onepub(crate)core,BailingMlainsrc/models/bailing_mla.rs, so a fix to the MLA forward (like #3736'sembed_qlayout fix) lands once. The core takes the three things that differ between the families:MlaSpec::rope_traditional, aFoldedMaskargument (hybrid passes the caller mask or causal mode, v3 always causal), andMlaSpec::output_gate(v3's per-headsigmoid(g_proj(x))beforedense). Each family still loads its own absorbed planes through a closure: hybrid still splits a rawkv_b_proj, and v3 still reads only the pre-split planes. Weight keys, supported checkpoints and type names are unchanged.mla_rope.rsandrope_folded_attentionare untouched.Parity evidence
bailing_mla_parity_oracle.rs) reproduces the pre-refactor forward op for op. Each test runs the real module and the oracle on fixed-seed weights for a 3-token prefill and two cached decode steps, and requiresmax_abs_diff == 0with identical f32 bits. The tests cover bothq_lora_rankforms. For hybrid they also cover both RoPE layouts and both mask sources, and for v3 the gate. I compared against the oracle rather than a stored fixture because a fixture recorded on one backend would not stay bit-exact on the other CI backends.q_lora_rankset and null, hybrid with twokv_lora_rankvalues) was bit-identical between main and this branch.Test plan
cargo test --profile test-fast --features cuda -p mlxcel --lib -- bailing mla(200 passed, after merging current main)cargo clippy --all-targets -- -D warningson default features and--features cuda,cargo fmt --check,check_env_var_docs.py,mlx_test_guard_coverageNot run: a real-checkpoint greedy generate comparison. No
bailing_hybridorbailing_moe_v3checkpoint is available on the test hosts.Closes #3782