Spaces:
Running
Running
Download lpu/core/execution_policy.py from iparaco/Virtual-LPU: direct link, hf CLI and curl.
- Browser
- Download file 2.68 kB
-
https://huggingface.co/spaces/iparaco/Virtual-LPU/resolve/refs%2Fpr%2F2/lpu/core/execution_policy.py
- Command line
-
hf download hf://spaces/iparaco/Virtual-LPU@refs/pr/2/lpu/core/execution_policy.py
-
curl -L -o execution_policy.py https://huggingface.co/spaces/iparaco/Virtual-LPU/resolve/refs%2Fpr%2F2/lpu/core/execution_policy.py
2.68 kB
| """Execution policy: PERFORMANCE | BALANCED | EFFICIENCY. | |
| A policy is a set of decision thresholds, not marketing words. Every knob | |
| below has a consumer in the scheduler/monitor and changes real behavior: | |
| - probe_iterations: how many real micro-benchmark iterations run when | |
| choosing a strategy / precision. | |
| - strategy aggressiveness: PERFORMANCE may test model_parallel for large | |
| models; EFFICIENCY never leaves single-GPU unless VRAM forces it. | |
| - monitoring frequency: PERFORMANCE samples GPU state less often during | |
| training (less overhead); EFFICIENCY idles at the slowest safe rate. | |
| """ | |
| from __future__ import annotations | |
| from dataclasses import dataclass | |
| from enum import Enum | |
| from typing import Dict | |
| class PerformanceMode(str, Enum): | |
| PERFORMANCE = "performance" | |
| BALANCED = "balanced" | |
| EFFICIENCY = "efficiency" | |
| class Policy: | |
| mode: PerformanceMode | |
| probe_iterations: int | |
| model_parallel_min_param_mb: float # below this, model split is refused | |
| allow_strategy_probe: bool # measure DP vs single at startup | |
| monitor_active_seconds: float | |
| monitor_idle_seconds: float | |
| min_dp_batch_per_gpu: int # DP pointless below this per-GPU batch | |
| allow_ddp_auto: bool # DDP may win a probe and be selected | |
| POLICIES: Dict[PerformanceMode, Policy] = { | |
| PerformanceMode.PERFORMANCE: Policy( | |
| mode=PerformanceMode.PERFORMANCE, | |
| probe_iterations=12, | |
| model_parallel_min_param_mb=200.0, | |
| allow_strategy_probe=True, | |
| monitor_active_seconds=1.0, | |
| monitor_idle_seconds=5.0, | |
| min_dp_batch_per_gpu=2, | |
| allow_ddp_auto=False, # Windows gloo reliability: opt-in only, always | |
| ), | |
| PerformanceMode.BALANCED: Policy( | |
| mode=PerformanceMode.BALANCED, | |
| probe_iterations=6, | |
| model_parallel_min_param_mb=400.0, | |
| allow_strategy_probe=True, | |
| monitor_active_seconds=2.0, | |
| monitor_idle_seconds=10.0, | |
| min_dp_batch_per_gpu=4, | |
| allow_ddp_auto=False, | |
| ), | |
| PerformanceMode.EFFICIENCY: Policy( | |
| mode=PerformanceMode.EFFICIENCY, | |
| probe_iterations=0, # no probing overhead at all | |
| model_parallel_min_param_mb=1e9, | |
| allow_strategy_probe=False, | |
| monitor_active_seconds=5.0, | |
| monitor_idle_seconds=30.0, | |
| min_dp_batch_per_gpu=8, | |
| allow_ddp_auto=False, | |
| ), | |
| } | |
| def get_policy(mode: str) -> Policy: | |
| try: | |
| return POLICIES[PerformanceMode(str(mode).lower())] | |
| except KeyError: | |
| raise ValueError( | |
| f"unknown performance mode {mode!r}; valid: {[m.value for m in PerformanceMode]}" | |
| ) | |