Skip to content

refactor(paged-attn): remove test-only KvScaleManager FP8 calibration API - #262

Closed
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1792073172-remove-kv-scale-manager
Closed

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1792073172-remove-kv-scale-manager

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Removes dead code: KvScaleManager (FP8 KV-scale calibration) only ran from tests. PagedKVCacheAdapter.scale_manager started as None, and its only setter, set_scale_manager, was #[cfg(all(test, target_os = "macos"))]. So in production every Some(manager) branch was unreachable and K/V scales were always 1.0. There is no #[napi] or TS exposure.

Removed:

  • crates/mlx-paged-attn/src/metal/kv_scale.rs and its KvScaleManager / KvScaleStats re-export in metal/mod.rs
  • crates/mlx-paged-attn/tests/kv_scale_calibration.rs
  • From PagedKVCacheAdapter: the scale_manager and scale_arrays fields, set_scale_manager / scale_manager (test-gated), read_layer_scales, lookup_{k,v,}_scale, cached_scale_array, and the 6 tests that install a manager

What replaces them:

// macOS
pub fn k_scale_array(&mut self, _layer_idx: u32) -> Result<MxArray, String> {
    Ok(self.unit_kv_scale_array.clone())   // same as the old `scale_manager.is_none()` early return
}
// update_keys_values / gather_kv_for_decode
let (k_scale, v_scale) = (1.0, 1.0);       // was self.read_layer_scales(layer_idx)? -> Ok((1.0, 1.0))

On non-macOS, k_scale_array / v_scale_array now build a fresh [1] 1.0 array on each call. Before, they went through the scale_arrays memo. All callers are macOS-gated, so this only affects the non-macOS compile surface.

Also updated comments and docs/perf.md that pointed at KvScaleManager. The kept test k_v_scale_arrays_default_to_one_when_no_manager still pins the [1] / f32 / 1.0 contract.

Verification: cargo fmt --check passes. mlx-sys can't build on the Linux dev VM, so build, clippy and tests are left to macOS CI.

Link to Devin session: https://app.devin.ai/sessions/94f6bdacb1004d828fbc1aec579a7a56
Open in Devin Desktop: https://app.devin.ai/desktop/session/94f6bdacb1004d828fbc1aec579a7a56?variant=devin
Requested by: @Brooooooklyn

… API

PagedKVCacheAdapter never installs a KvScaleManager outside tests
(set_scale_manager/scale_manager were #[cfg(test)]), so production
always ran with unit (1.0) K/V scales. Remove kv_scale.rs, its
re-export, the kv_scale_calibration integration test, and the adapter's
scale_manager plumbing; k_scale_array/v_scale_array now return the unit
scale array and write/gather pass 1.0 scales directly.

Co-Authored-By: Brooklyn <[email protected]>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@coderabbitai

coderabbitai Bot commented Oct 15, 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: Advanced
  • Run ID: c903e7ce-d715-4e0d-b6dd-9df62898d9a6

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
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Closing in favor of one combined dead-code cleanup PR (requested by the maintainer). The new PR will include this branch's changes.

Brooooooklyn added a commit that referenced this pull request Oct 16, 2026
…283) (#284)

## Summary
This PR removes the dead code reported by the dead-code scan of
`mlx-node/mlx-node`. It replaces the 62 single-finding PRs #222–#283,
which are closed and had their CI cancelled. Each of those branches is
merged here as-is, in PR-number order, so `git log --first-parent` lists
every removal under its original PR title. Of the scan's 79 open
findings, 78 are covered here. The remaining one,
`Qwen4ExpModel.residencyInfo()`, was dismissed as a false positive
because it is a documented diagnostics API.

Totals: 159 files changed, about 16k lines deleted and about 440 added.
Most of the added lines are helpers moved into `#[cfg(test)]` modules,
plus doc and comment updates.

Biggest removals:
- `crates/mlx-core/src/gradients/` (the legacy `Gradients` API) and the
Rust `Adam`/`SGD`/`RMSprop`/`LRScheduler` optimizers. AdamW stays.
- The never-dispatched `copy_blocks` Metal kernel, the test-only
`KvScaleManager` FP8 calibration API (the FP8 scales are now always
`1.0`, as in production), and the test-only `profile_run` auto-sizer.
- Unused `mlx-sys` FFI wrappers, the unused `mlx-db` API (`AsyncDb`,
`DbConfig`, run-lifecycle/log writers), and unused `OutputStore`
queries.
- The test-only Gemma4 large sliding-restore suppression policy
(`MLX_GEMMA4_MAX_SLIDING_RESTORE_TOKENS`), and the cold-tier
`restore_suppressed` counter, which production never incremented. The
dashboard trace index drops `cold_sidecar_restore_suppressed`, and
`SCHEMA_VERSION` goes from 7 to 8, so the index rebuilds from JSONL.
- Stale files: `example-tools.js`, the
`experiments/flashqla/int8-recovery/` fragments, 16 unused
`__test__/test-utils.ts` helpers, and the dashboard `tooltip` component
together with `@radix-ui/react-tooltip`.

Two merges needed conflict resolution, and both kept the removals from
each side:
- `crates/mlx-paged-attn/src/metal/mod.rs`: #255 (`copy_blocks`) against
#262 (`kv_scale`).
- `crates/mlx-core/src/tools/mod.rs`: #246 against #263.

## Breaking changes (public `@mlx-node/*` surface)
- `@mlx-node/core`:
- Removed the `Tensor` class and the
`parseToolCallsFromText()`/`ParseToolCallsResult`,
`gdnPrefixCheckpointLimit()`, and
`quantizedQmvMicrobench()`/`QmvQuantizedMicrobenchResult` exports.
- Removed these `MxArray` methods: `tan`, `sinh`, `cosh`, `arcsin`,
`arccos`, `arctan`, `evalAsync`, `getBatchSeqLen`, and
`getBatchSeqHidden`.
- Removed `OutputStore.getRecentGenerations`, `getGenerationsByReward`,
`getGenerationsByFinishReason`, `exportJsonl`, and `queryRaw`.
- Removed `Qwen3Model.validateParameters`,
`MuseGlimmerModel.autoEnablesMtp`, and the always-erroring
`SftTrainingEngine.getModel`.
- `@mlx-node/core` / `@mlx-node/vlm`: removed
`TextDetModel.detectCrop()` and `TextRecModel.recognizeCrop()`. Use
`detect()` / `recognize()` with an encoded image instead.
- `@mlx-node/lm`: removed the `ChatMessageWithTools` and
`ApplyChatTemplateOptions` types.
- `@mlx-node/server`: removed `readDesktopEndpoint`.
- Removed the desktop sidecar control ops `health` and `load`.

## Verification
- CI is green: 9 checks passed and 1 (e2e) was skipped. The macOS
`mlx-core` lib tests passed (3,947 passed, 0 failed), along with
integration, other crates, and Clippy.
- The macOS-only test
`gemma4_coordinator_is_lawful_under_the_permissive_checker` still calls
`NoDurableSettleInCycle::into_inner`, so 31fd05e brings that helper
back. Code gated by `cfg(target_os = "macos")` was searched for any
other references to removed symbols, and none were found.

Link to Devin session:
https://app.devin.ai/sessions/62a7b98e3d054aaca83c94c609273d7b
Open in Devin Desktop:
https://app.devin.ai/desktop/session/62a7b98e3d054aaca83c94c609273d7b?variant=devin
Requested by: @Brooooooklyn

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Brooklyn <[email protected]>
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.

1 participant