MCPcopy Create free account
hub / github.com/unslothai/unsloth / _probe_installed_torch_version

Function _probe_installed_torch_version

studio/install_python_stack.py:158–181  ·  view source on GitHub ↗

Return torch.__version__ from the target venv (sys.executable), or None if torch is absent/unimportable. Cross-platform (unlike probe_torch_wheel_env, which is Linux-only); mirrors the subprocess probe in _ensure_cuda_torch.

()

Source from the content-addressed store, hash-verified

156
157
158def _probe_installed_torch_version() -> str | None:
159 """Return torch.__version__ from the target venv (sys.executable), or None if
160 torch is absent/unimportable. Cross-platform (unlike probe_torch_wheel_env,
161 which is Linux-only); mirrors the subprocess probe in _ensure_cuda_torch.
162 """
163 try:
164 probe = subprocess.run(
165 [
166 sys.executable,
167 "-c",
168 "import torch, sys; sys.stdout.write(getattr(torch, '__version__', ''))",
169 ],
170 stdout = subprocess.PIPE,
171 stderr = subprocess.DEVNULL,
172 text = True,
173 timeout = 90,
174 **_windows_hidden_subprocess_kwargs(),
175 )
176 except (OSError, subprocess.TimeoutExpired):
177 return None
178 if probe.returncode != 0:
179 return None
180 lines = [line.strip() for line in (probe.stdout or "").splitlines() if line.strip()]
181 return lines[-1] if lines else None
182
183
184# constraints.txt caps new anyio resolutions at <4.14 (#6483), but an install

Callers 1

install_python_stackFunction · 0.85

Calls 2

runMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…