diff --git a/Libraries/MLXGuidedGeneration/GuidedGenerationLoop.swift b/Libraries/MLXGuidedGeneration/GuidedGenerationLoop.swift index 2802733bf0..10a010b834 100644 --- a/Libraries/MLXGuidedGeneration/GuidedGenerationLoop.swift +++ b/Libraries/MLXGuidedGeneration/GuidedGenerationLoop.swift @@ -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)) + logger.info("[GuidedGen] token=\(tokenCount) elapsed=\(ms)ms text=\(prefix)") + } } if commitResult.isTerminated { @@ -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)")