Skip to content

fix(gguf): keep the Muse companion seed out of the target namespace - #125

Merged
Brooooooklyn merged 6 commits into
mainfrom
fix/muse-companion-phantom-quant
Aug 22, 2026
Merged

Brooooooklyn merged 6 commits into
mainfrom
fix/muse-companion-phantom-quant

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

When the target config.json carries no quantization block, prepare_muse_secondary_config seeded both aliases from the companion's block and then ran the target rescope over that seed. The companion's per-tensor keys are already spelled in the draft namespace, so the rescope invented a target override that was never asked for.

GGUF blk.0.attn_q      ─normalize_override_key─►  language_model.model.layers.0.self_attn.q_proj
                       ─rescope─►  language_model.model.language_model.layers.0.self_attn.q_proj   ◄─ PHANTOM
                       ─normalize_per_layer_key─►  language_model.layers.0.self_attn.q_proj
                                                    == quant_lookup_prefix(target layer 0 q_proj)
muse_projection_quant tries the scoped key FIRST  ─►  the target inherits the draft's q4k geometry

Severity: latent today, loud tomorrow

The seeding branch is reachable only when the target has no quantization block at all, which means an entirely float target. build_projection computes the per-layer quant but only consumes it inside if params.contains_key("{prefix}.scales"), and a float target has no scales — so the override is discarded. Today the user gets a bogus key in config.json and nothing else.

Two ways it stops being harmless, both verified rather than assumed:

  • Repeating the companion pass hard-errors. The second pass rescopes the re-inserted draft key onto the phantom already present and hits "companion quantization collides with existing scoped target override". This is wider than --config-dir: the function reads output_dir/config.json, so any repeat against an already-converted output dir reaches it.
  • It disables a safety refusal. With the block seeded, top_mode becomes Some, so the "packed weights but config.json has no quantization mode" check no longer fires. A quantized target with no alias would go from a loud refusal to a silent mis-decode.

The fix

Build the merged block once and assign it to both aliases, and rescope only a block that came from a target alias. When no target block exists, the companion's block is used as-is — its per-tensor entries are restated verbatim by the profiles loop immediately after, so not rescoping them loses nothing.

This subsumes #120's sibling fix; single_alias_target_does_not_produce_disagreeing_companion_aliases still passes.

One deliberate behavior change. Two aliases that are both present and disagree now error instead of each being transformed independently. That input is already unloadable — select_quantization_block rejects it — so the alternative was silently picking one half, possibly the wrong one. This function runs before the destructive save, so the failure simply moves earlier.

Gate

companion_seed_does_not_rescope_draft_keys_into_the_target_namespace, on the same fixture as the existing test — which is the point, since that test produces the phantom and never notices. It asserts anti-vacuity first (the fixture really has neither alias, or the seeding branch never runs and the test proves nothing), then that the draft's own override survives, the literal phantom is absent, and — writing the config out and reading it back through the real loader — that no key resolves onto any target projection across 52 layers × 8 projections plus embed_tokens.

Mutation-checked in two stages: restoring the old shared-seed rescope makes it fail; then, still mutated, disabling the literal-phantom assertion leaves it failing at the resolver loop. So the spelling-independent half is not carried by the literal one.

clippy --all-targets 0 warnings. utils::gguf:: 73, convert 220, models::muse_glimmer:: 216, models::quant_dispatch:: 41 — 0 failures.

Repeated companion merges: refused, not silently merged

A reviewer raised that a repeated companion pass re-creates the phantom, because target_block then holds the
draft profiles the previous pass wrote and the rescope cannot tell them from genuine target overrides.

Correcting this PR's earlier claim. An earlier revision of this description said the fix "turned a loud
failure into a silent one" on the second pass. That is wrong, and it was checked by running
prepare_muse_secondary_config from both main and this branch over three chained passes. For a target that
carries a quantization alias — uniform, single-alias, or with an explicit per-layer override — the two
revisions are bit-identical at every pass: main's rescope loop moves the previous pass's draft keys
exactly as this one does. The repeated-pass phantom is pre-existing and unchanged in kind.

The only shape whose pass index moved is a target with no quantization block, and that shape is issue
#123: on main the companion seed put the phantom there on pass 1, so main's pass-2 error was main
tripping over its own corruption rather than a guard worth preserving. That shape is also inert — no
quantization block means a float target, and build_projection consumes the resolved override only inside
if params.contains_key("{prefix}.scales").

The obvious discriminator does not exist. Excluding entries whose key is also a companion profile key
looks like it would work, and does not: the SafeTensors target converter writes genuine target overrides at
the same spelling the draft uses — that is the only reason the rescope loop exists — and
companion_quantization_keeps_target_and_dflash_layers_distinct pins a real target q6k override at exactly
the key the draft owns as q4k. Key-identity would delete a real target pin, and value-identity fails whenever
a Q4_K target meets a Q4_K draft. Separating the two provenances needs the companion to write under its own
on-disk namespace, which is a format decision with migration consequences.

So the ambiguous input is refused instead — keyed on the ambiguity itself, not on a marker.

A first attempt keyed the refusal on dflash_config alone, on the premise that this function is the only
on-disk writer of it. A reviewer showed that premise is false: when --config-dir points at an already
converted Muse directory, the primary conversion copies that config forward, marker included, so the draft
pass would always refuse — and the suggested remedy, a fresh output directory, is what the CLI already does.

The obvious repair, clearing the marker in the primary, is strictly worse, and the reason is the decisive
fact here: the primary does not always rebuild the quantization block. When the source is neither quantized by
this run nor carries preserved source quantization, the copied block passes through verbatim, previous draft
entries and all. Clearing the marker there would remove the signal and keep the ambiguous data, so the phantom
would come back silently. Verified by probe rather than argued.

The refusal therefore requires both conditions:

non-null dflash_config bare-prefix entry in the block verdict
no — allow: a bare entry is the target's own, and is rescoped
yes no allow: the primary rebuilt the block, so nothing is ambiguous
yes yes refuse: a previous draft pass wrote in the namespace a target override also uses

The marker means a non-null dflash_config. Key presence alone disagreed with the loader, whose
Option<MuseGlimmerDFlashConfig> maps a JSON null to None — so an explicit null would have refused a first
companion pass. No writer in the tree emits a null; the schema permits it and two copy paths preserve it, so
this is marker/loader alignment rather than an observed failure.

Why no further narrowing is needed, which the earlier rounds did not establish: a Muse main-GGUF primary that
rebuilds the block always writes it one wrapper deeper, into language_model.model.language_model.layers.*.
So any unscoped key present when the guard runs was copied from a config describing a different
checkpoint, or written by a previous secondary merge. There is no input where a correct, current block reaches
the guard. A dense primary is the case that makes this visible: it rebuilds nothing, the copied block survives
verbatim, and disabling the guard there writes the issue-#123 phantom outright.

It also binds the block rather than the running companion. The rescope loop walks the target block, so a
vision pass over a merged config invents the same phantom; an is_dflash conjunct would have let it through.

The error now names the offending key and gives advice the user can act on: point --config-dir at the base
model directory rather than a converted output, or re-run the primary so it rebuilds the block.

Five mutations were run and each observed failing: dropping either half of the condition, restoring the
marker-only guard, re-adding the is_dflash conjunct, deleting the guard entirely, and — as the anti-vacuity
proof — making the primary strip dflash_config, which fails the test's on-disk marker assertion.

Still open, deliberately. A stale dflash_config is still written into an output that has no
draft.safetensors, when --config-dir points at a converted output and no --draft is given. It is inert at
load, since the loader returns early when the draft file is absent, and clearing it is the unsafe move above.
Removing it properly means clearing the bare-prefix entries alongside it, in the primary path every family
shares — a larger blast radius than this PR. The same pass-through arm also leaves a quantization block that is
stale for the new weights independently of DFlash; that is pre-existing and untouched.

Separately, muse_projection_quant's bare-namespace fallback resolves a target prefix down to the draft's own
key, so a target projection with no scoped override still picks up draft geometry. That is asserted as
intended by target_and_dflash_quantization_namespaces_stay_distinct, so it is a design question, not this bug.

Fixes #123

🤖 Generated with Claude Code

https://claude.ai/code/session_01MCBk7iwMve89ru8c116kki

@cursor

cursor Bot commented Aug 21, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_32dd7d9c-0005-463d-b7e6-8d8e76a82cfb)

@coderabbitai

coderabbitai Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c6d6e5e3-174f-4763-bc0e-e15b8d66652c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d667eba59f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/mlx-core/src/utils/gguf.rs Resolved
@cursor

cursor Bot commented Aug 21, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_9135a104-45d8-44c8-9f8a-0f5929b98e9a)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 39e76c408b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/mlx-core/src/utils/gguf.rs Resolved
Brooooooklyn and others added 4 commits August 22, 2026 10:30
A target config carrying neither quantization alias seeded both from the
companion block, and the rescope loop then read the draft's own
`language_model.model.layers.*` entries as target overrides and moved them one
wrapper deeper — the exact spelling a target projection resolves to. The merged
block is now built once, rescoping only entries that came from a target alias,
and assigned to both aliases.

Closes #123

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MCBk7iwMve89ru8c116kki
A config that already carries `dflash_config` was merged by a previous
companion pass, and the draft profiles that pass wrote share the target
overrides' spelling. Rescoping them again reinvents the phantom target
override, so fail closed instead.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MCBk7iwMve89ru8c116kki
The guard's `is_dflash` conjunct was behaviourally load-bearing but
unobserved: dropping it left every test green while a mixed-quant mmproj
against a merged sidecar was wrongly refused.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MCBk7iwMve89ru8c116kki
…e marker

`prepare_muse_secondary_config` refused any DFlash pass over a config
carrying `dflash_config`, on the premise that it is the only writer of
that key. The primary conversion copies `--config-dir`'s config.json
verbatim (gguf.rs:3724), so pointing `--config-dir` at an already
converted Muse directory propagates the marker into the fresh staged
output and every subsequent `--draft` pass was refused — with advice to
use a fresh output directory the CLI already stages.

Clearing the marker in the primary is not the fix: the block is only
rebuilt when `do_quantize` or a visible source profile applies, so a
float source or a K-quant source without `--gguf-kquant` carries the
previous draft's per-layer entries through with it. Stripping the marker
there would drop the signal and keep the ambiguity.

Refuse instead when the marker sits beside an entry still under the
namespace the rescope walks — the state that actually cannot be
attributed — and name that entry in the error. The condition binds the
block rather than the running companion: a vision pass rescopes the same
target block and invented the same phantom.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MCBk7iwMve89ru8c116kki
@Brooooooklyn
Brooooooklyn force-pushed the fix/muse-companion-phantom-quant branch from 39e76c4 to e43256a Compare August 22, 2026 02:47
@cursor

cursor Bot commented Aug 22, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_d5edfbd5-d830-4163-b1e6-c921179b7b34)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e43256a8ce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/mlx-core/src/utils/gguf.rs Resolved
`dflash_config` is optional, and `MuseGlimmerConfig`'s
`Option<MuseGlimmerDFlashConfig>` reads an explicit JSON `null` as absent.
The companion guard's marker used `get(...).is_some()`, which tests key
presence, so a target config that spells the field out as null and carries
an unscoped per-layer override was refused on its FIRST quantized companion
pass as an already-merged draft. Key the marker on a non-null value so it
means what the loader means.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MCBk7iwMve89ru8c116kki
@cursor

cursor Bot commented Aug 22, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_0c5402d4-6009-4704-a6cf-cba5289e72f4)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e3289cee5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/mlx-core/src/utils/gguf.rs Resolved
The copied-marker regression test converts a Q4_0/Q4_1 primary, so the
conversion rebuilds both aliases one wrapper deeper and the guard is never
reached — deleting the guard leaves that test green. A primary whose GGUF is
dense and that is not asked to quantize rebuilds neither alias, so the
`--config-dir` block reaches the merge verbatim, draft overrides included;
that is the arm the refusal actually fires on and it had no coverage.

The comment above the guard asserted the primary always rebuilds the block,
which that arm falsifies.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MCBk7iwMve89ru8c116kki
@cursor

cursor Bot commented Aug 22, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_9ee39101-0240-44eb-b389-82a8651e3fad)

@Brooooooklyn
Brooooooklyn merged commit 233dbb3 into main Aug 22, 2026
7 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/muse-companion-phantom-quant branch August 22, 2026 05:20
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.

Muse-Glimmer: a K-quant companion injects a phantom quantization override onto the target when the target config has no quantization block

1 participant