veloxquant_mlx.cache.squeeze_coordinator module¶
SqueezeAttention cross-layer coordinator — one-shot data-driven re-budgeting.
The repo’s contract is one cache object per layer; mlx_lm.generate iterates
them independently. SqueezeAttention needs a global view to reallocate a fixed
total budget across layers by their measured attention concentration. Rather than
modify the model forward pass, all SqueezeAttentionCache instances of a model
hold a reference to a single shared SqueezeCoordinator (injected at
KVCacheBuilder.for_model build time).
The re-budget is one-shot at the prefill boundary: during the first
update_and_fetch (the prompt), each layer reports its concentration score.
Once every attention layer has reported, the coordinator computes the per-layer
budget schedule with squeeze_budgets and publishes it; each layer then pulls
its resolved budget and applies it to every head’s eviction state. Decode steps
run against the frozen schedule — no further re-budgeting.
Unlike the XQuant / MiniCache coordinators (which exchange tensors every step), this coordinator exchanges only per-layer scalars and runs its allocation exactly once. Single-threaded by construction (mlx generate is sequential), so plain dicts need no locking.
- class veloxquant_mlx.cache.squeeze_coordinator.SqueezeCoordinator(n_layers, avg_budget, n_sink, strength)[source]¶
Bases:
objectShared per-model re-budgeting state for one generation.
- Parameters:
- report_concentration(layer_id, concentration)[source]¶
Record a layer’s prefill concentration score.
Idempotent per layer: the first report for a layer wins (prefill only); later reports (decode steps) are ignored so the schedule stays frozen.
Once all
n_layershave reported, the budget schedule is computed and cached so subsequentresolved_budgetcalls return real values.