Skip to content

Commit 8334541

Browse files
fix: KeyError in kv_router.py by Initializing active_blocks_dict for New Workers (#1827)
Co-authored-by: Yan Ru Pei <yanrpei@gmail.com>
1 parent 7ba0575 commit 8334541

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

examples/llm/components/kv_router.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ def _update_and_get_active_blocks(self, worker_id: str, polled_value: int) -> in
185185
This allows the router to account for requests that have been dispatched but
186186
not yet reflected in the polled metrics.
187187
"""
188+
# Initialize if worker_id is not present
189+
if worker_id not in self.active_blocks_dict:
190+
logger.warning(f"New Worker added: {worker_id}")
191+
self.active_blocks_dict[worker_id] = [polled_value, polled_value]
192+
return polled_value
193+
188194
old_value, predictive_value = self.active_blocks_dict[worker_id]
189195

190196
# Check if polled value is different from old value

0 commit comments

Comments
 (0)