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
109use crate :: kv_router:: protocols:: WorkerWithDpRank ;
1110
@@ -14,11 +13,17 @@ pub struct RendezvousHasher;
1413impl 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.
7781pub fn compute_replica_factor (
7882 demand_estimate : f64 ,
7983 min_replicas : usize ,
0 commit comments