Resolve (sliding_window, global_ratio) for honored SWA architectures. Returns (None, None) for every model outside the allowlist so the KV estimate stays at full context (conservative).
(
config: dict, model_id: str, gguf_arch: str | None = None
)
| 257 | |
| 258 | |
| 259 | def _resolve_sliding_window( |
| 260 | config: dict, model_id: str, gguf_arch: str | None = None |
| 261 | ) -> tuple[int | None, float | None]: |
| 262 | """Resolve (sliding_window, global_ratio) for honored SWA architectures. |
| 263 | |
| 264 | Returns (None, None) for every model outside the allowlist so the KV |
| 265 | estimate stays at full context (conservative). |
| 266 | """ |
| 267 | # Respect an explicit opt-out before doing any work. |
| 268 | if config.get("use_sliding_window") is False: |
| 269 | return None, None |
| 270 | |
| 271 | key = _swa_arch_key(config, model_id, gguf_arch) |
| 272 | if key is None: |
| 273 | return None, None |
| 274 | |
| 275 | default_window, default_ratio = _SWA_ARCH_DEFAULTS[key] |
| 276 | |
| 277 | window = config.get("sliding_window") |
| 278 | if not isinstance(window, int) or window <= 0: |
| 279 | window = default_window |
| 280 | |
| 281 | pattern = config.get("sliding_window_pattern") |
| 282 | if isinstance(pattern, int) and pattern > 0: |
| 283 | global_ratio = 1.0 / pattern |
| 284 | else: |
| 285 | global_ratio = default_ratio |
| 286 | |
| 287 | return window, global_ratio |
| 288 | |
| 289 | |
| 290 | def _normalize_param_count( |
no test coverage detected