Skip to content
Merged
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
13 changes: 8 additions & 5 deletions Libraries/MLXLLM/Models/GPTOSS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,13 @@ class AttentionBlock: Module {
return active
}()

// Quantized cache path
// Quantized cache path (taken when the cache conforms to
// QuantizedKVCacheProtocol, i.e. the native quantized-attention kernel).
// Attention sinks are threaded through so the kernel folds them into the
// softmax denominator and stays correct for sink models — no fatalError.
// (Note: GPT-OSS defaults to the dequant cache for decode speed; this
// path is used only when the kernel cache is selected.)
if let qcache = cache as? QuantizedKVCacheProtocol {
if sinksActive {
fatalError("Quantized attention does not support non-zero sinks.")
}
q = applyRotaryPosition(rope, to: q, cache: cache)
k = applyRotaryPosition(rope, to: k, cache: cache)

Expand All @@ -241,7 +243,8 @@ class AttentionBlock: Module {
mask: mask,
groupSize: qcache.groupSize,
bits: qcache.bits,
mode: qcache.mode
mode: qcache.mode,
sinks: sinksActive ? sinks : nil
)

return oProj(vHat.swappedAxes(1, 2).reshaped(B, L, -1))
Expand Down
4 changes: 2 additions & 2 deletions Libraries/MLXLMCommon/BatchKVCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public final class BatchKVCache: BaseKVCache, BatchPositionedKVCache, BatchedCac
self.keys?[.ellipsis, prev ..< _idx, 0...] = keys
self.values?[.ellipsis, prev ..< _idx, 0...] = values

// DAR-325: collapse the per-step `batchOffset` lazy chain on decode.
// Collapse the per-step `batchOffset` lazy chain on decode.
// gemma-4 shares one RoPE `perRowOffset` from the first cache
// (Gemma4.swift:1264), so other caches never consume their own
// `batchOffset` and leak a tiny scalar buffer/step (COUNT leak, flat
Expand Down Expand Up @@ -610,7 +610,7 @@ public final class BatchRotatingKVCache: BaseKVCache, BatchPositionedKVCache, Ba
_idx = maxCacheSize
}

// DAR-325: collapse the per-step `batchOffset`/`leftPadding` lazy chains
// Collapse the per-step `batchOffset`/`leftPadding` lazy chains
// on decode (rebuilt at :594/:600). gemma-4 consumes each from only one
// representative cache (shared RoPE offset + one sliding mask), so the
// others leak ~2 tiny scalar buffers/step until `numResources` hits the
Expand Down
18 changes: 10 additions & 8 deletions Libraries/MLXLMCommon/ContinuousBatching/EngineCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,20 @@ public final class EngineCore: @unchecked Sendable {
// live-buffer climb (count climbs while cache stays small -> needs admission
// control) — the latter is the `[metal::malloc] Resource limit (499000)` crash.
//
// DEFAULT ON: `darkbloom report` collects logs via
// `log show --predicate 'subsystem == "dev.darkbloom.provider"'`, so the
// `[rsrc]` line is emitted via os_log under that subsystem (not just stdout)
// and is therefore captured in every uploaded report — giving us the
// resource-count trajectory before a crash without asking the operator to set
// any env var. Opt out with DARKBLOOM_MLX_RESOURCE_DEBUG=0 (or false/no/off).
// DEFAULT OFF (opt-in): the `Memory.*` resource/byte reads in the step loop
// (see `engineLoop`) sit on the per-step decode hot path, so they are gated
// behind this flag and not evaluated at all unless an operator opts in.
// Enable with DARKBLOOM_MLX_RESOURCE_DEBUG=1 (or true/yes/on) to collect the
// `[rsrc]` trajectory; `darkbloom report` then captures the os_log line via
// `log show --predicate 'subsystem == "dev.darkbloom.provider"'`. The
// capability is unchanged — it simply costs nothing when disabled, which is
// the default.
private static let resourceDebug: Bool = {
switch ProcessInfo.processInfo.environment["DARKBLOOM_MLX_RESOURCE_DEBUG"]?
.lowercased()
{
case "0", "false", "no", "off": return false
default: return true
case "1", "true", "yes", "on": return true
default: return false
}
}()
// Console cadence (stdout). Frequent, so the console line is TTY-gated (see
Expand Down
Loading