Repository navigation
Closed
Labels
area:coremlxcel-core: MLX FFI, primitives, KV cache, layersarea:inferenceGeneration, sampling, decoding (incl. speculative, DRY)priority:lowLow prioritystatus:doneCompletedtype:performancePerformance improvements
Milestone
Description
Summary
Maintain incremental per-sequence sampler state so repetition, frequency/presence, and DRY penalties, plus selected-token logprobs, stop rebuilding sorted sets, hashmaps, and full-vocab vectors every token in long generations.
Source: idea.md "6. Sampling Option State Caches" (P2, expected payoff low to medium, risk low-medium).
Current state
- Repetition penalty copies, sorts, and deduplicates token history each token (
src/lib/mlxcel-core/src/sampling.rs, around line 336). - Frequency/presence penalty rebuilds a token-count
HashMapand allocates a full-vocabulary penalty vector each token (src/lib/mlxcel-core/src/sampling.rs, around line 366). - DRY penalty intentionally runs CPU-side sequential pattern matching and builds maps for the current window (
src/lib/mlxcel-core/src/sampling.rs, around line 396). compute_logprobs()applies full log-softmax plus extra gathers/evals when enabled (src/lib/mlxcel-core/src/sampling.rs:530).
Proposal
- Maintain incremental per-sequence sampler state:
- sorted/deduped seen-token set for repetition penalty,
- token counts for frequency/presence penalty,
- reusable sparse index/value buffers for touched tokens,
- optional DRY window index cache for long outputs.
- Add a selected-token-only logprob fast path when
top_k == 0, IF the numerical semantics can remain OpenAI-compatible.
Validation
- Microbench long generations with repetition/frequency/DRY enabled and disabled.
- Server test with mixed option usage to ensure no baseline overhead when options are off.
- Deterministic parity for penalty-adjusted greedy sampling.
Acceptance criteria
- Per-sequence incremental state replaces per-token rebuilds for repetition and frequency/presence penalties.
- Reusable sparse buffers avoid full-vocab allocation per token for touched tokens.
- Optional DRY window index cache for long outputs, with behavior unchanged.
- Selected-token-only logprob fast path for
top_k == 0, only if OpenAI-compatible numerics are preserved; otherwise documented as not feasible. - NO added baseline overhead when penalties and logprobs are off, verified by the server test.
- Deterministic parity for penalty-adjusted greedy sampling.
Risk and priority
idea.md priority P2; risk low-medium. Does not help the default no-penalty path; it reduces CPU and allocation overhead for OpenAI-compatible sampling features in long generations.
References
- idea.md "6. Sampling Option State Caches".
- Code:
src/lib/mlxcel-core/src/sampling.rs(repetition/frequency/DRY penalties,compute_logprobs).
Metadata
Metadata
Assignees
Labels
area:coremlxcel-core: MLX FFI, primitives, KV cache, layersarea:inferenceGeneration, sampling, decoding (incl. speculative, DRY)priority:lowLow prioritystatus:doneCompletedtype:performancePerformance improvements
Activity