refactor: report cache usage directly - #4798
Open
lvhan028 wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors scheduler cache reporting to expose cache_usage directly (as a normalized 0.0–1.0 fraction) and removes the older total_blocks/free_blocks fields from schedule-metrics across TurboMind (C++/pybind) and Python.
Changes:
- Remove
total_blocks/free_blocksfrom TurboMindScheduleMetrics(struct, logging, and pybind exposure). - Compute and expose
cache_usagedirectly in the PyTorch paging scheduler, with added unit coverage including a zero-GPU-blocks edge case. - Simplify metrics aggregation to always consume
ScheduleMetrics.cache_usage(no fallback derivation).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/pytorch/paging/test_scheduler.py | Adds assertions/tests validating schedule_metrics.cache_usage, including num_gpu_blocks=0. |
| src/turbomind/utils/metrics.h | Removes block-count fields from ScheduleMetrics and stops printing them. |
| src/turbomind/python/bind.cpp | Stops exporting total_blocks/free_blocks to Python bindings. |
| src/turbomind/engine/engine.cc | Stops populating removed block-count fields; retains cache_usage. |
| lmdeploy/turbomind/turbomind.py | Stops reading removed TurboMind fields when constructing Python ScheduleMetrics. |
| lmdeploy/pytorch/paging/scheduler.py | Computes cache_usage directly from block-manager utilization. |
| lmdeploy/metrics/stats.py | Uses scheduled_metrics.cache_usage directly for gpu_cache_usage. |
| lmdeploy/messages.py | Updates the shared ScheduleMetrics dataclass to drop block-count fields and make cache_usage non-optional. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Motivation
ScheduleMetrics.total_blocksandfree_blocksexpose allocator-specific details to the upper metrics layer.Having the upper layer derive cache utilization from these fields couples it to a particular allocation strategy. Each engine should instead calculate cache utilization according to its own memory model and report a backend-independent value.
Modification
total_blocksandfree_blocksfromScheduleMetrics.cache_usageto a concrete float with a default of 0.0.