Skip to content

[KV Offload] Pass request context - #39185

Merged
orozery merged 13 commits into
vllm-project:mainfrom
omerpaz95:pass_request_context
Apr 19, 2026
Merged

orozery merged 13 commits into
vllm-project:mainfrom
omerpaz95:pass_request_context

Conversation

@omerpaz95

@omerpaz95 omerpaz95 commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Pass per-request context (kv_transfer_params) through the CPU offloading manager interface.

The OffloadingManager ABC and CPUOffloadingManager now accept a ReqContext argument on lookup, prepare_load, and prepare_store. ReqContext wraps request.kv_transfer_params (a free-form dict set via sampling_params.extra_args) and is constructed at each call site in OffloadingConnectorScheduler.

This is wiring-only: ReqContext is accepted but not yet consumed by CPUOffloadingManager.

Structural changes:

  • ReqContext dataclass is defined in vllm/v1/kv_offload/abstract.py (shared layer) rather than cpu/manager.py, so other OffloadingManager implementations can use it without importing from the CPU-specific module.

Test Plan

# Lint
cd vllm
pre-commit run

# Scheduler unit tests
pytest tests/v1/kv_connector/test_offloading_scheduler.py -v -s

Test Result

Pre-commit (ruff, mypy, all hooks): all passed.


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a ReqContext dataclass to pass per-request parameters, such as kv_transfer_params, through the KV offloading pipeline. The OffloadingManager interface and its CPU implementation have been updated to include this context in lookup, prepare_load, and prepare_store methods. Feedback indicates that for full consistency and to support features like tenant-aware resource management, the ReqContext should also be added to the touch, complete_load, and complete_store methods. Furthermore, existing unit test mocks need to be updated to match the new method signatures to avoid TypeError exceptions.

def lookup(
self,
block_hashes: Iterable[BlockHash],
req_context: ReqContext,

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.

high

The ReqContext should also be added to the touch, complete_load, and complete_store methods. Since the stated goal of this PR is to support features like tenant routing and priority hints, these lifecycle management methods must also be context-aware. For example, a tenant-aware manager needs the context in complete_load to correctly release tenant-specific pins or quotas, and in touch to update the correct tenant's LRU state. Omitting the context here creates an inconsistent API that will likely require another breaking change soon.


src_spec = self.manager.prepare_load(block_hashes)
req_context = ReqContext(kv_transfer_params=request.kv_transfer_params)
src_spec = self.manager.prepare_load(block_hashes, req_context)

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.

high

Updating the prepare_load signature to require req_context will break the existing unit tests. Specifically, in tests/v1/kv_connector/unit/offloading_connector/utils.py, the MockOffloadingSpec initializes self.manager.prepare_load with a single-argument lambda (lambda block_hashes: ...). This will now raise a TypeError when called with two arguments in the scheduler. Please ensure the test mocks are updated to accommodate the new parameter.

@mergify

mergify Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @omerpaz95.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@@ -304,7 +309,8 @@ def _get_reqs_to_store(self, scheduler_output: SchedulerOutput):
assert len(req.block_hashes) >= num_gpu_blocks

new_offload_keys = group_state.offload_keys[start_block_idx:num_blocks]
store_output = self.manager.prepare_store(new_offload_keys)
req_context = ReqContext(kv_transfer_params=req.kv_transfer_params)

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.

Can we re-use ReqContext by introducing a field in RequestOffloadState?

Comment thread vllm/v1/kv_offload/abstract.py Outdated
"""
Prepare the given blocks to be offloaded.
The given blocks will be protected from eviction until
complete_store is called.

Args:
req_context: per-request context (e.g. kv_transfer_params).

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.

Let's move this after keys to match the args order.

Comment thread vllm/v1/kv_offload/cpu/manager.py Outdated
@@ -114,7 +123,11 @@ def complete_load(self, keys: Iterable[OffloadKey]) -> None:
assert block.ref_cnt > 0, f"Block {key!r} ref_cnt is already 0"
block.ref_cnt -= 1

def prepare_store(self, keys: Iterable[OffloadKey]) -> PrepareStoreOutput | None:
def prepare_store(
self,

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.

Suggested change
self,
self,

Comment thread tests/v1/kv_offload/test_cpu_manager.py Outdated
return ReqContext(kv_transfer_params=kv_transfer_params)


_CTX = make_req_context()

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.

Suggested change
_CTX = make_req_context()
_EMPTY_REQ_CTX = make_req_context()

@orozery orozery 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.

Thanks! Please also make sure pre-commit passes following these changes.

hits = self.manager.lookup(offload_keys[start_block_idx:])
hits = self.manager.lookup(
offload_keys[start_block_idx:],
self._req_status[request.request_id].req_context,

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.

Suggested change
self._req_status[request.request_id].req_context,
req_status.req_context,

@@ -249,7 +255,9 @@ def update_state_after_alloc(
assert len(request.block_hashes) // self.config.block_size_factor >= num_blocks
offload_keys = group_state.offload_keys[start_block_idx:num_blocks]

src_spec = self.manager.prepare_load(offload_keys)
src_spec = self.manager.prepare_load(
offload_keys, self._req_status[request.request_id].req_context

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.

Suggested change
offload_keys, self._req_status[request.request_id].req_context
offload_keys, req_status.req_context

Signed-off-by: omerpaz95 <omerpaz95@gmail.com>
Signed-off-by: omerpaz95 <omerpaz95@gmail.com>
@omerpaz95
omerpaz95 force-pushed the pass_request_context branch from 49aa8cf to 40f913b Compare April 15, 2026 13:15
@omerpaz95
omerpaz95 requested a review from xuechendi as a code owner April 16, 2026 18:08

@orozery orozery 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.

LGTM

@github-project-automation github-project-automation Bot moved this to Ready in NVIDIA Apr 19, 2026
@github-project-automation github-project-automation Bot moved this from To Triage to Ready in gpt-oss Issues & Enhancements Apr 19, 2026
@orozery
orozery merged commit 4353c9c into vllm-project:main Apr 19, 2026
63 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AMD Apr 19, 2026
@github-project-automation github-project-automation Bot moved this from Ready to Done in NVIDIA Apr 19, 2026
iboiko-habana pushed a commit to vllm-project/vllm-gaudi that referenced this pull request Apr 21, 2026
…floading test lambdas for upstream req_context parameter (#1375)

## Root Cause

Upstream vLLM PR vllm-project/vllm#39185 (commit
`4353c9cb4a`) added a `req_context: ReqContext` parameter to
`OffloadingManager.prepare_store()`, `prepare_load()`, and `lookup()`
methods. The vllm-gaudi tests use mock `side_effect` lambdas and direct
lambda assignments that only accepted the original single parameter
(`block_hashes`/`keys`), but now receive two positional arguments.

## Fix

Updated all 14 lambda signatures in
`tests/unit_tests/kv_offload/offloading_connector/test_scheduler.py` and
1 lambda in `utils.py` to accept the new `req_context` parameter (unused
in test mocks).

## Files Changed
- `tests/unit_tests/kv_offload/offloading_connector/test_scheduler.py` —
all `prepare_store.side_effect` lambdas: `lambda block_hashes:` →
`lambda block_hashes, req_context:`
- `tests/unit_tests/kv_offload/offloading_connector/utils.py` —
`prepare_load` lambda: `lambda block_hashes:` → `lambda block_hashes,
req_context:`

## Verification

Verified on Gaudi3 HPU (g3 pod):
- **Before fix**: 8/8 tests FAILED with `TypeError: lambda() takes 1
positional argument but 2 were given`
- **After fix**: 8/8 tests PASSED (6.52s)

Tests: `python -m pytest
tests/unit_tests/kv_offload/offloading_connector/test_scheduler.py -v`

Signed-off-by: Paweł Olejniczak <pawelx.olejniczak@intel.com>
yeonsily pushed a commit to yeonsily/vllm-gaudi that referenced this pull request Apr 21, 2026
…floading test lambdas for upstream req_context parameter (vllm-project#1375)

## Root Cause

Upstream vLLM PR vllm-project/vllm#39185 (commit
`4353c9cb4a`) added a `req_context: ReqContext` parameter to
`OffloadingManager.prepare_store()`, `prepare_load()`, and `lookup()`
methods. The vllm-gaudi tests use mock `side_effect` lambdas and direct
lambda assignments that only accepted the original single parameter
(`block_hashes`/`keys`), but now receive two positional arguments.

## Fix

Updated all 14 lambda signatures in
`tests/unit_tests/kv_offload/offloading_connector/test_scheduler.py` and
1 lambda in `utils.py` to accept the new `req_context` parameter (unused
in test mocks).

## Files Changed
- `tests/unit_tests/kv_offload/offloading_connector/test_scheduler.py` —
all `prepare_store.side_effect` lambdas: `lambda block_hashes:` →
`lambda block_hashes, req_context:`
- `tests/unit_tests/kv_offload/offloading_connector/utils.py` —
`prepare_load` lambda: `lambda block_hashes:` → `lambda block_hashes,
req_context:`

## Verification

Verified on Gaudi3 HPU (g3 pod):
- **Before fix**: 8/8 tests FAILED with `TypeError: lambda() takes 1
positional argument but 2 were given`
- **After fix**: 8/8 tests PASSED (6.52s)

Tests: `python -m pytest
tests/unit_tests/kv_offload/offloading_connector/test_scheduler.py -v`

Signed-off-by: Paweł Olejniczak <pawelx.olejniczak@intel.com>
Signed-off-by: Yeonsil Yoon <yeon.sil.yoon@intel.com>
bmyrcha pushed a commit to bmyrcha/vllm-gaudi that referenced this pull request Apr 22, 2026
…floading test lambdas for upstream req_context parameter (vllm-project#1375)

## Root Cause

Upstream vLLM PR vllm-project/vllm#39185 (commit
`4353c9cb4a`) added a `req_context: ReqContext` parameter to
`OffloadingManager.prepare_store()`, `prepare_load()`, and `lookup()`
methods. The vllm-gaudi tests use mock `side_effect` lambdas and direct
lambda assignments that only accepted the original single parameter
(`block_hashes`/`keys`), but now receive two positional arguments.

## Fix

Updated all 14 lambda signatures in
`tests/unit_tests/kv_offload/offloading_connector/test_scheduler.py` and
1 lambda in `utils.py` to accept the new `req_context` parameter (unused
in test mocks).

## Files Changed
- `tests/unit_tests/kv_offload/offloading_connector/test_scheduler.py` —
all `prepare_store.side_effect` lambdas: `lambda block_hashes:` →
`lambda block_hashes, req_context:`
- `tests/unit_tests/kv_offload/offloading_connector/utils.py` —
`prepare_load` lambda: `lambda block_hashes:` → `lambda block_hashes,
req_context:`

## Verification

Verified on Gaudi3 HPU (g3 pod):
- **Before fix**: 8/8 tests FAILED with `TypeError: lambda() takes 1
positional argument but 2 were given`
- **After fix**: 8/8 tests PASSED (6.52s)

Tests: `python -m pytest
tests/unit_tests/kv_offload/offloading_connector/test_scheduler.py -v`

Signed-off-by: Paweł Olejniczak <pawelx.olejniczak@intel.com>
Signed-off-by: bmyrcha <bartosz.myrcha@intel.com>
avinashsingh77 pushed a commit to avinashsingh77/vllm that referenced this pull request Apr 27, 2026
Signed-off-by: omerpaz95 <omerpaz95@gmail.com>
Signed-off-by: Avinash Singh <avinashsingh.rcoem@gmail.com>
afierka-intel pushed a commit to vllm-project/vllm-gaudi that referenced this pull request May 4, 2026
…floading test lambdas for upstream req_context parameter (#1375)

## Root Cause

Upstream vLLM PR vllm-project/vllm#39185 (commit
`4353c9cb4a`) added a `req_context: ReqContext` parameter to
`OffloadingManager.prepare_store()`, `prepare_load()`, and `lookup()`
methods. The vllm-gaudi tests use mock `side_effect` lambdas and direct
lambda assignments that only accepted the original single parameter
(`block_hashes`/`keys`), but now receive two positional arguments.

## Fix

Updated all 14 lambda signatures in
`tests/unit_tests/kv_offload/offloading_connector/test_scheduler.py` and
1 lambda in `utils.py` to accept the new `req_context` parameter (unused
in test mocks).

## Files Changed
- `tests/unit_tests/kv_offload/offloading_connector/test_scheduler.py` —
all `prepare_store.side_effect` lambdas: `lambda block_hashes:` →
`lambda block_hashes, req_context:`
- `tests/unit_tests/kv_offload/offloading_connector/utils.py` —
`prepare_load` lambda: `lambda block_hashes:` → `lambda block_hashes,
req_context:`

## Verification

Verified on Gaudi3 HPU (g3 pod):
- **Before fix**: 8/8 tests FAILED with `TypeError: lambda() takes 1
positional argument but 2 were given`
- **After fix**: 8/8 tests PASSED (6.52s)

Tests: `python -m pytest
tests/unit_tests/kv_offload/offloading_connector/test_scheduler.py -v`

Signed-off-by: Paweł Olejniczak <pawelx.olejniczak@intel.com>
Signed-off-by: Artur Fierka <artur.fierka@intel.com>
mystous pushed a commit to mystous/vllm_hybrid that referenced this pull request May 10, 2026
Signed-off-by: omerpaz95 <omerpaz95@gmail.com>
my-other-github-account pushed a commit to my-other-github-account/vllm that referenced this pull request May 15, 2026
Signed-off-by: omerpaz95 <omerpaz95@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/build documentation Improvements or additions to documentation frontend gpt-oss Related to GPT-OSS models intel-gpu Related to Intel GPU kv-connector multi-modality Related to multi-modality (#4194) nvidia ready ONLY add when PR is ready to merge/full CI is needed rocm Related to AMD ROCm v1

Projects

Status: Done
Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants