Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions openinfer-qwen35-4b/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use crate::logprobs::snapshot_requested_logprobs;
use crate::recurrent_state::RecurrentState;
use crate::weights::Qwen35Model;
use openinfer_core::engine::{
EngineHandle as SchedulerHandle, FinishReason, GenerateRequest as SchedulerRequest, TokenEvent,
TokenLogprob, TokenSink,
EngineHandle as SchedulerHandle, FinishReason, GenerateRequest as SchedulerRequest, KvCapacity,
TokenEvent, TokenLogprob, TokenSink,
};
use openinfer_core::kv_pool::KvState;
use openinfer_core::sampler::SamplingParams;
Expand Down Expand Up @@ -85,10 +85,12 @@ pub fn start_with_capacity(
);
// Static instance cap for the vLLM bridge's max_model_len. Live admission
// still uses the current page budget inside the scheduler loop.
let total_blocks = model.kv_pool().capacity_pages().saturating_sub(1);
let block_size = model.kv_pool().layout().page_size;
let servable = servable_len(
model.config().max_position_embeddings,
model.kv_pool().capacity_pages().saturating_sub(1),
model.kv_pool().layout().page_size,
total_blocks,
block_size,
);
let graph_state = model.create_batch_decode_graph_state_with_capacity(max_batch)?;

Expand All @@ -115,7 +117,14 @@ pub fn start_with_capacity(
let _ = join_handle.join();
return Err(err);
}
Ok(SchedulerHandle::new_with_join_handle(submit_tx, join_handle).with_servable_len(servable))
Ok(
SchedulerHandle::new_with_join_handle(submit_tx, join_handle)
.with_servable_len(servable)
.with_kv_capacity(KvCapacity {
total_blocks,
block_size,
}),
)
}

fn servable_len(max_context: usize, max_pages: usize, page_size: usize) -> u32 {
Expand Down
34 changes: 26 additions & 8 deletions openinfer-vllm-frontend/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,39 @@ impl LocalEngineBridge {
)
})?;

let kv_capacity = self.handle.kv_capacity();
let (num_gpu_blocks, block_size, kv_cache_size_tokens, kv_cache_max_concurrency) =
match kv_capacity {
Some(c) => {
// vLLM single-group concurrency: blocks / ceil(max_len / block_size).
let blocks_per_req =
u64::from(self.max_model_len).div_ceil(c.block_size as u64);
(
c.total_blocks as u64,
c.block_size as u64,
Some(c.total_tokens() as u64),
Some(c.total_blocks as f64 / blocks_per_req as f64),
)
}
None => (0, 16, None, None),
};
let ready = EngineCoreReadyResponse {
max_model_len: self.max_model_len as u64,
num_gpu_blocks: 0,
// TODO(#401): report the real paged-KV block size and capacity from the
// openinfer scheduler once the vLLM frontend consumes ready_response KV fields.
block_size: 16,
max_model_len: u64::from(self.max_model_len),
num_gpu_blocks,
block_size,
dp_stats_address: None,
dtype: ModelDtype::BFloat16,
vllm_version: "openinfer-local-bridge".to_string(),
// The in-process bridge fronts a single engine instance.
world_size: 1,
data_parallel_size: 1,
kv_cache_size_tokens: None,
kv_cache_max_concurrency: None,
kv_cache_size_tokens,
kv_cache_max_concurrency,
};
info!(
"local engine KV capacity: {kv_capacity:?} -> \
kv_cache_size_tokens={kv_cache_size_tokens:?} \
kv_cache_max_concurrency={kv_cache_max_concurrency:?}"
);
input
.send(ZmqMessage::from(encode_msgpack(&ready)?))
.await
Expand Down