-
Notifications
You must be signed in to change notification settings - Fork 580
feat: vllm mocker enhancement #1236
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
Conversation
WalkthroughThe codebase underwent a major refactor of the mock worker's scheduling, eviction, and sequence management logic. The LRU evictor now uses integer counters and a BTreeSet for precise eviction order. Scheduler and KV manager logic were updated to support a two-phase (prefill/decode) model, improved resource accounting, and simplified interfaces. Sequence and protocol structures were adjusted accordingly. A new asynchronous mock engine was introduced, integrating schedulers, streaming token generation, metrics, and KV event publishing. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant MockVllmEngine
participant Scheduler
participant KvManager
participant Evictor
Client->>MockVllmEngine: generate(DirectRequest)
MockVllmEngine->>Scheduler: submit request
Scheduler->>KvManager: compute prefill cost
Scheduler->>Scheduler: insert into prefill queue
loop Prefill phase
Scheduler->>Scheduler: process prefill queue
Scheduler->>KvManager: update active blocks/tokens
end
Scheduler->>Scheduler: move to decode queue
loop Decode phase
Scheduler->>Scheduler: process decode queue
Scheduler->>Evictor: evict if needed
Scheduler->>KvManager: send block store/remove responses
end
Scheduler->>MockVllmEngine: output signals
MockVllmEngine->>Client: stream generated tokens
Assessment against linked issues
Assessment against linked issues: Out-of-scope changes
Possibly related PRs
Poem
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🔭 Outside diff range comments (1)
lib/llm/src/mocker/scheduler.rs (1)
294-346
: 🛠️ Refactor suggestion
⚠️ Potential issueLocks are held across an
.await
; this blocks every other task
state_guard
andkv_manager_guard
stay alive while the task sleeps:let adjusted_time = Duration::from_secs_f64(total_time.as_secs_f64() / speedup_ratio); if adjusted_time.as_millis() > 0 { tokio::time::sleep(adjusted_time).await; // <-- await with locks held }While sleeping, all other async tasks that need the same
Mutex
es (e.g.receive
, metrics queries, other scheduler ticks) will starve, drastically reducing concurrency and possibly causing dead-locks when used with additional locks elsewhere.Fix by dropping the guards before the await:
-// Sleep once for the adjusted duration -let adjusted_time = Duration::from_secs_f64(total_time.as_secs_f64() / speedup_ratio); -if adjusted_time.as_millis() > 0 { - tokio::time::sleep(adjusted_time).await; -} +// Sleep once for the adjusted duration +let adjusted_time = Duration::from_secs_f64(total_time.as_secs_f64() / speedup_ratio); + +// Explicitly drop locks to avoid holding them across await points +drop(state_guard); +drop(kv_manager_guard); + +if adjusted_time.as_millis() > 0 { + tokio::time::sleep(adjusted_time).await; +}Please scope the guard usages or call
drop()
as above to restore non-blocking behaviour.
🧹 Nitpick comments (7)
lib/llm/src/mocker/protocols.rs (1)
58-63
: Consider documenting the newnew_blocks
field
PrefillCost
now exposesnew_blocks
, but the struct-level doc comment still talks about “the cost of prefilling content” without explaining that both token and block deltas are returned. A short description will make downstream usage clearer and avoid confusion with the pre–refactor signature./// Represents the cost of prefilling content in the cache -#[derive(Debug, Clone, Serialize, Deserialize)] +/// `new_blocks` – number of blocks not currently resident in **active** cache +/// `new_tokens` – number of tokens that need to be copied for those blocks +/// `prefill_compute` – empirical latency model (µs) +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct PrefillCost {lib/llm/src/mocker/sequence.rs (3)
69-76
: Parameter name still indicates an option, but the struct has a fixedblock_size
The constructor now takes
block_size: Option<usize>
, which is fine, yet the earlier discussion in the PR implied the removal of a configurable size.
If external callers are no longer expected to passNone
(i.e. we always default to64
) consider:
- Dropping the
Option
wrapper and acceptingusize
directly, or- Renaming to
block_size_override
(or similar) to clarify semantics.This will prevent accidental
None
propagation or double-wrapped options elsewhere.
107-110
:new_with_signal
leaks the same default-handling logic twice
new_with_signal
forwards toSelf::new
which already expands the default forblock_size
.
If you accept the previous suggestion and drop theOption
, you can simplify the call and the tests that passSome(16)
.
229-234
: Tests rely on magic numbers – make them constants
Some(16)
is repeated in every test case. Replacing the literal with aconst BLOCK: usize = 16;
at the module level improves readability and prevents drift when the default changes.lib/llm/src/mocker/kv_manager.rs (1)
203-206
: Floating-point division on integers – cast onceA micro-nit: you convert both operands every call. Caching
max_capacity as f64
in the struct saves a few casts in hot loops.lib/llm/src/mocker/evictor.rs (1)
108-113
: Risk ofi64
counter under-/overflow & eventual wrap-around
negative_counter
monotonically decreases andpositive_counter
increases forever.
With long-running services (billions of insertions) the counters may reach the limits ofi64
, wrapping to the opposite sign and breaking ordering guarantees.Mitigations:
- Use
i128
, or reset both counters when they approach the limits (e.g. every 2^60 ops) while re-normalising all stored counters.- Alternatively, store
(Instant, u64)
or(u64, GenerationId)
and rely on wrapping add with safe tiebreakers.Although unlikely in tests, overflow bugs manifest in persistent services.
lib/llm/src/mocker/scheduler.rs (1)
108-113
: Decode LRU is not refreshed on every access
run()
merely checks membership; it does not update recency, so eviction order is insertion order, not true LRU.
If the intent is genuine LRU pre-emption, consider callingdecode.insert(uuid)
insiderun()
(or providing a specialisedtouch
method) to bump the counter each time the sequence is decoded.This is a functional not a correctness bug – but it biases eviction unfairly.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
lib/llm/src/mocker/evictor.rs
(2 hunks)lib/llm/src/mocker/kv_manager.rs
(3 hunks)lib/llm/src/mocker/protocols.rs
(1 hunks)lib/llm/src/mocker/scheduler.rs
(12 hunks)lib/llm/src/mocker/sequence.rs
(5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
lib/llm/src/mocker/scheduler.rs (3)
lib/llm/src/mocker/kv_manager.rs (4)
new
(70-82)num_active_blocks
(199-201)get_prefill_cost
(224-239)get_active_perc
(204-206)lib/llm/src/mocker/evictor.rs (2)
new
(62-65)default
(50-57)lib/llm/src/mocker/sequence.rs (3)
new
(69-87)generate
(151-177)pop
(210-218)
🔇 Additional comments (1)
lib/llm/src/mocker/kv_manager.rs (1)
178-183
:probe_new_blocks
no longer checks the inactive pool – is that deliberate?Switching the probe from
all_blocks
to onlyactive_blocks
means a block that resides in the inactive LRU will now be treated as new.
That will over-estimatenew_blocks
andnew_tokens
, skewing both budget checks and the latency model.If the intent is precisely “blocks not currently active”, please update the docstring of
PrefillCost::new_blocks
to match.
Otherwise, consider reverting to!self.all_blocks.contains(block)
(or additionally checkinginactive_blocks
) to preserve previous behaviour.
can be used for #1409 for pure predictive routing (via mocking the KV Events and load metrics) |
da4cefc
to
8e8d0b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't create DistributedRuntime there, see my comment.
Overview:
This PR introduces:
AsyncEngine
, integrating withdynamo-run
dynamo-run
)Will close #995
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Refactor
Bug Fixes