Skip to content

Commit 86c79ba

Browse files
committed
some prelim cleanups
1 parent 3e3c3b1 commit 86c79ba

File tree

5 files changed

+38
-40
lines changed

5 files changed

+38
-40
lines changed

lib/llm/src/kv_router.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ pub mod scoring;
2525

2626
use crate::{
2727
kv_router::{
28-
indexer::{KvIndexer, KvIndexerInterface, RouterEvent},
28+
indexer::{KvIndexer, KvIndexerInterface},
2929
metrics_aggregator::KvMetricsAggregator,
30-
protocols::{LocalBlockHash, RouterRequest, RouterResponse, WorkerSelectionResult},
30+
protocols::{
31+
LocalBlockHash, RouterEvent, RouterRequest, RouterResponse, WorkerSelectionResult,
32+
},
3133
scheduler::{KvScheduler, KvSchedulerError, SchedulingRequest},
3234
scoring::ProcessedEndpoints,
3335
},

lib/llm/src/kv_router/indexer.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ pub enum KvRouterError {
7777
IndexerDroppedRequest,
7878
}
7979

80-
/// Identifier of a LLM worker which emits events to the router.
81-
pub type WorkerId = i64;
82-
8380
/// A shared reference to a [`RadixBlock`].
8481
type SharedRadixBlock = Rc<RefCell<RadixBlock>>;
8582

@@ -133,31 +130,6 @@ pub fn compute_block_hash_for_seq(tokens: &[u32], kv_block_size: usize) -> Vec<L
133130
.collect()
134131
}
135132

136-
/// A [`KvCacheEvent`] on a specific LLM worker denoted by [`WorkerId`].
137-
#[derive(Debug, Clone, Serialize, Deserialize)]
138-
pub struct RouterEvent {
139-
/// The ID of the worker emitting the event.
140-
worker_id: WorkerId,
141-
/// The cache event associated with the worker.
142-
event: KvCacheEvent,
143-
}
144-
145-
impl RouterEvent {
146-
/// Create a new `RouterEvent`.
147-
///
148-
/// ### Arguments
149-
///
150-
/// * `worker_id` - The ID of the worker emitting the event.
151-
/// * `event` - The cache event.
152-
///
153-
/// ### Returns
154-
///
155-
/// A new `RouterEvent`.
156-
pub fn new(worker_id: WorkerId, event: KvCacheEvent) -> Self {
157-
Self { worker_id, event }
158-
}
159-
}
160-
161133
/// A block in the Radix Tree.
162134
#[derive(Debug)]
163135
struct RadixBlock {

lib/llm/src/kv_router/protocols.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ pub struct RouterRequest {
2121
pub tokens: Vec<Token>,
2222
}
2323

24+
/// Identifier of a LLM worker which emits events to the router.
25+
pub type WorkerId = i64;
26+
2427
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
2528
pub struct RouterResponse {
26-
pub worker_id: i64,
29+
pub worker_id: WorkerId,
2730
}
2831

2932
#[derive(Debug)]
3033
pub struct WorkerSelectionResult {
3134
/// The worker id of the selected worker
32-
pub worker_id: i64,
35+
pub worker_id: WorkerId,
3336

3437
/// The total number of blocks required to prefill the request
3538
pub required_blocks: u64,
@@ -58,14 +61,14 @@ pub struct ForwardPassMetrics {
5861

5962
/// A [`LocalBlockHash`] is a hash computed from the tokens_ids, extra_token_ids and the optional
6063
/// lora_id of a block.
61-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
64+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
6265
pub struct LocalBlockHash(pub u64);
6366

6467
/// A sequence aware hash of a block where the hash is computed from the tokens_ids, extra_token_ids
6568
/// and the optional lora_id of a block, PLUS the hash of the parent block.
6669
///
6770
/// In this case, the hashing function is external and unknown.
68-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
71+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
6972
pub struct ExternalSequenceBlockHash(pub u64);
7073

7174
// Implement From trait for convenient conversion
@@ -138,6 +141,31 @@ pub struct KvCacheRemoveData {
138141
pub block_hashes: Vec<ExternalSequenceBlockHash>,
139142
}
140143

144+
/// A [`KvCacheEvent`] on a specific LLM worker denoted by [`WorkerId`].
145+
#[derive(Debug, Clone, Serialize, Deserialize)]
146+
pub struct RouterEvent {
147+
/// The ID of the worker emitting the event.
148+
pub worker_id: WorkerId,
149+
/// The cache event associated with the worker.
150+
pub event: KvCacheEvent,
151+
}
152+
153+
impl RouterEvent {
154+
/// Create a new `RouterEvent`.
155+
///
156+
/// ### Arguments
157+
///
158+
/// * `worker_id` - The ID of the worker emitting the event.
159+
/// * `event` - The cache event.
160+
///
161+
/// ### Returns
162+
///
163+
/// A new `RouterEvent`.
164+
pub fn new(worker_id: WorkerId, event: KvCacheEvent) -> Self {
165+
Self { worker_id, event }
166+
}
167+
}
168+
141169
impl Serialize for LocalBlockHash {
142170
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
143171
where

lib/llm/src/kv_router/publisher.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
// limitations under the License.
1515

1616
use crate::kv_router::{
17-
indexer::{compute_block_hash_for_seq, RouterEvent},
18-
protocols::*,
19-
KV_EVENT_SUBJECT, KV_METRICS_ENDPOINT,
17+
indexer::compute_block_hash_for_seq, protocols::*, KV_EVENT_SUBJECT, KV_METRICS_ENDPOINT,
2018
};
2119
use async_trait::async_trait;
2220
use dynamo_runtime::traits::{events::EventPublisher, DistributedRuntimeProvider, RuntimeProvider};

lib/llm/src/kv_router/recorder.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
use crate::kv_router::indexer::RouterEvent;
16+
use crate::kv_router::protocols::*;
1717
use crate::recorder::Recorder;
1818

1919
// Type alias for backward compatibility
@@ -23,8 +23,6 @@ pub type KvRecorder = Recorder<RouterEvent>;
2323
mod tests {
2424
use super::*;
2525
use crate::kv_router::indexer::KvIndexer;
26-
use crate::kv_router::indexer::WorkerId;
27-
use crate::kv_router::protocols::*;
2826
use std::time::Duration;
2927
use tempfile::tempdir;
3028
use tokio::fs;

0 commit comments

Comments
 (0)