diff --git a/studio/backend/core/training/worker.py b/studio/backend/core/training/worker.py index ef5cafb175..fa9501f58a 100644 --- a/studio/backend/core/training/worker.py +++ b/studio/backend/core/training/worker.py @@ -1084,6 +1084,17 @@ def run_training_process( 'Install for better performance: pip install "triton-windows<3.7"' ) + # ── 1d. Ensure torch.distributed.is_initialized exists before ML libs load ── + # The ROCm Windows wheel (2.9.0+rocmsdk*) does not expose is_initialized on + # the torch.distributed module object until it is explicitly imported. + # transformers and trl access it before that happens, causing AttributeError. + try: + import torch.distributed as _td # noqa: F401 -- forces full module load + if not hasattr(_td, "is_initialized"): + _td.is_initialized = lambda: False + except Exception: + pass + # ── 2. Now import ML libraries (fresh in this clean process) ── try: _send_status(event_queue, "Importing Unsloth...") diff --git a/studio/backend/utils/wheel_utils.py b/studio/backend/utils/wheel_utils.py index 3ed9bda827..06c5544f22 100644 --- a/studio/backend/utils/wheel_utils.py +++ b/studio/backend/utils/wheel_utils.py @@ -14,6 +14,7 @@ import urllib.request from typing import Callable from utils.native_path_leases import child_env_without_native_path_secret +from utils.subprocess_compat import windows_hidden_subprocess_kwargs _logger = logging.getLogger(__name__) @@ -62,6 +63,7 @@ def probe_torch_wheel_env(*, timeout: int | None = None) -> dict[str, str] | Non text = True, timeout = timeout, env = child_env_without_native_path_secret(), + **windows_hidden_subprocess_kwargs(), ) except subprocess.TimeoutExpired: return None