-
-
Notifications
You must be signed in to change notification settings - Fork 17.7k
File system secondary tier implemented in python #41735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b062ca9
[KV Offload] Add pure-Python filesystem secondary tier.
rshavitt 1c889da
Add KV offload tests for file mapper and FS tier.
rshavitt 46b4eb4
update constructor to use OffloadingSpecs
rshavitt ed9fa0c
Fix file mapper creation, formatting issues, e2e test.
rshavitt bce4165
Fix O_DIRECT platform compatibility for macOS
rshavitt 2b2d757
Restore CLAUDE.md to match main branch
rshavitt 43f125a
fix FileMapper test file
rshavitt d565826
remove cpu_cpu_blocks_per_file and fix tests
rshavitt 4f3cd3c
add shutdown to tier manager
rshavitt 76e0975
fix test_ts_tier to correctly shutdown
rshavitt 28a49a3
Merge branch 'main' into fs-tier-python
orozery c8cc24e
Merge branch 'main' into fs-tier-python
orozery 2328e70
fix docstring
orozery File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| """Unit tests for FileMapper.""" | ||
|
|
||
| from unittest.mock import MagicMock | ||
|
|
||
| from vllm.v1.kv_offload.base import ( | ||
| OffloadingSpec, | ||
| make_offload_key, | ||
| ) | ||
| from vllm.v1.kv_offload.file_mapper import FileMapper | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Shared mocks (mirrors test_fs_tier.py pattern) | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| _MOCK_VLLM_CONFIG = MagicMock() | ||
| _MOCK_VLLM_CONFIG.model_config.model = "test-model" | ||
| _MOCK_VLLM_CONFIG.cache_config.block_size = 16 | ||
| _MOCK_VLLM_CONFIG.cache_config.cache_dtype = "torch.float32" | ||
| _MOCK_VLLM_CONFIG.parallel_config.tensor_parallel_size = 1 | ||
| _MOCK_VLLM_CONFIG.parallel_config.pipeline_parallel_size = 1 | ||
| _MOCK_VLLM_CONFIG.parallel_config.prefill_context_parallel_size = 1 | ||
| _MOCK_VLLM_CONFIG.parallel_config.decode_context_parallel_size = 1 | ||
| _MOCK_VLLM_CONFIG.parallel_config.rank = 0 | ||
|
|
||
| _MOCK_KV_CACHE_CONFIG = MagicMock() | ||
| _MOCK_KV_CACHE_CONFIG.kv_cache_groups = [] | ||
|
|
||
| _MOCK_OFFLOADING_SPEC = MagicMock(spec=OffloadingSpec) | ||
| _MOCK_OFFLOADING_SPEC.vllm_config = _MOCK_VLLM_CONFIG | ||
| _MOCK_OFFLOADING_SPEC.kv_cache_config = _MOCK_KV_CACHE_CONFIG | ||
| _MOCK_OFFLOADING_SPEC.block_size_factor = 1 | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Helper | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def make_mapper_from_offloading_spec(**kwargs) -> FileMapper: | ||
| """Helper to create FileMapper with customizable mock config.""" | ||
| # Create a copy of the mock config to avoid modifying the global one | ||
| mock_vllm_config = MagicMock() | ||
| mock_vllm_config.model_config.model = kwargs.get("model_name", "test-model") | ||
| mock_vllm_config.cache_config.block_size = kwargs.get("hash_block_size", 16) | ||
| mock_vllm_config.cache_config.cache_dtype = ( | ||
| f"torch.{kwargs.get('dtype', 'float16')}" | ||
| ) | ||
| mock_vllm_config.parallel_config.tensor_parallel_size = kwargs.get("tp_size", 1) | ||
| mock_vllm_config.parallel_config.pipeline_parallel_size = kwargs.get("pp_size", 1) | ||
| mock_vllm_config.parallel_config.prefill_context_parallel_size = kwargs.get( | ||
| "pcp_size", 1 | ||
| ) | ||
| mock_vllm_config.parallel_config.decode_context_parallel_size = kwargs.get( | ||
| "dcp_size", 1 | ||
| ) | ||
| mock_vllm_config.parallel_config.rank = kwargs.get("rank", 0) | ||
|
|
||
| mock_kv_cache_config = MagicMock() | ||
| mock_kv_cache_config.kv_cache_groups = [] | ||
|
|
||
| mock_offloading_spec = MagicMock(spec=OffloadingSpec) | ||
| mock_offloading_spec.vllm_config = mock_vllm_config | ||
| mock_offloading_spec.kv_cache_config = mock_kv_cache_config | ||
| mock_offloading_spec.block_size_factor = kwargs.get("block_size_factor", 1) | ||
|
|
||
| return FileMapper.from_offloading_spec( | ||
| root_dir=kwargs.get("root_dir", "/tmp/cache"), | ||
| offloading_spec=mock_offloading_spec, | ||
| gpu_blocks_per_file=mock_offloading_spec.block_size_factor, | ||
| ) | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Tests | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def test_get_file_name_full_structure(): | ||
| """ | ||
| Path must match: <base_path>_r<rank>/<hhh>/<hh>_g<group_idx>/<hash_hex>.bin | ||
|
|
||
| Concretely: | ||
| - The segment immediately after base_path must end with `_r0` | ||
| - The next segment is the first 3 hex chars of the block hash | ||
| - The next segment is <2 hex chars>_g<group_idx> | ||
| - The final segment is <full hash hex>.bin | ||
| """ | ||
| rank = 3 | ||
| group_idx = 2 | ||
| block_hash = bytes(range(8)) # deterministic, non-zero bytes | ||
| fm = make_mapper_from_offloading_spec(rank=rank) | ||
| key = make_offload_key(block_hash, group_idx) | ||
| path = fm.get_file_name(key) | ||
|
|
||
| expected_path = ( | ||
| "/tmp/cache/test-model_588656ebcc66_r3/000/10_g2/0001020304050607.bin" | ||
| ) | ||
|
rshavitt marked this conversation as resolved.
|
||
| assert path == expected_path | ||
|
|
||
|
|
||
| def test_get_run_config_fields(): | ||
| fm = make_mapper_from_offloading_spec( | ||
| model_name="my-model", | ||
| dtype="bfloat16", | ||
| tp_size=2, | ||
| ) | ||
| cfg = fm.get_run_config() | ||
| assert cfg == { | ||
| "model_name": "my-model", | ||
| "hash_block_size": 16, | ||
| "gpu_blocks_per_file": 1, | ||
| "tp_size": 2, | ||
| "pp_size": 1, | ||
| "pcp_size": 1, | ||
| "dcp_size": 1, | ||
| "dtype": "bfloat16", | ||
| "kv_cache_groups": [], | ||
| "inference_engine": "vllm", | ||
| } | ||
|
|
||
|
|
||
| def test_get_config_file_path(): | ||
| fm = make_mapper_from_offloading_spec() | ||
| config_path = fm.get_config_file_path() | ||
| assert config_path == f"{fm.base_path}/config.json" | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.