Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

MagicQuant discovers **mixed-precision GGUF quantizations for llama.cpp** that offer better measured tradeoffs between model size and fidelity. It learns tensor configurations from existing quantizations, combines promising choices into new hybrids, and benchmarks the resulting models. The output is a selection of useful GGUFs with the measurements and reproducible recipes behind them.

For controlled search experiments, the [discovery lab](https://github.com/magiccodingman/MagicQuant/blob/main/docs/discovery-lab.md) designs bounded exact-map combinations and analyzes interactions, frontier recovery, short evaluations, and paired measurements. The [implementation and hardware handoff](https://github.com/magiccodingman/MagicQuant/blob/main/docs/discovery-handoff.md) tracks the current review findings, completed groundwork, and next experiments.

**The opportunity is inside the model.** Tensor groups do not all respond to compression in the same way: an attention group may benefit from a higher-precision recipe while a feed-forward group tolerates a smaller one. Their behavior can also change with the surrounding quantization choices. Existing llama.cpp baselines and external quantizations such as Unsloth provide valuable starting recipes; recombining their strengths can uncover choices that a familiar Q4, Q5, or Q6 label alone does not reveal.

MagicQuant investigates those opportunities for your model. It measures group changes, predicts promising combinations, then builds and benchmarks actual GGUFs to find out which improvements hold up. **Predictions guide the search; measured results decide what earns a place.**
Expand Down
73 changes: 73 additions & 0 deletions docs/discovery-handoff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Discovery implementation and hardware handoff

This change implements the correctness fixes and experimental groundwork from the MagicQuant deep review. It does not claim a new measured model-quality gain. Review baseline: `700c5e8eeaff17c3d69bbcbafa9fe0ea9c8d452f` on `main`. The next agent should preserve a current-control campaign and evaluate the opt-in challengers under the same artifact and data protocol.

## What each review finding became

| Review issue | Implemented here | Follow-up requiring real measurements |
|---|---|---|
| Isolated KLD/size improvements can be pruned by absolute PPL-delta rules | Opt-in bounded rescue queue with exact incumbent-state scope | Rebuild the Q6 KV witness and test it in three representative incumbent contexts |
| Contextual probe outcomes can fail to reach final consideration | Reconcile compatible probe outcomes and references, including rejected/harmful outcomes; retain reasons | Verify a real favorable probe reaches truth finalization without globally unbanning a state |
| PAVA can hide useful interaction reversals | Raw/projected exports, projection-change diagnostics, challenger proposal/replay | Compare discoveries from raw, projected and disagreement proposals; no production projection switch added |
| Validation reused training targets and overstated tie accuracy | Explicit reconstruction/holdout scopes, coefficient-fit exclusions, tie-aware metrics, coverage, population identity | Freeze a production population and conduct a real prospective holdout experiment |
| LIMIT preceded eligibility filtering; ordinary windows left an upper interval uncovered | Shared predicate before SQL LIMIT; opt-in complete interior coverage | Compare proposal membership and useful outcomes at an equal new-recipe budget |
| Selection did not refit from new observations | Sequential residual challenger with acquisition traces in the offline lab | Implement a production batch/refit coordinator only after replay and forward trials justify it |
| Carrier-floor effects can distort additive features | Pure-target shortcut removed; fit seams and raw features exposed; residual baseline available | Measure carrier controls; compare nonnegative calibrated damage and context-conditioned models, rather than blindly subtracting a constant |
| Fixed coarse groups miss finer structure | Exact-map factorial/splice planner supports block/family/expert-name subsets | Test architecture-specific dimensions; production group schema is intentionally unchanged |
| Reuse could accept stale source, imatrix, corpus, or raw logs | Content evidence, exact imatrix lookup, reference sidecars, forced remeasurement, history, clone build proof | Cold/warm A→B imatrix and corpus/toolchain mutation campaigns; actual GPU/process checks |
| Evaluation lacked explicit fidelity/uncertainty protocol | Frozen corpus input, partitioned lab observations, paired-block statistics, screening audit | Produce actual token chunks, per-block KLD, native self-comparison, task/long-context checks and topology repeats |
| Scratch ownership may serialize build and evaluation | Stage/queue/process/lifetime timing with existing ownership retained | Measure overlap bottlenecks before changing lease lifetime, concurrency or tensor-payload caching |
| Release spacing obscured the full measured frontier | Separate unspaced measured-evidence archive and curated-membership flags | Confirm close useful points persist even when the downloadable release omits them |

See [runtime search](discovery-search.md), [measurement identity](measurement-evidence.md), [prediction diagnostics](prediction-diagnostics.md), and the [offline lab protocol](discovery-lab.md) for the exact APIs and limitations.

## Phase A: establish an interpretable control

1. Use a prepared small model first. Pin source weights, native GGUF, tokenizer, llama binaries/libraries, imatrix, YAML, architecture/group profile, numerical execution policy, and three disjoint data partitions. Record actual artifact hashes, not only model names or byte lengths.
2. Run the ordinary checks in [testing](testing.md) and the opt-in prepared-model smoke. Then run a short real baseline/isolation/hybrid path. A synthetic unit-test pass is not a numerical-parity result.
3. Exercise cold run, warm reuse, force-relearn, imatrix A→B, imatrix off, changed corpus, and changed evaluator. Each incompatible change must either cause a clearly identified fresh evaluation or fail with an actionable missing-input error. Repeating the unchanged run should reuse compatible evidence.
4. Confirm native reference sidecars and archived old metrics survive repairs. Legacy rows should remain historical and must not silently seed current prediction. Check external baseline first-learning/resume and clone artifact proof as separate paths.
5. Run the same native artifact against its stored reference and compare independent/shared GPU topology on fixed chunks. Record real self-comparison and repeated variation; reference generation's stored native KLD of zero is not this experiment.

Do not compare a fresh challenger against stale legacy scores. Rebuild the current control under the evidence protocol first. Cache hashing adds IO, especially at process start; measure it separately from quantization and inference.

## Phase B: first bounded discovery campaign

Use a total cap of 24 newly built recipes as an initial investigation, with existing compatible controls recorded separately. This is a starting design, not a claim of an optimal allocation.

| Arm | New recipes | Question |
|---|---:|---|
| Current policy after shared correctness fixes | 12 | What does the current search discover with reliable evidence and correct eligibility? |
| Rescue contexts | 3 | Does an isolated KLD/size-favorable but pruned state help in real incumbents? |
| Raw/PAVA disagreement or upper-interval proposals | 3 | Is useful ordering or coverage lost before measurement? |
| Two local 2×2 interaction experiments | 6 | For each existing `00` incumbent, measure `10`, `01`, `11` and inspect the mixed contrast |

Deduplicate concrete maps across arms before building. Predeclare storage ceilings and selection rules. If a proposed map is already measured compatibly, record that reuse and choose whether the saved budget is reallocated according to a written rule. Record failed builds and evaluations; they consume the request budget and do not become high-KLD or successful quality labels.

The initial review's Q6 KV example is a candidate hypothesis: its isolated size/KLD improvement and pruning witness do not establish a finished hybrid win. Reproduce the actual map and current context, then test the bounded substitutions. Do not count aliases of the same concrete map as independent discoveries.

Choose proposals using discovery data only. Use validation to compare the resulting policies and useful frontier points. Evaluate the final selected policy/artifacts once on untouched holdout data. If validation repeatedly guides new choices, preserve a new independent final audit set. Record both recipe counts and build/evaluation time; equal counts are not equal compute.

## Phase C: small oracle and finer structure

If Phase B finds a plausible signal, enumerate a 3×3×3 exact-map space: three meaningful dimensions and three states each. Measure all 27 unique maps, or report any deduplication/failures. Use the lab to compare frontier recall and regret for random, projected, raw, disagreement and sequential residual policies at budgets such as 3, 6 and 12, across fixed seeds. Keep the initially available training labels identical across arms.

Run the comparison at multiple storage ceilings. A global ranking dominated by large, low-KLD artifacts can hide useful small models. Report complete frontier coverage and missing outcomes, not just reconstruction error or the single best KLD.

For an architecture with uncovered SSM or specialized expert structure, use a separate bounded design of at most 16 maps, preserving the incumbent elsewhere. Check that selected names exist, donor maps agree on the full tensor universe, protected F32 tensors remain unchanged, and the built GGUF's resolved map matches the plan. Promote a useful finer dimension into production only after reproducible cross-context evidence warrants the schema/migration work.

## Phase D: evaluation and throughput experiments

Build true nested token subsets from fixed independent chunks. Compare a short budget such as 8,192 tokens with a full 32,768-token budget only after confirming what the evaluator actually consumes. Audit how many full-fidelity frontier points a short screen would discard. Set the acceptable recall target before inspecting the result; promotion policy must preserve small-budget candidates as well as low-KLD large ones.

For close contenders, preserve paired per-block loss sums, token counts, and content IDs. Compare the paired interval with observed effect size. Repeated identical-chunk hardware runs answer numerical variation; block resampling answers variation across evaluation chunks. They are different experiments. Add a compact task-specific and long-context check for final candidates, using separate labels and provenance.

Use timing sidecars to distinguish writer wait, CPU wait, quantization/preparation, GPU wait, process time, artifact lifetime and cleanup. Only then trial releasing a scratch writer while retaining the artifact lease, or a bounded artifact/tensor cache. Require byte/recipe parity, output-map parity, measured-quality parity, cancellation cleanup and disk-capacity bounds before adopting new concurrency behavior. This branch does not change those ownership defaults.

## Acceptance and stop rules

A challenger is promising when it improves compatible validation/holdout KLD at a predeclared byte ceiling, or discovers additional useful non-dominated points, by more than the measured uncertainty or repeat variation. Confirm the exact built map and actual bytes. Gains in prediction MAE alone do not meet this criterion.

Retain the current policy if the bounded challengers fail to improve frontier outcomes after comparable requests/costs, or if apparent improvements disappear on held-out chunks. That result supports a local plateau within the tested recipe vocabulary and budget. It does not prove the global mixed-precision optimum. Report which dimensions, contexts and budgets were tested so the conclusion remains useful.

The handoff deliverable should contain the immutable plan, frozen score exports with training provenance, candidate/map joins, per-attempt observations and failures, current benchmark envelopes, full measured frontier, curated release subset, cost/coverage tables, and a short decision for each challenger. Keep the final held-out outcomes out of subsequent fitting.
Loading
Loading