Skip to content

Commit f0e21c4

Browse files
committed
Replaced DefaultHasher with blake3
1 parent e7d7bbf commit f0e21c4

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/llm/src/lora/rendezvous_hash.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
//! Implements Highest Random Weight (HRW) / Rendezvous hashing,
55
//! for deterministic and stable LORA-to-server assignment.
66
7-
use std::collections::hash_map::DefaultHasher;
8-
use std::hash::{Hash, Hasher};
7+
use blake3;
98

109
use crate::kv_router::protocols::WorkerWithDpRank;
1110

@@ -14,11 +13,17 @@ pub struct RendezvousHasher;
1413
impl RendezvousHasher {
1514
/// Compute a deterministic score for a LORA-worker pair
1615
pub fn compute_score(lora_name: &str, worker: WorkerWithDpRank) -> u64 {
17-
let mut hasher = DefaultHasher::new();
18-
lora_name.hash(&mut hasher);
19-
worker.worker_id.hash(&mut hasher);
20-
worker.dp_rank.hash(&mut hasher);
21-
hasher.finish()
16+
let mut hasher = blake3::Hasher::new();
17+
hasher.update(lora_name.as_bytes());
18+
hasher.update(&worker.worker_id.to_le_bytes());
19+
hasher.update(&worker.dp_rank.to_le_bytes());
20+
let hash = hasher.finalize();
21+
22+
// Extract first 8 bytes as u64
23+
let hash_bytes = hash.as_bytes();
24+
let mut bytes_array = [0u8; 8];
25+
bytes_array.copy_from_slice(&hash_bytes[..8]);
26+
u64::from_le_bytes(bytes_array)
2227
}
2328

2429
/// Rank all workers by their score for a given LORA
@@ -72,8 +77,7 @@ pub fn compute_replica_set(
7277
/// Uses linear interpolation: replicas = min + (num_workers - min) × demand
7378
///
7479
/// The maximum number of replicas is automatically determined from the number
75-
/// of available workers, Jautomatically scaling with cluster size.
76-
/// ```
80+
/// of available workers, automatically scaling with cluster size.
7781
pub fn compute_replica_factor(
7882
demand_estimate: f64,
7983
min_replicas: usize,

0 commit comments

Comments
 (0)