diff --git a/amdsmi-shim/strixhalo_vram_fix.py b/amdsmi-shim/strixhalo_vram_fix.py index 4002289..e296d7c 100644 --- a/amdsmi-shim/strixhalo_vram_fix.py +++ b/amdsmi-shim/strixhalo_vram_fix.py @@ -55,8 +55,33 @@ def _get_real_vram() -> tuple[int, int] | None: return None +def _should_skip() -> bool: + """Check if we should skip the patch (lightweight/init containers).""" + # Check cgroup memory limit — if under 512Mi, skip the expensive + # torch/ROCm import. KubeRay's wait-gcs-ready init container has + # only 256Mi and importing torch+ROCm would OOMKill it. + for cgroup_mem_path in ( + "/sys/fs/cgroup/memory.max", # cgroup v2 + "/sys/fs/cgroup/memory/memory.limit_in_bytes", # cgroup v1 + ): + try: + with open(cgroup_mem_path) as f: + val = f.read().strip() + if val != "max" and int(val) < 512 * 1024 * 1024: + return True + except (OSError, ValueError): + continue + return False + + def _apply_patch() -> None: """Patch torch.cuda.mem_get_info if we detect unified memory mis-reporting.""" + if _should_skip(): + return + + if _get_real_vram() is None: + return + try: import torch if not hasattr(torch, "cuda") or not torch.cuda.is_available():