microscopic-knife-5995
07/01/2025, 8:58 PMpants generate-lockfiles
but as the repo grows it is taking longer and longer for the command to finish. On top of that even when the resolve finishes, I get PyTorch errors at run time (see thread).
Pragmatic solution
The pragmatic solution that I came up with is disable enable_resolves = true
in pants.toml
and use uv pip compile --universal
to generate a lock file. Then I use this generated lock file in python_requirements
.
This approach isn't as strict as directly using pants generate-lockfiles
. uv pip compile
functionality is a subset of pants generate-lockfiles
but I made this pragmatic trade off because the reality I face living in Python AI/ML ecosystem. I hope this helps other folks who are prisoners of PyTorch.
Questions and feedback
I have been doing this for a while and haven't encountered any issues. Maybe a Pants dev will shake their head and say "no no"? What could be a potential drawback of this approach?microscopic-knife-5995
07/01/2025, 8:59 PMDependency on torch not satisfied, 1 incompatible candidate found:
1.) torch 2.6+default does not have any compatible artifacts:
<https://pypi.org/torch/2.6.0%2Bdefault/torch-2.6.0%2Bdefault-cp311-cp311-manylinux1_x86_64.whl>
requirers:
via: torch==2.6.0
via: torchvision==0.21.0 -> torch==2.6.0
via: trl==0.16.1 -> accelerate>=0.34.0 -> torch>=2.0.0
happy-kitchen-89482
07/01/2025, 10:23 PMhappy-kitchen-89482
07/01/2025, 10:23 PMhappy-kitchen-89482
07/01/2025, 10:24 PMbrief-branch-21752
07/01/2025, 10:56 PMmicroscopic-knife-5995
07/01/2025, 11:44 PMuv
generates doesn't have hashes and it will resolve the version into the concrete binary at run time when it creates the venv. That's what I can think of but I would love to hear what Benjy says.happy-kitchen-89482
07/02/2025, 1:20 AMmicroscopic-knife-5995
07/02/2025, 1:40 AMpython_requirements(
name="requirements",
source="requirements.lock",
)
Where the requirements.lock
file is generated by uv pip compile --universal requirements.txt -o requirements.lock
microscopic-knife-5995
07/02/2025, 1:41 AMhappy-kitchen-89482
07/02/2025, 11:35 AMbrief-branch-21752
07/02/2025, 3:31 PMhappy-kitchen-89482
07/02/2025, 7:33 PMbrief-branch-21752
07/02/2025, 7:44 PM* Uses --hash to validate that all downloaded files are expected, which reduces the risk of supply chain attacks.
* Enforces that all transitive dependencies are in the lockfile, whereas constraints allow you to leave off dependencies. This ensures your build is more stable and reduces the risk of supply chain attacks.
* Allows you to have multiple lockfiles in your repository.
brief-branch-21752
07/02/2025, 7:45 PMhappy-kitchen-89482
07/02/2025, 8:28 PMmicroscopic-knife-5995
07/02/2025, 8:34 PMuv pip compile --universal
does specify transitive dependencies and Pants already support multiple "universes" of dependencies without having to generate a lockfile...