colossal-pilot-94395
05/22/2023, 3:47 PMboundless-ambulance-11161
05/22/2023, 4:21 PMhappy-kitchen-89482
05/22/2023, 4:26 PMpytorch
should yield some workarounds.boundless-ambulance-11161
05/22/2023, 4:45 PMbase_requirements.txt
file with the loose requirements (numpy >= 1.21.5, < 2.0.0
).
Our installation script export it to a lockfile base_requirements.lock
using directly pex
if any of those requirements has changed (or we called the script with a --force
flag). This can be done on any environment, so we make no assumption about which version of torch is in it. To check whether the requirements changed: I read the current lockfile, filter out the header, load the rest with json into a dictionary lock_d
, compare lock_d["requirements"]
with base_requirements.txt
.
Our installation script then extract the pinned version of every package (including transitive dependencies), by accessing lock_d["locked_resolves"][0]["locked_requirements"]
. The version of torch and torchvision need to be parsed because they may contain a "+cpu". It writes three requirements file linux_cpu.txt
, linux_gpu.txt
and macos_cpu.txt
by dumping the pinned requirements and only changing the versions for torch
and torchvision
.
Use pex
to generate the lockfiles for these three requirements (if they have changed compared to the last time they were generated). This part looks like this:
requirements_path = REQUIREMENTS_DIR / f"{resolve_name}.txt"
lockfile_path = LOCKFILES_DIR / f"{resolve_name}.lock"
pex_cmd = [
"pex3", "lock", "create",
"--index-url", "<https://pypi.org/simple/>",
"--style", "universal",
"--resolver-version", "pip-2020-resolver",
"--interpreter-constraint", python_constraint,
"-r", str(requirements_path),
"-o", str(lockfile_path),
"--pex-root", str(pex_root),
"--jobs", "6",
]
for target_system in target_systems:
pex_cmd += ["--target-system", target_system]
for index_url in extra_index_urls:
pex_cmd += ["--index-url", index_url]
pex_cmd_str = " ".join(pex_cmd)
<http://LOG.info|LOG.info>(f"Run {pex_cmd_str}")
subprocess.run(pex_cmd)
We automatically create symbolic links mapping default.txt
to either linux_cpu.txt
, linux_gpu.txt
or macos_cpu.txt
depending on the platform detected by python and the availability of CUDA according to nvidia-smi
. Similarly, the script creates default.lock
to one of the three lockfile. If those links already exist, we don't overwrite them (in case a developer has cuda but wants to work with cpu only, they only need to change the symbolic link once).
The path of those 2 symbolic links are added to .gitignore
to avoid sharing them in git.
There may be a better way to do it (I'm still kinda new to pants) and I certainly hope there will be a cleaner/standard way to do it in the near future.happy-kitchen-89482
05/22/2023, 4:47 PMhappy-kitchen-89482
05/22/2023, 4:47 PMcolossal-pilot-94395
05/22/2023, 5:18 PMboundless-ambulance-11161
05/22/2023, 7:47 PMpex
.busy-vase-39202
05/22/2023, 8:56 PMcolossal-pilot-94395
05/23/2023, 8:19 AM