fix: install unsloth to /app/pkgs (writable), detect torch version for git extra
Browse files- training/space_runner.py +23 -15
training/space_runner.py
CHANGED
|
@@ -43,25 +43,33 @@ def _run_training():
|
|
| 43 |
# Step 1 — install unsloth on the live GPU
|
| 44 |
_training_status = "installing"
|
| 45 |
_append_log("Installing unsloth on GPU hardware...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
install_cmds = [
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
[sys.executable, "-m", "pip", "install", "--upgrade", "--no-cache-dir",
|
| 51 |
-
"unsloth[cu121-ampere-torch240] @ git+https://github.com/unslothai/unsloth.git"],
|
| 52 |
]
|
| 53 |
installed = False
|
| 54 |
for cmd in install_cmds:
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
if
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
_append_log(f"Install attempt error: {e}")
|
| 65 |
if not installed:
|
| 66 |
_training_status = "failed"
|
| 67 |
_append_log("❌ All unsloth install attempts failed. Check logs above.")
|
|
|
|
| 43 |
# Step 1 — install unsloth on the live GPU
|
| 44 |
_training_status = "installing"
|
| 45 |
_append_log("Installing unsloth on GPU hardware...")
|
| 46 |
+
|
| 47 |
+
import torch
|
| 48 |
+
tv = torch.__version__.split("+")[0].split(".") # ['2', '5', '1']
|
| 49 |
+
torch_tag = f"torch{''.join(tv[:2])}{tv[2] if tv[2] != '0' else ''}" # torch251
|
| 50 |
+
_append_log(f"PyTorch {torch.__version__} — will try extras: cu121-ampere-{torch_tag}")
|
| 51 |
+
|
| 52 |
+
# Install to /app/pkgs — always writable regardless of HF user UID
|
| 53 |
+
_PKGS = "/app/pkgs"
|
| 54 |
+
os.makedirs(_PKGS, exist_ok=True)
|
| 55 |
+
_pip_base = [sys.executable, "-m", "pip", "install", "--no-cache-dir", "--target", _PKGS]
|
| 56 |
+
|
| 57 |
install_cmds = [
|
| 58 |
+
_pip_base + ["unsloth"],
|
| 59 |
+
_pip_base + [f"unsloth[cu121-ampere-{torch_tag}] @ git+https://github.com/unslothai/unsloth.git"],
|
| 60 |
+
_pip_base + ["git+https://github.com/unslothai/unsloth.git"],
|
|
|
|
|
|
|
| 61 |
]
|
| 62 |
installed = False
|
| 63 |
for cmd in install_cmds:
|
| 64 |
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
| 65 |
+
if result.returncode == 0:
|
| 66 |
+
if _PKGS not in sys.path:
|
| 67 |
+
sys.path.insert(0, _PKGS)
|
| 68 |
+
_append_log("unsloth installed successfully.")
|
| 69 |
+
installed = True
|
| 70 |
+
break
|
| 71 |
+
err = (result.stderr or result.stdout or "")[-600:].strip()
|
| 72 |
+
_append_log(f"Install attempt failed:\n{err}")
|
|
|
|
| 73 |
if not installed:
|
| 74 |
_training_status = "failed"
|
| 75 |
_append_log("❌ All unsloth install attempts failed. Check logs above.")
|