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
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ extension EngineLoopV2 {
let constraintEligible =
rec.request.tokenConstraint == nil || grammarMTPEnabled
|| mtpSpanConstraint(rec) != nil
// A reasoning budget keeps the whole request target-only: no drafts
// and no assistant history.
// A reasoning budget, or a prompt over the configured draft limit
// (`CBv2MTPConfig.maxDraftPromptTokens`), keeps the whole request
// target-only: no drafts and no assistant history.
guard rec.request.reasoningBudget == nil,
mtp?.config.promptExceedsDraftLimit(rec.request.promptTokens.count) != true,
constraintEligible,
samplingEligible,
sampling.topLogprobs == 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,18 @@ public struct CBv2MTPConfig: Sendable {
/// measuring it; `DARKBLOOM_CBV2_MTP_COST_CURVE=0` turns it off. No value
/// turns it on for a family that has not opted in. Tokens are unaffected.
public var costCurveDepthSelection: Bool
/// Optional prompt-length gate: a request whose prompt holds more than
/// this many tokens never drafts and keeps no assistant history for its
/// whole lifetime, as a reasoning budget does; it decodes as ordinary
/// target-only rows, so its tokens are the MTP-off engine's. nil (the
/// default) or a value below one lets every prompt length draft.
public var maxDraftPromptTokens: Int?
/// Whether a prompt of `promptTokens` tokens is over `maxDraftPromptTokens`
/// (never when the limit is nil or below one).
public func promptExceedsDraftLimit(_ promptTokens: Int) -> Bool {
guard let limit = maxDraftPromptTokens, limit > 0 else { return false }
return promptTokens > limit
}
/// False for `DARKBLOOM_MTP_STOP_STRING_ROWS=0/false/no/off`; read once.
public static let envStopStringSpeculation = envSwitch("DARKBLOOM_MTP_STOP_STRING_ROWS")
/// The opt-in AND the process kill switch.
Expand Down Expand Up @@ -680,7 +692,8 @@ public struct CBv2MTPConfig: Sendable {
penaltySpeculation: Bool = false,
stopStringSpeculation: Bool = false,
costCurveDepthSelection: Bool = false,
speculativeBatchLimit: Int = Self.testedMaxSpeculativeBatch
speculativeBatchLimit: Int = Self.testedMaxSpeculativeBatch,
maxDraftPromptTokens: Int? = nil
) {
self.enabled = enabled
self.allowsAdaptiveSerialRounds = allowsAdaptiveSerialRounds
Expand All @@ -692,6 +705,7 @@ public struct CBv2MTPConfig: Sendable {
self.penaltySpeculation = penaltySpeculation
self.stopStringSpeculation = stopStringSpeculation
self.costCurveDepthSelection = costCurveDepthSelection
self.maxDraftPromptTokens = maxDraftPromptTokens.flatMap { $0 > 0 ? $0 : nil }
let resolvedMax = min(max(maxDraftTokens, 0), Self.testedMaxDraftTokens)
self.maxDraftTokens = resolvedMax
// A family raises its limit only after measuring that wider rounds pay.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ public final class CBv2CompleteCheckpointImportPlan: @unchecked Sendable {
CBv2CheckpointAllocationFootprint.add(
max(initializationScratch, pageInitializationScratch), paged?.nativeRecentBytes ?? 0
),
codec.checkpointQuantization == nil ? 0 : CBv2NativeCheckpointRowCodec.scratchBytes)
codec.checkpointQuantization == nil
? 0
: CBv2NativeCheckpointRowCodec.scratchBytes
+ CBv2NativeCheckpointRowDecoder.scratchBytes(
workers: CBv2NativeCheckpointRowDecoder.defaultWorkers))
let totalTarget = try CBv2CheckpointAllocationFootprint.add(
target, paged?.pageNativeBytes ?? 0)
nativeTargetBytes = totalTarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ final class CBv2NativeCompleteCheckpointImportOwner: @unchecked Sendable {
self.codecOwner = codecOwner
self.reservation = reservation
self.evaluate = evaluate
quantizedDecoder = plan.manifest.usesLossyNativeCheckpoint ? .init() : nil
quantizedDecoder = plan.manifest.usesLossyNativeCheckpoint ? .forImport() : nil
}

func allocate(work: CBv2NativeCompletePrefixWork) throws {
Expand Down Expand Up @@ -383,11 +383,14 @@ public final class CBv2CompleteCheckpointImport: @unchecked Sendable {
self.plan = plan
self.reservation = reservation
self.stageLease = stageLease
quantizedDecoder = plan.manifest.usesLossyNativeCheckpoint ? .init() : nil
quantizedDecoder = plan.manifest.usesLossyNativeCheckpoint ? .forImport() : nil
if let storagePlan = plan.pagedStoragePlan {
pagedStorage = try CBv2PagedCheckpointStorage(
plan: storagePlan, evaluate: { try plan.evaluateDestinations([$0]) },
admission: plan.codec.admission, hostMaterialized: true)
admission: plan.codec.admission, hostMaterialized: true,
// As the live pool's growth (`hostZeroedSegments`): staged
// segments wrap zero-fill-on-demand pages instead of copying zeros.
hostZeroed: plan.codec.pagedConfig?.hostZeroedSegments == true)
}
let destinationDescriptors =
plan.pagedStoragePlan == nil
Expand Down
Loading
Loading