Skip to content

Fix graph capture identity after LoRA adapter activation - #2740

Merged
kunal-vaishnavi merged 3 commits into
mainfrom
qjia7/fix-lora-adapter-capture-identity
Oct 22, 2026
Merged

kunal-vaishnavi merged 3 commits into
mainfrom
qjia7/fix-lora-adapter-capture-identity

Conversation

@qjia7

Copy link
Copy Markdown
Contributor

Activating a LoRA adapter after a generator has captured decode currently reuses the base path's gpu_graph_id. Graph replay bypasses input processing and kernel selection, so decode can silently ignore the newly activated adapter.

This change includes the active-adapter revision in capture identity, alongside input length and execution variant. It reuses the process-wide GraphAnnotationIds allocator to prevent collisions between generators sharing a session, retains older captures for cleanup, and uses the actual capture ID for recurrent-state capture fixup. Adapter activation remains additive; it does not recompute earlier KV-cache entries.

The new Python regression is included in the regular test runner. It captures the base path, activates A and then A+B on the same generator after rewind, compares full logits with fresh active generators, and verifies a fresh base generator sharing the session. It also checks distinct capture IDs and adapter unloading.

Validation on Windows / NVIDIA RTX 5080:

  • Release native library and Python wheel built successfully. Formatting and whitespace checks pass.
  • WebGPU regression: 2 passed (capture off/on); the two CUDA parameterizations were not run locally.
  • Full-model reproduction before the fix: capture-off comparisons were exact, but captured decode differed from a fresh active generator by up to 2.82764 in logits. After the fix, all six forced-prefix logit rows match exactly with built-in WebGPU, and with the plugin under capture.
  • Isolated native performance checks cover FP16 and INT8 adapters, on/off, at 128 and 1024 prompt tokens. Two initially slower cases were checked in a three-configuration comparison separating the ORT update from GenAI. Final 1024-token confirmation changes versus the previous build were +0.14% decode / -0.41% TTFT for FP16 adapter-off and -0.25% decode / +0.15% TTFT for INT8 adapter-on. No repeatable regression was observed on this GPU.

Related ORT operator and capture coverage: microsoft/onnxruntime#33370. This GenAI fix addresses capture identity independently of that operator implementation.

Copilot AI 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.

🔵 Needs a closer look

CUDA parameterizations remain unvalidated, and adapter recapture with recurrent state needs hardware-backed confirmation.

0 open findings

What changed in this PR

Fixes graph-capture identity so activating LoRA adapters does not replay a previously captured base-model path.

Changes:

  • Includes adapter revision in capture identity using process-wide IDs, retaining older captures for cleanup.
  • Uses actual capture IDs for recurrent-state fixup.
  • Adds regression coverage and documents additive activation and KV-cache behavior.
File Description
test/​python/​test_onnxruntime_genai.py Includes the new regression in the regular runner.
test/​python/​test_adapter_graph_capture.py Tests adapter activation, capture isolation, logits, and unloading.
src/​ort_genai_c.h Documents activation and KV-cache semantics.
src/​models/​multi_modal.cpp Uses actual capture IDs for recurrent-state fixup.
src/​models/​model.h Replaces local capture-ID storage with the shared allocator.
src/​models/​model.cpp Allocates adapter-aware capture IDs and releases retained captures.
src/​models/​decoder_only.cpp Uses actual capture IDs for recurrent-state fixup.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@baijumeswani Baiju Meswani (baijumeswani) left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The main fix looks sound. I did not find a confirmed correctness bug. These four comments are non-blocking suggestions, mainly about test coverage and making fallback behavior easier to understand.

Comment thread src/models/decoder_only.cpp
Comment thread src/models/model.cpp Outdated
Comment thread test/python/test_adapter_graph_capture.py
Comment thread test/python/test_adapter_graph_capture.py Outdated
Comment thread src/models/model.cpp
@kunal-vaishnavi
kunal-vaishnavi enabled auto-merge (squash) October 22, 2026 05:22
@kunal-vaishnavi
kunal-vaishnavi merged commit 0048278 into main Oct 22, 2026
66 checks passed
@kunal-vaishnavi
kunal-vaishnavi deleted the qjia7/fix-lora-adapter-capture-identity branch October 22, 2026 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants