diff --git a/doc/testing_matrix.md b/doc/testing_matrix.md index 9308a0e73..fa938a668 100644 --- a/doc/testing_matrix.md +++ b/doc/testing_matrix.md @@ -777,8 +777,9 @@ audio bytes. `gemma4-mtp-smoke` takes the Gemma 4 GGUF and its external drafter via `--draft-model-path`. Inspect the JSON for plain output and either MTP output -or an MTP error. The command can exit successfully after reporting an MTP -error, so use it for manual inspection. For MTP and n-gram performance +or an MTP error. Omit the drafter path for a target with embedded MTP. +The smoke exits nonzero with a typed JSON error when the MTP turn fails +or the drafter runs and proposes zero tokens. For MTP and n-gram performance numbers, use `llama-cpp-speculative-benchmark` with `--speculative-cases draft-mtp,ngram-simple`, which supersedes the older env-var-driven benchmark script. Like every `local-only` row, neither runs in CI. diff --git a/test/unit/backends/llama_cpp/library_probe_call_sites_test.dart b/test/unit/backends/llama_cpp/library_probe_call_sites_test.dart index 12aac408b..60551e22b 100644 --- a/test/unit/backends/llama_cpp/library_probe_call_sites_test.dart +++ b/test/unit/backends/llama_cpp/library_probe_call_sites_test.dart @@ -604,14 +604,20 @@ void main() { expect( () => _invoke(service, '_resolveSpeculativeApi', const []), throwsA( - isA().having( - (error) => error.message, - 'message', - 'llama.cpp speculative decoding is unavailable in this native ' - 'runtime bundle (missing llama_dart_speculative_* wrapper ' - 'symbols). Use the package-pinned native runtime or an ' - 'ABI-compatible build.', - ), + isA() + .having( + (error) => error.runtimeType, + 'runtimeType', + LlamaUnsupportedException, + ) + .having( + (error) => error.message, + 'message', + 'llama.cpp speculative decoding is unavailable in this native ' + 'runtime bundle (missing llama_dart_speculative_* wrapper ' + 'symbols). Use the package-pinned native runtime or an ' + 'ABI-compatible build.', + ), ), ); }); diff --git a/test/unit/backends/llama_cpp/llama_cpp_backend_test.dart b/test/unit/backends/llama_cpp/llama_cpp_backend_test.dart index 6e9b2ea43..9089057dd 100644 --- a/test/unit/backends/llama_cpp/llama_cpp_backend_test.dart +++ b/test/unit/backends/llama_cpp/llama_cpp_backend_test.dart @@ -1899,11 +1899,15 @@ void main() { throwsA( allOf( isA(), - isA().having( - (error) => error.strategies, - 'strategies', - [strategy], - ), + isA() + .having( + (error) => error.runtimeType, + 'runtimeType', + LlamaSpeculativeDecodingUnsupportedException, + ) + .having((error) => error.strategies, 'strategies', [ + strategy, + ]), ), ), ); diff --git a/test/unit/backends/llama_cpp/llama_cpp_service_test.dart b/test/unit/backends/llama_cpp/llama_cpp_service_test.dart index 4a17387e0..f3f09c482 100644 --- a/test/unit/backends/llama_cpp/llama_cpp_service_test.dart +++ b/test/unit/backends/llama_cpp/llama_cpp_service_test.dart @@ -1379,7 +1379,13 @@ void main() { speculativeDecodingConfig: SpeculativeDecodingConfig.ngramMod(), ), ), - throwsA(isA()), + throwsA( + isA().having( + (error) => error.runtimeType, + 'runtimeType', + LlamaUnsupportedException, + ), + ), ); }); @@ -1621,11 +1627,17 @@ void main() { const ModelParams(), ), throwsA( - isA().having( - (error) => error.message, - 'message', - contains('ModelParams(loadMtp: true)'), - ), + isA() + .having( + (error) => error.runtimeType, + 'runtimeType', + LlamaUnsupportedException, + ) + .having( + (error) => error.message, + 'message', + contains('ModelParams(loadMtp: true)'), + ), ), ); expect( diff --git a/test/unit/backends/llama_cpp/llama_cpp_service_token_logprobs_test.dart b/test/unit/backends/llama_cpp/llama_cpp_service_token_logprobs_test.dart index 63e3ff058..ae2d83410 100644 --- a/test/unit/backends/llama_cpp/llama_cpp_service_token_logprobs_test.dart +++ b/test/unit/backends/llama_cpp/llama_cpp_service_token_logprobs_test.dart @@ -296,11 +296,17 @@ void main() { ), ), throwsA( - isA().having( - (e) => e.message, - 'message', - allOf(contains('topLogprobs'), contains('speculative')), - ), + isA() + .having( + (error) => error.runtimeType, + 'runtimeType', + LlamaUnsupportedException, + ) + .having( + (e) => e.message, + 'message', + allOf(contains('topLogprobs'), contains('speculative')), + ), ), ); }); diff --git a/test/unit/tooling/gemma4_mtp_smoke_test.dart b/test/unit/tooling/gemma4_mtp_smoke_test.dart index df6e4a099..43547b696 100644 --- a/test/unit/tooling/gemma4_mtp_smoke_test.dart +++ b/test/unit/tooling/gemma4_mtp_smoke_test.dart @@ -36,6 +36,48 @@ void main() { }); } + for (final (attempts, proposals, expectedCode) in [ + (1, 0, 1), + (0, 0, 0), + (1, 2, 0), + ]) { + test( + 'MTP exits $expectedCode after $attempts attempts and $proposals proposals', + () async { + final engine = _SmokeEngine( + perf: BackendPerfContextData( + loadMs: 0, + promptEvalMs: 0, + evalMs: 0, + sampleMs: 0, + promptEvalTokens: 0, + evalTokens: 0, + sampleCount: 0, + reusedGraphs: 0, + speculativeDraftAttempts: attempts, + speculativeDraftTokens: proposals, + speculativeAcceptedDraftTokens: 0, + ), + ); + final (code, report) = await _runSmoke([ + 'target.gguf', + 'draft.gguf', + ], engine); + + expect(code, expectedCode); + final mtp = report['mtp'] as Map; + expect(mtp['perf'], containsPair('speculativeDraftTokens', proposals)); + if (expectedCode == 1) { + expect(mtp['errorType'], 'NoDraftTokensProposed'); + expect(mtp['error'], contains('proposed zero tokens')); + } else { + expect(mtp, isNot(contains('errorType'))); + } + expect(engine.disposed, isTrue); + }, + ); + } + test('reports a typed MTP error and exits nonzero', () async { final engine = _SmokeEngine(failMtp: true); final (code, report) = await _runSmoke(['target.gguf'], engine); @@ -69,7 +111,9 @@ Future<(int, Map)> _runSmoke( } class _SmokeEngine implements LlamaEngine { - _SmokeEngine({this.failMtp = false}); + _SmokeEngine({this.failMtp = false, this.perf}); + + final BackendPerfContextData? perf; final bool failMtp; late ModelParams modelParams; @@ -93,7 +137,8 @@ class _SmokeEngine implements LlamaEngine { } @override - Future getPerformanceContext() async => null; + Future getPerformanceContext() async => + turns.last == null ? null : perf; @override Stream create( diff --git a/tool/testing/gemma4_mtp_smoke.dart b/tool/testing/gemma4_mtp_smoke.dart index 36b99fe30..772be1f26 100644 --- a/tool/testing/gemma4_mtp_smoke.dart +++ b/tool/testing/gemma4_mtp_smoke.dart @@ -67,7 +67,6 @@ Future runGemma4MtpSmoke( ), ); - var result = 0; Map mtp; try { mtp = await _run( @@ -87,7 +86,6 @@ Future runGemma4MtpSmoke( ), ); } catch (error, stackTrace) { - result = 1; mtp = { 'error': error.toString(), 'errorType': error.runtimeType.toString(), @@ -106,7 +104,7 @@ Future runGemma4MtpSmoke( 'mtp': mtp, }), ); - return result; + return mtp.containsKey('errorType') ? 1 : 0; } finally { await engine.dispose(); } @@ -138,7 +136,15 @@ Future> _run( final text = output.toString(); final perf = await engine.getPerformanceContext(); + final noDraftTokensProposed = + params.isSpeculativeDecodingEnabled && + (perf?.speculativeDraftAttempts ?? 0) > 0 && + perf?.speculativeDraftTokens == 0; return { + if (noDraftTokensProposed) ...{ + 'errorType': 'NoDraftTokensProposed', + 'error': 'The MTP drafter ran but proposed zero tokens.', + }, 'elapsedMs': stopwatch.elapsedMilliseconds, 'firstTokenLatencyMs': firstTokenLatencyMs, 'outputChars': text.length, diff --git a/tool/testing/test_matrix.dart b/tool/testing/test_matrix.dart index 15c4719ad..2d414a20f 100644 --- a/tool/testing/test_matrix.dart +++ b/tool/testing/test_matrix.dart @@ -563,7 +563,8 @@ const List testMatrixRows = [ '--benchmark-max-tokens 32 --draft-token-max 1', useWhen: 'Omit --draft-model-path for a target with embedded MTP. The smoke ' - 'exits nonzero and reports the error in JSON if the MTP turn fails. ' + 'exits nonzero and reports a typed JSON error if the MTP turn fails ' + 'or the drafter runs and proposes zero tokens. ' 'Run locally before the llama-cpp-speculative-benchmark row.', ), TestMatrixRow( diff --git a/website/docs/guides/performance-tuning.md b/website/docs/guides/performance-tuning.md index 1517f44c8..bbf5e7d2e 100644 --- a/website/docs/guides/performance-tuning.md +++ b/website/docs/guides/performance-tuning.md @@ -184,7 +184,8 @@ chain then selects and accepts the token, preserving greedy output and seeded sampling. The benefit depends on how often the model's shortlist passes. Older runtimes and requests with lazy grammar, a thinking budget, DRY, -top-n-sigma, Mirostat or requested token logprobs keep their existing paths. +top-n-sigma, Mirostat, requested token logprobs, or speculative decoding keep +their existing paths. ## Speculative decoding