Skip to content

Commit 8acca36

Browse files
committed
Fix installation that causes torch conflict
When pip installs timm==1.0.7 (from requirements-examples.txt), it's pulling its dependencies from PyPI, and since the PyPI version of timm has a dependency on torch without any version constraints, pip is "upgrading" your nightly torch to the latest stable release from PyPI. Here's what's happening: I have torch==2.9.0.dev20250725 (nightly) installed When pip installs timm, it sees that timm requires torch Pip finds torch==2.7.1 on PyPI (the latest stable release) Since 2.9.0.dev20250725 is considered a pre-release version, pip thinks 2.7.1 is "newer" in terms of stable releases Pip uninstalls the nightly and installs the stable version.
1 parent 48e4822 commit 8acca36

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dist/
2020
ethos-u-scratch/
2121
executorch.egg-info
2222
pip-out/
23+
constraints.txt
2324

2425
# Any exported models and profiling outputs
2526
*.bin

install_executorch.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def clean():
6565
print("ccache not found, skipping ccache cleanup.")
6666
except (subprocess.CalledProcessError, FileNotFoundError):
6767
print("ccache not found, skipping ccache cleanup.")
68+
69+
shutil.rmtree("constraints.txt", ignore_errors=True)
6870

6971
print("Done cleaning build artifacts.")
7072

install_requirements.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,6 @@ def install_requirements(use_pytorch_nightly):
142142

143143

144144
def install_optional_example_requirements(use_pytorch_nightly):
145-
print("Installing packages in requirements-examples.txt")
146-
subprocess.run(
147-
[
148-
sys.executable,
149-
"-m",
150-
"pip",
151-
"install",
152-
"-r",
153-
"requirements-examples.txt",
154-
],
155-
check=True,
156-
)
157-
158145
print("Installing torch domain libraries")
159146
DOMAIN_LIBRARIES = [
160147
(
@@ -179,6 +166,43 @@ def install_optional_example_requirements(use_pytorch_nightly):
179166
)
180167

181168

169+
print("Installing packages in requirements-examples.txt")
170+
try:
171+
import torch
172+
import torchvision
173+
import torchaudio
174+
torch_version = torch.__version__
175+
torchvision_version = torchvision.__version__
176+
torchaudio_version = torchaudio.__version__
177+
except ImportError as e:
178+
print(f"Error: Required package not installed: {e}")
179+
sys.exit(1)
180+
181+
with open("constraints.txt", "w") as f:
182+
f.write(f"torch=={torch_version}\n")
183+
f.write(f"torchvision=={torchvision_version}\n")
184+
f.write(f"torchaudio=={torchaudio_version}\n")
185+
186+
# Packages in requirements-example (e.g., timm) may require torch, torchvision et
187+
# pip searches PyPI and finds torch stable release and thinks this is "newer" than your dev version
188+
# Uninstalls torch nightly and installs a stable release version, which is older.
189+
subprocess.run(
190+
[
191+
sys.executable,
192+
"-m",
193+
"pip",
194+
"install",
195+
"-r",
196+
"requirements-examples.txt",
197+
"-c",
198+
"constraints.txt",
199+
],
200+
check=True,
201+
)
202+
203+
os.remove("constraints.txt")
204+
205+
182206
# Prebuilt binaries for Intel-based macOS are no longer available on PyPI; users must compile from source.
183207
# PyTorch stopped building macOS x86_64 binaries since version 2.3.0 (January 2024).
184208
def is_intel_mac_os():

0 commit comments

Comments
 (0)