Configuration for KV communication and scheduling. Args: threshold (float): The threshold for the KV communication. thread_pool_workers (int): The number of threads to use for the thread pool. worker_timeout (float): The timeout for the worker.
| 7 | |
| 8 | @dataclass(frozen=True) |
| 9 | class KVCommConfig: |
| 10 | """ |
| 11 | Configuration for KV communication and scheduling. |
| 12 | |
| 13 | Args: |
| 14 | threshold (float): The threshold for the KV communication. |
| 15 | thread_pool_workers (int): The number of threads to use for the thread pool. |
| 16 | worker_timeout (float): The timeout for the worker. |
| 17 | """ |
| 18 | threshold: float = 0.3 |
| 19 | max_anchor_num: int = 20 |
| 20 | window_size: int = 5 |
| 21 | thread_pool_workers: int = 8 |
| 22 | worker_timeout: float = 30.0 |
| 23 | |
| 24 | @classmethod |
| 25 | def from_env(cls) -> "KVCommConfig": |
| 26 | """Create a config from environment variables with safe defaults.""" |
| 27 | return cls( |
| 28 | threshold=float(os.environ.get("THRESHOLD", cls.threshold)), |
| 29 | max_anchor_num=int(os.environ.get("MAX_ANCHOR_NUM", cls.max_anchor_num)), |
| 30 | window_size=int(os.environ.get("WINDOW_SIZE", cls.window_size)), |
| 31 | thread_pool_workers=int(os.environ.get("KVCOMM_THREAD_WORKERS", cls.thread_pool_workers)), |
| 32 | worker_timeout=float(os.environ.get("KVCOMM_WORKER_TIMEOUT", cls.worker_timeout)), |
| 33 | ).validate() |
| 34 | |
| 35 | def apply_overrides(self, **overrides: Any) -> "KVCommConfig": |
| 36 | """Return a copy with provided non-None fields overridden.""" |
| 37 | current: Dict[str, Any] = asdict(self) |
| 38 | for key, value in overrides.items(): |
| 39 | if value is None or key not in current: |
| 40 | continue |
| 41 | current[key] = value |
| 42 | return replace(self, **current).validate() |
| 43 | |
| 44 | def validate(self) -> "KVCommConfig": |
| 45 | """Validate value ranges and return self.""" |
| 46 | if self.thread_pool_workers <= 0: |
| 47 | raise ValueError("thread_pool_workers must be positive") |
| 48 | if self.worker_timeout <= 0: |
| 49 | raise ValueError("worker_timeout must be positive") |
| 50 | return self |
nothing calls this directly
no outgoing calls
no test coverage detected