Expose LiteRT-LM speculative decoding through GenerationParams#191
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR exposes LiteRT-LM native speculative decoding through GenerationParams while keeping unsupported backends explicit and documenting benchmark guidance/results.
Changes:
- Adds
GenerationParams.speculativeDecodingand forwards it to native LiteRT-LM runtime initialization. - Rejects speculative decoding for llama.cpp, WebGPU, and LiteRT-LM web with tests.
- Updates benchmark tooling/app metrics and documentation for LiteRT-LM speculative decoding comparisons.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
lib/src/core/models/inference/generation_params.dart |
Adds the public speculative decoding flag and copy support. |
lib/src/backends/litert_lm/litert_lm_service.dart |
Tracks and forwards speculative decoding to native LiteRT-LM runtime settings. |
lib/src/backends/litert_lm/litert_lm_backend_web.dart |
Rejects speculative decoding on LiteRT-LM web. |
lib/src/backends/llama_cpp/llama_cpp_service.dart |
Rejects speculative decoding for llama.cpp. |
lib/src/backends/webgpu/webgpu_backend.dart |
Rejects speculative decoding for WebGPU. |
example/chat_app/lib/litert_lm_benchmark_app.dart |
Wires the benchmark toggle into generation and records it in metrics. |
tool/macos_fair_litert_vs_llamadart.sh |
Adds a SPECULATIVE env toggle for macOS LiteRT-LM benchmarks. |
test/unit/core/models/inference/generation_params_test.dart |
Covers default and copy behavior for the new parameter. |
test/unit/backends/litert_lm/litert_lm_service_test.dart |
Verifies native LiteRT-LM default/off and opt-in/on forwarding. |
test/unit/backends/litert_lm/litert_lm_backend_web_test.dart |
Covers LiteRT-LM web rejection. |
test/unit/backends/llama_cpp/llama_cpp_service_test.dart |
Covers llama.cpp rejection. |
test/unit/backends/webgpu/webgpu_backend_test.dart |
Covers WebGPU rejection. |
README.md |
Documents LiteRT-LM support and unsupported speculative decoding paths. |
CHANGELOG.md |
Records the new speculative decoding opt-in behavior. |
website/docs/configuration/runtime-parameters.md |
Documents the new GenerationParams field. |
website/docs/guides/backend-selection.md |
Adds native LiteRT-LM support guidance and benchmark caveats. |
website/docs/guides/backend-benchmarks.md |
Adds measured speculative decoding benchmark results and commands. |
website/docs/guides/performance-tuning.md |
Adds tuning guidance and benchmark commands. |
website/docs/platforms/support-matrix.md |
Updates LiteRT-LM platform support notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #191 +/- ##
==========================================
+ Coverage 80.55% 80.57% +0.02%
==========================================
Files 85 85
Lines 11380 11392 +12
==========================================
+ Hits 9167 9179 +12
Misses 2213 2213
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refs #188.
This exposes LiteRT-LM speculative decoding as an opt-in
GenerationParams.speculativeDecodingflag and wires it through the native LiteRT-LM runtime settings. The default remains disabled.Scope
GenerationParams.speculativeDecodingwith defaultfalseand copy support.Benchmark Notes
The flag is exposed as a tuning knob, not enabled as a default optimization. In measured Gemma 4 E2B runs it was slower:
false15.50 wall tok/s,true9.06 wall tok/s, about 42% slower.false135.02 wall tok/s,true118.96 wall tok/s, about 12% slower.The Pixel NPU path was attempted for
gemma-4-E2B-it.litertlm, but native LiteRT-LM failed engine creation for backendnpuon this device/model bundle, so there is no NPU performance claim in this PR.Validation
dart format --output=none --set-exit-if-changed .dart analyzedart test -p vm test/unit/core/models/inference/generation_params_test.dart test/unit/backends/litert_lm/litert_lm_service_test.dart test/unit/backends/llama_cpp/llama_cpp_service_test.dartdart test -p chrome test/unit/backends/litert_lm/litert_lm_backend_web_test.dart test/unit/backends/webgpu/webgpu_backend_test.dartbash -n tool/macos_fair_litert_vs_llamadart.sh tool/litert_lm_pixel_benchmark.sh./tool/docs/validate_links.shgit diff --check