Skip to content
Merged
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
33 changes: 18 additions & 15 deletions Libraries/MLXGuidedGeneration/GuidedGenerationLoop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,16 @@ public enum GuidedGenerationLoop {
}
tokenCount += 1

// Periodic progress logging (once per main loop iteration, not per FF token)
if tokenCount % 50 == 0 {
let elapsed = clock.now - startInstant
let ms =
elapsed.components.seconds * 1000 + elapsed.components.attoseconds
/ 1_000_000_000_000_000
let prefix = String(accumulatedText.prefix(200))
logger.info("[GuidedGen] token=\(tokenCount) elapsed=\(ms)ms text=\(prefix)")
if diagnosticLog {
// Periodic progress logging (once per main loop iteration, not per FF token)
if tokenCount % 50 == 0 {
let elapsed = clock.now - startInstant
let ms =
elapsed.components.seconds * 1000 + elapsed.components.attoseconds
/ 1_000_000_000_000_000
let prefix = String(accumulatedText.prefix(200))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This accumulated text is only ever consumed here. Perhaps the collection (above, outside this change) should be gated on diagnosticLog being true. That doesn't block merge -- it was this way before, but logger.info is probably true by default.

logger.info("[GuidedGen] token=\(tokenCount) elapsed=\(ms)ms text=\(prefix)")
}
}

if commitResult.isTerminated {
Expand Down Expand Up @@ -454,13 +456,14 @@ public enum GuidedGenerationLoop {
_ = emit(text)
}

// Log final generation stats
let totalElapsed = clock.now - startInstant
let totalMs =
totalElapsed.components.seconds * 1000 + totalElapsed.components.attoseconds
/ 1_000_000_000_000_000
logger.info("[GuidedGen] done tokens=\(tokenCount) elapsed=\(totalMs)ms")

if diagnosticLog {
// Log final generation stats
let totalElapsed = clock.now - startInstant
let totalMs =
totalElapsed.components.seconds * 1000 + totalElapsed.components.attoseconds
/ 1_000_000_000_000_000
logger.info("[GuidedGen] done tokens=\(tokenCount) elapsed=\(totalMs)ms")
}
// Flush any xgrammar warnings (limit exceedances, parser state)
if diagnosticLog, let logs = constraint.flushLogs() {
logger.warning("[GuidedGen] xgrammar logs:\n\(logs)")
Expand Down
Loading