Siddh12334 commited on
Commit
9f4f5dc
·
verified ·
1 Parent(s): 5bd6953

fix: install unsloth to /app/pkgs (writable), detect torch version for git extra

Browse files
Files changed (1) hide show
  1. 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
- # Try PyPI release first (picks up correct CUDA extras automatically)
48
- [sys.executable, "-m", "pip", "install", "--upgrade", "--no-cache-dir", "unsloth"],
49
- # Fall back to git HEAD with cu121 extra
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
- try:
56
- result = subprocess.run(cmd, capture_output=True, text=True)
57
- if result.returncode == 0:
58
- _append_log("unsloth installed successfully.")
59
- installed = True
60
- break
61
- else:
62
- _append_log(f"Install attempt failed: {result.stderr[-500:] if result.stderr else 'no output'}")
63
- except Exception as e:
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.")