Skip to content

feat(llm-llamacpp): add MTP self-speculative decoding - #4390

Open
dev-nid wants to merge 51 commits into
mainfrom
pr-2938-mtp-llamacpp
Open

dev-nid wants to merge 51 commits into
mainfrom
pr-2938-mtp-llamacpp

Conversation

@dev-nid

@dev-nid dev-nid commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

  • Adds MTP draft-mtp self-speculative decoding support to @qvac/llm-llamacpp.
  • Moves the work from external draft PR [DRAFT] QVAC b9840 MTP  #2938 to an internal branch so the full C++, desktop, and mobile CI suite can run.
  • Supersedes [DRAFT] QVAC b9840 MTP  #2938 while preserving the original commit authorship.

How does it solve it?

  • Adds a shared draft, verify, and accept loop used by text and multimodal contexts.
  • Keeps target and draft contexts synchronized across reset, token removal, and cache loading.
  • Persists the target KV, draft KV, and MTP driver state as one generation.
  • Bounds draft sizes and validates speculative-decoding configuration.
  • Handles cancellation, stop tokens, EOS reasoning recovery, context exhaustion, and mid-generation speculation fallback.
  • Rejects unsupported context shifting and ignores other speculative decoder types with a warning.
  • Adds draftAccepted and draftTotal runtime statistics.
  • Avoids unnecessary per-token logits during prefill and reuses the multimodal prefill batch.
  • Preserves comparable prompt and generation timing for speculative runs.
  • Adds text, multimodal, cache, context-boundary, configuration, and reasoning-recovery coverage.
  • Stages the MTP model for mobile Device Farm tests.

The MTP driver-state support and position-aware fresh-sequence guard are in qvac-fabric PR #269, including commit 9b14d8473. The pending MTP row is serialized with its target position and is only reused when the next batch starts at the consecutive position. Invalid state blobs are ignored without overwriting valid pending state.

This qvac branch carries a temporary fabric overlay so the addon and fabric changes can be validated together. The overlay is pinned to PR #269 directly, with no qvac-local fabric patch. It will be removed and replaced with the published fabric baseline after PR #269 lands.

Why are workflow and overlay changes included?

The Embed integration workflow downloaded an artifact named prebuilds, but the reusable prebuild workflow publishes prebuilds-embed-llamacpp. The job therefore failed before any integration test started. The workflow file is repository code, so the artifact name must be fixed in this PR for the tests to run.

The automatic PR workflow uses the reusable workflow from main, so it still runs the old artifact name and cannot validate a workflow change from the PR branch. A manual dispatch from this branch used the corrected workflow and passed all seven platform jobs.

The addon cache restore also depends on the MTP driver-state API from fabric PR #269. Registry fabric does not contain that API yet, so the temporary overlay lets CI build the qvac and fabric changes together. This validates the integration before fabric is published. The overlay is not the final dependency update and will be removed after PR #269 lands.

Benchmark results:

  • Apple M4 Metal: tuned MTP achieved approximately 1.13x to 1.21x TPS.
  • Linux Vulkan with the 27B model: default MTP achieved approximately 1.80x to 2.15x TPS.

Validation

  • Full native build passes.
  • Text MTP integration tests: 45/45 assertions pass.
  • Multimodal MTP integration tests: 21/21 assertions pass.
  • Invalid speculative configuration is rejected.
  • Fabric MTP shared CPU and Metal regression tests pass locally.
  • Fabric overlay policy tests: 61/61 pass.
  • clang-format and clang-tidy pass.
  • git diff --check passes.
  • The manually dispatched Embed workflow passed all seven platform jobs: run.

Mobile Device Farm runs

Pinned to a dev build of this branch because an unpinned dispatch installs the published @latest, which has no MTP.

  • Build: @tetherto/llm-llamacpp-mono@0.52.0-tmp.runid-34784321981 from tmp-mtp-llamacpp-4390 at edfbe3c2e via publish run
  • Android: Pixel 9, 8/8 shards, 24/24 tests via run
  • iOS: iPhone 17, 13/14 shards, 41/42 tests via run
  • The mtp shard with runMtpTest and runMtpMtmdTest passed on both platforms.

The one iOS failure is runGemma4Test, which does not use MTP. The app crashes while loading the Gemma 4 f16 mmproj in Gemma 4 multimodal honours remove_thinking_from_context. It reproduces identically on the published @qvac/llm-llamacpp@0.52.0 with none of this branch's code in the control run, and reproduces across three runs.

Breaking changes

None. MTP is opt-in through spec-type=draft-mtp. Unsupported models fall back to normal decoding, and the new statistics fields are additive.

Known limitations

  • MTP is supported only with parallel=1. When continuous batching is enabled, the addon logs a warning and falls back to non-speculative decoding. Fabric's llama-server supports MTP with continuous batching, but the addon's scheduler does not yet manage the required per-slot speculative state. Scheduler integration is deferred to a follow-up change.
  • Actual image turns currently run non-speculatively because image embeddings are not mirrored into the draft context. Separate MTP-head model-file support is deferred to QVAC-25040.

@dev-nid
dev-nid requested review from a team as code owners September 10, 2026 13:29
@github-actions

Copy link
Copy Markdown
Contributor

Review Status

Current Status: ❌ PENDING
Approvals so far: none

Pending reviews: Needs 1 Management or Team Lead, and 1 more from Management, Team Lead, or Member.

@github-actions

Copy link
Copy Markdown
Contributor

License compliance — clean

No new dependency license findings in this PR.

Warn-only (shadow) mode — this check does not block merges yet.

Updated automatically by the canonical license compliance workflow.

NOTICE presence (advisory)

Missing NOTICE (advisory, does not block):

  • ./docs/website
  • ./packages/fabric/test/integration
  • ./packages/llm-llamacpp/benchmarks/server
  • ./packages/llm-llamacpp/benchmarks/performance
  • ./packages/inference-addon-cpp/mobile
  • ./packages/asr-ggml/benchmarks/server
  • ./packages/embed-llamacpp/benchmarks/server
  • ./packages/embed-llamacpp/benchmarks/performance
  • ./packages/sdk/e2e
  • ./packages/vla-ggml/sim/server
  • ./.github/actions/release-merge-guard

@dev-nid dev-nid added run-cpp-addon-tests CI: run C++ addon tests (requires verified) run-desktop-addon-tests CI: run desktop integration tests (requires verified) labels Sep 10, 2026
@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Workflow security (shadow mode)

zizmor found 1103 finding(s) in .github/ (highest severity: high). This check is warn-only and does not block the merge.

Findings are annotated inline on the changed files and listed in the job summary.

Reproduce locally:

pipx run zizmor==1.27.0 --offline .github/

@github-actions

Copy link
Copy Markdown
Contributor

🧪 C++ Test Coverage Report

Coverage:

📊 Detailed Coverage
Filename                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NmtLazyInitializeBackend.cpp          99                19    80.81%          11                 1    90.91%         157                34    78.34%          66                20    69.70%
NmtLazyInitializeBackend.hpp           2                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
TranslationModel.cpp                 296               168    43.24%          28                 8    71.43%         506               213    57.91%         181               122    32.60%
TranslationModel.hpp                   1                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
nmt.cpp                               72                22    69.44%           9                 1    88.89%         137                28    79.56%          44                16    63.64%
nmt.hpp                               51                 4    92.16%          11                 2    81.82%          53                 4    92.45%          28                 0   100.00%
nmt_beam_search.cpp                  116                25    78.45%          10                 3    70.00%         254                32    87.40%          76                19    75.00%
nmt_graph_decoder.cpp                164                78    52.44%          15                 7    53.33%         540               161    70.19%         112                69    38.39%
nmt_graph_encoder.cpp                 54                13    75.93%           3                 0   100.00%         268                33    87.69%          37                16    56.76%
nmt_loader.cpp                       270                67    75.19%          14                 0   100.00%         774                97    87.47%         161                67    58.39%
nmt_state_backend.cpp                188                46    75.53%          20                 0   100.00%         424                79    81.37%         121                51    57.85%
nmt_tokenization.cpp                  88                21    76.14%           8                 0   100.00%         135                36    73.33%          61                26    57.38%
nmt_utils.cpp                        211                34    83.89%          21                 0   100.00%         314                38    87.90%         143                45    68.53%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               1612               497    69.17%         152                22    85.53%        3564               755    78.82%        1030               451    56.21%

@github-actions

Copy link
Copy Markdown
Contributor

🧪 C++ Test Coverage Report

Coverage:

📊 Detailed Coverage
Filename                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NmtLazyInitializeBackend.cpp          99                19    80.81%          11                 1    90.91%         157                34    78.34%          66                20    69.70%
NmtLazyInitializeBackend.hpp           2                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
TranslationModel.cpp                 296               168    43.24%          28                 8    71.43%         506               213    57.91%         181               122    32.60%
TranslationModel.hpp                   1                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
nmt.cpp                               72                22    69.44%           9                 1    88.89%         137                28    79.56%          44                16    63.64%
nmt.hpp                               51                 4    92.16%          11                 2    81.82%          53                 4    92.45%          28                 0   100.00%
nmt_beam_search.cpp                  116                25    78.45%          10                 3    70.00%         254                32    87.40%          76                19    75.00%
nmt_graph_decoder.cpp                164                78    52.44%          15                 7    53.33%         540               161    70.19%         112                69    38.39%
nmt_graph_encoder.cpp                 54                13    75.93%           3                 0   100.00%         268                33    87.69%          37                16    56.76%
nmt_loader.cpp                       270                67    75.19%          14                 0   100.00%         774                97    87.47%         161                67    58.39%
nmt_state_backend.cpp                188                46    75.53%          20                 0   100.00%         424                79    81.37%         121                51    57.85%
nmt_tokenization.cpp                  88                21    76.14%           8                 0   100.00%         135                36    73.33%          61                26    57.38%
nmt_utils.cpp                        211                34    83.89%          21                 0   100.00%         314                38    87.90%         143                45    68.53%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               1612               497    69.17%         152                22    85.53%        3564               755    78.82%        1030               451    56.21%

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

🧪 C++ Test Coverage Report

Coverage:

📊 Detailed Coverage
Filename                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NmtLazyInitializeBackend.cpp          99                19    80.81%          11                 1    90.91%         157                34    78.34%          66                20    69.70%
NmtLazyInitializeBackend.hpp           2                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
TranslationModel.cpp                 296               168    43.24%          28                 8    71.43%         506               213    57.91%         181               122    32.60%
TranslationModel.hpp                   1                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
nmt.cpp                               72                22    69.44%           9                 1    88.89%         137                28    79.56%          44                16    63.64%
nmt.hpp                               51                 4    92.16%          11                 2    81.82%          53                 4    92.45%          28                 0   100.00%
nmt_beam_search.cpp                  116                25    78.45%          10                 3    70.00%         254                32    87.40%          76                19    75.00%
nmt_graph_decoder.cpp                164                78    52.44%          15                 7    53.33%         540               161    70.19%         112                69    38.39%
nmt_graph_encoder.cpp                 54                13    75.93%           3                 0   100.00%         268                33    87.69%          37                16    56.76%
nmt_loader.cpp                       270                67    75.19%          14                 0   100.00%         774                97    87.47%         161                67    58.39%
nmt_state_backend.cpp                188                46    75.53%          20                 0   100.00%         424                79    81.37%         121                51    57.85%
nmt_tokenization.cpp                  88                21    76.14%           8                 0   100.00%         135                36    73.33%          61                26    57.38%
nmt_utils.cpp                        211                34    83.89%          21                 0   100.00%         314                38    87.90%         143                45    68.53%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               1612               497    69.17%         152                22    85.53%        3564               755    78.82%        1030               451    56.21%

Signed-off-by: Ridwan Taiwo <donriddo@gmail.com>
Signed-off-by: Ridwan Taiwo <donriddo@gmail.com>
Signed-off-by: Ridwan Taiwo <donriddo@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

🧪 C++ Test Coverage Report

Coverage:

📊 Detailed Coverage
Filename                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NmtLazyInitializeBackend.cpp          99                99     0.00%          11                11     0.00%         157               157     0.00%          66                66     0.00%
NmtLazyInitializeBackend.hpp           2                 2     0.00%           1                 1     0.00%           1                 1     0.00%           0                 0         -
TranslationModel.cpp                 296               296     0.00%          28                28     0.00%         506               506     0.00%         181               181     0.00%
TranslationModel.hpp                   1                 1     0.00%           1                 1     0.00%           1                 1     0.00%           0                 0         -
nmt.cpp                               72                72     0.00%           9                 9     0.00%         137               137     0.00%          44                44     0.00%
nmt.hpp                               51                51     0.00%          11                11     0.00%          53                53     0.00%          28                28     0.00%
nmt_beam_search.cpp                  116               116     0.00%          10                10     0.00%         254               254     0.00%          76                76     0.00%
nmt_graph_decoder.cpp                164               164     0.00%          15                15     0.00%         540               540     0.00%         112               112     0.00%
nmt_graph_encoder.cpp                 54                54     0.00%           3                 3     0.00%         268               268     0.00%          37                37     0.00%
nmt_loader.cpp                       270               270     0.00%          14                14     0.00%         774               774     0.00%         161               161     0.00%
nmt_state_backend.cpp                188               188     0.00%          20                20     0.00%         424               424     0.00%         121               121     0.00%
nmt_tokenization.cpp                  88                88     0.00%           8                 8     0.00%         135               135     0.00%          61                61     0.00%
nmt_utils.cpp                        211               211     0.00%          21                21     0.00%         314               314     0.00%         143               143     0.00%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               1612              1612     0.00%         152               152     0.00%        3564              3564     0.00%        1030              1030     0.00%

@github-actions

Copy link
Copy Markdown
Contributor

🧪 C++ Test Coverage Report

Coverage:

📊 Detailed Coverage
Filename                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NmtLazyInitializeBackend.cpp          99                19    80.81%          11                 1    90.91%         157                34    78.34%          66                20    69.70%
NmtLazyInitializeBackend.hpp           2                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
TranslationModel.cpp                 296               168    43.24%          28                 8    71.43%         506               213    57.91%         181               122    32.60%
TranslationModel.hpp                   1                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
nmt.cpp                               72                22    69.44%           9                 1    88.89%         137                28    79.56%          44                16    63.64%
nmt.hpp                               51                 4    92.16%          11                 2    81.82%          53                 4    92.45%          28                 0   100.00%
nmt_beam_search.cpp                  116                25    78.45%          10                 3    70.00%         254                32    87.40%          76                19    75.00%
nmt_graph_decoder.cpp                164                78    52.44%          15                 7    53.33%         540               161    70.19%         112                69    38.39%
nmt_graph_encoder.cpp                 54                13    75.93%           3                 0   100.00%         268                33    87.69%          37                16    56.76%
nmt_loader.cpp                       270                67    75.19%          14                 0   100.00%         774                97    87.47%         161                67    58.39%
nmt_state_backend.cpp                188                46    75.53%          20                 0   100.00%         424                79    81.37%         121                51    57.85%
nmt_tokenization.cpp                  88                21    76.14%           8                 0   100.00%         135                36    73.33%          61                26    57.38%
nmt_utils.cpp                        211                34    83.89%          21                 0   100.00%         314                38    87.90%         143                45    68.53%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               1612               497    69.17%         152                22    85.53%        3564               755    78.82%        1030               451    56.21%

@github-actions

Copy link
Copy Markdown
Contributor

🧪 C++ Test Coverage Report

Coverage:

📊 Detailed Coverage
Filename                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NmtLazyInitializeBackend.cpp          99                99     0.00%          11                11     0.00%         157               157     0.00%          66                66     0.00%
NmtLazyInitializeBackend.hpp           2                 2     0.00%           1                 1     0.00%           1                 1     0.00%           0                 0         -
TranslationModel.cpp                 296               296     0.00%          28                28     0.00%         506               506     0.00%         181               181     0.00%
TranslationModel.hpp                   1                 1     0.00%           1                 1     0.00%           1                 1     0.00%           0                 0         -
nmt.cpp                               72                72     0.00%           9                 9     0.00%         137               137     0.00%          44                44     0.00%
nmt.hpp                               51                51     0.00%          11                11     0.00%          53                53     0.00%          28                28     0.00%
nmt_beam_search.cpp                  116               116     0.00%          10                10     0.00%         254               254     0.00%          76                76     0.00%
nmt_graph_decoder.cpp                164               164     0.00%          15                15     0.00%         540               540     0.00%         112               112     0.00%
nmt_graph_encoder.cpp                 54                54     0.00%           3                 3     0.00%         268               268     0.00%          37                37     0.00%
nmt_loader.cpp                       270               270     0.00%          14                14     0.00%         774               774     0.00%         161               161     0.00%
nmt_state_backend.cpp                188               188     0.00%          20                20     0.00%         424               424     0.00%         121               121     0.00%
nmt_tokenization.cpp                  88                88     0.00%           8                 8     0.00%         135               135     0.00%          61                61     0.00%
nmt_utils.cpp                        211               211     0.00%          21                21     0.00%         314               314     0.00%         143               143     0.00%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               1612              1612     0.00%         152               152     0.00%        3564              3564     0.00%        1030              1030     0.00%

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

🧪 C++ Test Coverage Report

Coverage:

📊 Detailed Coverage
Filename                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NmtLazyInitializeBackend.cpp          99                99     0.00%          11                11     0.00%         157               157     0.00%          66                66     0.00%
NmtLazyInitializeBackend.hpp           2                 2     0.00%           1                 1     0.00%           1                 1     0.00%           0                 0         -
TranslationModel.cpp                 296               296     0.00%          28                28     0.00%         506               506     0.00%         181               181     0.00%
TranslationModel.hpp                   1                 1     0.00%           1                 1     0.00%           1                 1     0.00%           0                 0         -
nmt.cpp                               72                72     0.00%           9                 9     0.00%         137               137     0.00%          44                44     0.00%
nmt.hpp                               51                51     0.00%          11                11     0.00%          53                53     0.00%          28                28     0.00%
nmt_beam_search.cpp                  116               116     0.00%          10                10     0.00%         254               254     0.00%          76                76     0.00%
nmt_graph_decoder.cpp                164               164     0.00%          15                15     0.00%         540               540     0.00%         112               112     0.00%
nmt_graph_encoder.cpp                 54                54     0.00%           3                 3     0.00%         268               268     0.00%          37                37     0.00%
nmt_loader.cpp                       270               270     0.00%          14                14     0.00%         774               774     0.00%         161               161     0.00%
nmt_state_backend.cpp                188               188     0.00%          20                20     0.00%         424               424     0.00%         121               121     0.00%
nmt_tokenization.cpp                  88                88     0.00%           8                 8     0.00%         135               135     0.00%          61                61     0.00%
nmt_utils.cpp                        211               211     0.00%          21                21     0.00%         314               314     0.00%         143               143     0.00%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               1612              1612     0.00%         152               152     0.00%        3564              3564     0.00%        1030              1030     0.00%

@github-actions

Copy link
Copy Markdown
Contributor

🧪 C++ Test Coverage Report

Coverage:

📊 Detailed Coverage
Filename                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NmtLazyInitializeBackend.cpp          99                19    80.81%          11                 1    90.91%         157                34    78.34%          66                20    69.70%
NmtLazyInitializeBackend.hpp           2                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
TranslationModel.cpp                 296               168    43.24%          28                 8    71.43%         506               213    57.91%         181               122    32.60%
TranslationModel.hpp                   1                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
nmt.cpp                               72                22    69.44%           9                 1    88.89%         137                28    79.56%          44                16    63.64%
nmt.hpp                               51                 4    92.16%          11                 2    81.82%          53                 4    92.45%          28                 0   100.00%
nmt_beam_search.cpp                  116                25    78.45%          10                 3    70.00%         254                32    87.40%          76                19    75.00%
nmt_graph_decoder.cpp                164                78    52.44%          15                 7    53.33%         540               161    70.19%         112                69    38.39%
nmt_graph_encoder.cpp                 54                13    75.93%           3                 0   100.00%         268                33    87.69%          37                16    56.76%
nmt_loader.cpp                       270                67    75.19%          14                 0   100.00%         774                97    87.47%         161                67    58.39%
nmt_state_backend.cpp                188                46    75.53%          20                 0   100.00%         424                79    81.37%         121                51    57.85%
nmt_tokenization.cpp                  88                21    76.14%           8                 0   100.00%         135                36    73.33%          61                26    57.38%
nmt_utils.cpp                        211                34    83.89%          21                 0   100.00%         314                38    87.90%         143                45    68.53%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               1612               497    69.17%         152                22    85.53%        3564               755    78.82%        1030               451    56.21%

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

🧪 C++ Test Coverage Report

Coverage:

📊 Detailed Coverage
Filename                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NmtLazyInitializeBackend.cpp          99                19    80.81%          11                 1    90.91%         157                34    78.34%          66                20    69.70%
NmtLazyInitializeBackend.hpp           2                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
TranslationModel.cpp                 296               168    43.24%          28                 8    71.43%         506               213    57.91%         181               122    32.60%
TranslationModel.hpp                   1                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
nmt.cpp                               72                22    69.44%           9                 1    88.89%         137                28    79.56%          44                16    63.64%
nmt.hpp                               51                 4    92.16%          11                 2    81.82%          53                 4    92.45%          28                 0   100.00%
nmt_beam_search.cpp                  116                25    78.45%          10                 3    70.00%         254                32    87.40%          76                19    75.00%
nmt_graph_decoder.cpp                164                78    52.44%          15                 7    53.33%         540               161    70.19%         112                69    38.39%
nmt_graph_encoder.cpp                 54                13    75.93%           3                 0   100.00%         268                33    87.69%          37                16    56.76%
nmt_loader.cpp                       270                67    75.19%          14                 0   100.00%         774                97    87.47%         161                67    58.39%
nmt_state_backend.cpp                188                46    75.53%          20                 0   100.00%         424                79    81.37%         121                51    57.85%
nmt_tokenization.cpp                  88                21    76.14%           8                 0   100.00%         135                36    73.33%          61                26    57.38%
nmt_utils.cpp                        211                34    83.89%          21                 0   100.00%         314                38    87.90%         143                45    68.53%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               1612               497    69.17%         152                22    85.53%        3564               755    78.82%        1030               451    56.21%

@gianni-cor gianni-cor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One remaining MTP cache lifecycle issue needs a target-only fallback.

std::vector<uint8_t> driverState;
uint64_t generation = 0;
if (saveMtpState) {
if (!common_speculative_get_state(spec_.get(), seqId_, driverState)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Fall back to a target-only cache when MTP state is unavailable

rollbackDraftContext() can intentionally clear the draft KV and set pending_pos to -1 after cancellation while keeping a valid target prefix. That is a valid cold MTP state, but common_speculative_get_state() returns false for it. Throwing here turns an otherwise usable target cache into a failed save and invalidates the active cache. Please save the four-field target cache, remove or ignore stale .mtp-draft and .mtp-state files, and let MTP rebuild on a later request. Please apply the same fallback to MtmdLlmContext and add a cacheKey plus saveCacheToDisk cancellation test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in dd8ab7572. Both TextLlmContext and MtmdLlmContext now save a target-only cache after cancellation and remove stale MTP sidecars. Added cancellation tests using cacheKey and saveCacheToDisk for both paths.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 C++ Test Coverage Report

Coverage:

📊 Detailed Coverage
Filename                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NmtLazyInitializeBackend.cpp          99                19    80.81%          11                 1    90.91%         157                34    78.34%          66                20    69.70%
NmtLazyInitializeBackend.hpp           2                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
TranslationModel.cpp                 296               168    43.24%          28                 8    71.43%         506               213    57.91%         181               122    32.60%
TranslationModel.hpp                   1                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
nmt.cpp                               72                22    69.44%           9                 1    88.89%         137                28    79.56%          44                16    63.64%
nmt.hpp                               51                 4    92.16%          11                 2    81.82%          53                 4    92.45%          28                 0   100.00%
nmt_beam_search.cpp                  116                25    78.45%          10                 3    70.00%         254                32    87.40%          76                19    75.00%
nmt_graph_decoder.cpp                164                78    52.44%          15                 7    53.33%         540               161    70.19%         112                69    38.39%
nmt_graph_encoder.cpp                 54                13    75.93%           3                 0   100.00%         268                33    87.69%          37                16    56.76%
nmt_loader.cpp                       270                67    75.19%          14                 0   100.00%         774                97    87.47%         161                67    58.39%
nmt_state_backend.cpp                188                46    75.53%          20                 0   100.00%         424                79    81.37%         121                51    57.85%
nmt_tokenization.cpp                  88                21    76.14%           8                 0   100.00%         135                36    73.33%          61                26    57.38%
nmt_utils.cpp                        211                34    83.89%          21                 0   100.00%         314                38    87.90%         143                45    68.53%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               1612               497    69.17%         152                22    85.53%        3564               755    78.82%        1030               451    56.21%

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

🧪 C++ Test Coverage Report

Coverage:

📊 Detailed Coverage
Filename                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NmtLazyInitializeBackend.cpp          99                19    80.81%          11                 1    90.91%         157                34    78.34%          66                20    69.70%
NmtLazyInitializeBackend.hpp           2                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
TranslationModel.cpp                 296               168    43.24%          28                 8    71.43%         506               213    57.91%         181               122    32.60%
TranslationModel.hpp                   1                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
nmt.cpp                               72                22    69.44%           9                 1    88.89%         137                28    79.56%          44                16    63.64%
nmt.hpp                               51                 4    92.16%          11                 2    81.82%          53                 4    92.45%          28                 0   100.00%
nmt_beam_search.cpp                  116                25    78.45%          10                 3    70.00%         254                32    87.40%          76                19    75.00%
nmt_graph_decoder.cpp                164                78    52.44%          15                 7    53.33%         540               161    70.19%         112                69    38.39%
nmt_graph_encoder.cpp                 54                13    75.93%           3                 0   100.00%         268                33    87.69%          37                16    56.76%
nmt_loader.cpp                       270                67    75.19%          14                 0   100.00%         774                97    87.47%         161                67    58.39%
nmt_state_backend.cpp                188                46    75.53%          20                 0   100.00%         424                79    81.37%         121                51    57.85%
nmt_tokenization.cpp                  88                21    76.14%           8                 0   100.00%         135                36    73.33%          61                26    57.38%
nmt_utils.cpp                        211                34    83.89%          21                 0   100.00%         314                38    87.90%         143                45    68.53%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               1612               497    69.17%         152                22    85.53%        3564               755    78.82%        1030               451    56.21%

gianni-cor
gianni-cor previously approved these changes Sep 18, 2026

@gianni-cor gianni-cor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The target-only cache fallback is now handled correctly in both Text and MTMD, with cancellation and cold-restore regression coverage.

# Conflicts:
#	.github/workflows/integration-test-embed-llamacpp.yml
@github-actions

Copy link
Copy Markdown
Contributor

🧪 C++ Test Coverage Report

Coverage:

📊 Detailed Coverage
Filename                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NmtLazyInitializeBackend.cpp          99                19    80.81%          11                 1    90.91%         157                34    78.34%          66                20    69.70%
NmtLazyInitializeBackend.hpp           2                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
TranslationModel.cpp                 296               168    43.24%          28                 8    71.43%         506               213    57.91%         181               122    32.60%
TranslationModel.hpp                   1                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
nmt.cpp                               72                22    69.44%           9                 1    88.89%         137                28    79.56%          44                16    63.64%
nmt.hpp                               51                 4    92.16%          11                 2    81.82%          53                 4    92.45%          28                 0   100.00%
nmt_beam_search.cpp                  116                25    78.45%          10                 3    70.00%         254                32    87.40%          76                19    75.00%
nmt_graph_decoder.cpp                164                78    52.44%          15                 7    53.33%         540               161    70.19%         112                69    38.39%
nmt_graph_encoder.cpp                 54                13    75.93%           3                 0   100.00%         268                33    87.69%          37                16    56.76%
nmt_loader.cpp                       270                67    75.19%          14                 0   100.00%         774                97    87.47%         161                67    58.39%
nmt_state_backend.cpp                188                46    75.53%          20                 0   100.00%         424                79    81.37%         121                51    57.85%
nmt_tokenization.cpp                  88                21    76.14%           8                 0   100.00%         135                36    73.33%          61                26    57.38%
nmt_utils.cpp                        211                34    83.89%          21                 0   100.00%         314                38    87.90%         143                45    68.53%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               1612               497    69.17%         152                22    85.53%        3564               755    78.82%        1030               451    56.21%

@github-actions

Copy link
Copy Markdown
Contributor

🧪 C++ Test Coverage Report

Coverage:

📊 Detailed Coverage
Filename                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NmtLazyInitializeBackend.cpp          99                99     0.00%          11                11     0.00%         157               157     0.00%          66                66     0.00%
NmtLazyInitializeBackend.hpp           2                 2     0.00%           1                 1     0.00%           1                 1     0.00%           0                 0         -
TranslationModel.cpp                 296               296     0.00%          28                28     0.00%         506               506     0.00%         181               181     0.00%
TranslationModel.hpp                   1                 1     0.00%           1                 1     0.00%           1                 1     0.00%           0                 0         -
nmt.cpp                               72                72     0.00%           9                 9     0.00%         137               137     0.00%          44                44     0.00%
nmt.hpp                               51                51     0.00%          11                11     0.00%          53                53     0.00%          28                28     0.00%
nmt_beam_search.cpp                  116               116     0.00%          10                10     0.00%         254               254     0.00%          76                76     0.00%
nmt_graph_decoder.cpp                164               164     0.00%          15                15     0.00%         540               540     0.00%         112               112     0.00%
nmt_graph_encoder.cpp                 54                54     0.00%           3                 3     0.00%         268               268     0.00%          37                37     0.00%
nmt_loader.cpp                       270               270     0.00%          14                14     0.00%         774               774     0.00%         161               161     0.00%
nmt_state_backend.cpp                188               188     0.00%          20                20     0.00%         424               424     0.00%         121               121     0.00%
nmt_tokenization.cpp                  88                88     0.00%           8                 8     0.00%         135               135     0.00%          61                61     0.00%
nmt_utils.cpp                        211               211     0.00%          21                21     0.00%         314               314     0.00%         143               143     0.00%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               1612              1612     0.00%         152               152     0.00%        3564              3564     0.00%        1030              1030     0.00%

@github-actions

Copy link
Copy Markdown
Contributor

🧪 C++ Test Coverage Report

Coverage:

📊 Detailed Coverage
Filename                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NmtLazyInitializeBackend.cpp          99                19    80.81%          11                 1    90.91%         157                34    78.34%          66                20    69.70%
NmtLazyInitializeBackend.hpp           2                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
TranslationModel.cpp                 296               168    43.24%          28                 8    71.43%         506               213    57.91%         181               122    32.60%
TranslationModel.hpp                   1                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
nmt.cpp                               72                22    69.44%           9                 1    88.89%         137                28    79.56%          44                16    63.64%
nmt.hpp                               51                 4    92.16%          11                 2    81.82%          53                 4    92.45%          28                 0   100.00%
nmt_beam_search.cpp                  116                25    78.45%          10                 3    70.00%         254                32    87.40%          76                19    75.00%
nmt_graph_decoder.cpp                164                78    52.44%          15                 7    53.33%         540               161    70.19%         112                69    38.39%
nmt_graph_encoder.cpp                 54                13    75.93%           3                 0   100.00%         268                33    87.69%          37                16    56.76%
nmt_loader.cpp                       270                67    75.19%          14                 0   100.00%         774                97    87.47%         161                67    58.39%
nmt_state_backend.cpp                188                46    75.53%          20                 0   100.00%         424                79    81.37%         121                51    57.85%
nmt_tokenization.cpp                  88                21    76.14%           8                 0   100.00%         135                36    73.33%          61                26    57.38%
nmt_utils.cpp                        211                34    83.89%          21                 0   100.00%         314                38    87.90%         143                45    68.53%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               1612               497    69.17%         152                22    85.53%        3564               755    78.82%        1030               451    56.21%

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

🧪 C++ Test Coverage Report

Coverage:

📊 Detailed Coverage
Filename                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NmtLazyInitializeBackend.cpp          99                19    80.81%          11                 1    90.91%         157                34    78.34%          66                20    69.70%
NmtLazyInitializeBackend.hpp           2                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
TranslationModel.cpp                 296               168    43.24%          28                 8    71.43%         506               213    57.91%         181               122    32.60%
TranslationModel.hpp                   1                 0   100.00%           1                 0   100.00%           1                 0   100.00%           0                 0         -
nmt.cpp                               72                22    69.44%           9                 1    88.89%         137                28    79.56%          44                16    63.64%
nmt.hpp                               51                 4    92.16%          11                 2    81.82%          53                 4    92.45%          28                 0   100.00%
nmt_beam_search.cpp                  116                25    78.45%          10                 3    70.00%         254                32    87.40%          76                19    75.00%
nmt_graph_decoder.cpp                164                78    52.44%          15                 7    53.33%         540               161    70.19%         112                69    38.39%
nmt_graph_encoder.cpp                 54                13    75.93%           3                 0   100.00%         268                33    87.69%          37                16    56.76%
nmt_loader.cpp                       270                67    75.19%          14                 0   100.00%         774                97    87.47%         161                67    58.39%
nmt_state_backend.cpp                188                46    75.53%          20                 0   100.00%         424                79    81.37%         121                51    57.85%
nmt_tokenization.cpp                  88                21    76.14%           8                 0   100.00%         135                36    73.33%          61                26    57.38%
nmt_utils.cpp                        211                34    83.89%          21                 0   100.00%         314                38    87.90%         143                45    68.53%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               1612               497    69.17%         152                22    85.53%        3564               755    78.82%        1030               451    56.21%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-cpp-addon-tests CI: run C++ addon tests (requires verified) run-desktop-addon-tests CI: run desktop integration tests (requires verified)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants