acceptable-football-32760
02/05/2022, 10:59 PMpytorch
which can be installed with CPU or GPU support. For tests, and having consistent local dev env, we would obviously need CPU
. For deployment to training infra, we would need GPU
.
With my limited knowldge of π I see an imperfect solution:
β’ have tags on literally every target (because we have a lot of things depending on pytorch
potentially transitively) cpu
or gpu
and duplicate those targets' code, changing only dependency on torch_cpu
vs torch_gpu
Question: is it possible, without messing tags, jsut somehow define a conditional python_requirement
, say (in pseudocode)
python_requirement(
name = "torch_1.10",
if (option == "cpu") {
requirements = ["torch @ <https://download.pytorch.org/whl/cpu/torch-1.10.0%2Bcpu-cp38-cp38-linux_x86_64.whl>"]
}
else {
requirements = ["torch @ <https://download.pytorch.org/whl/cu113/torch-1.10.0%2Bcu113-cp38-cp38-linux_x86_64.whl>"]
}
)
maybe using options or smth like that. So that the choice is made at the level of the initial requirement. Something similar to Bazel's toolchain hosts... Any ideas are welcome!
Thanks! Alexhappy-kitchen-89482
02/06/2022, 4:32 PMhappy-kitchen-89482
02/06/2022, 5:53 PMhappy-kitchen-89482
02/06/2022, 5:56 PM1.10.0-cpu
vs. 1.10.0-cu113
)happy-kitchen-89482
02/06/2022, 6:00 PMcpu
and gpu
, that differ only in that aspect (and those should be easy to create without a lot of repetition), and then your python_sources
targets are set up to be compatible with both by default, but your tests always select cpu
and your production deploy targets always select gpu
. Something like that, again @hundreds-father-404 can be far more helpful than I can...acceptable-football-32760
02/06/2022, 6:17 PMhappy-kitchen-89482
02/07/2022, 1:30 AMhappy-kitchen-89482
02/07/2022, 1:58 AMacceptable-football-32760
02/07/2022, 1:45 PMhundreds-father-404
02/07/2022, 4:46 PMutils.py
can claim to work with both the resolve pytorch-cpu
and pytorch-gpu
In the meantime, I think this might work?
1. Define two resolves with [python].resolves
, pytorch-cpu
and pytorch-gpu
. Set compatible_resolves
on each python_requirement
target to declare which requirement belongs in which resolve, including if both.
2. Change [python].default_resolve
to the one you want. You won't need to update any targets for first-party code like python_sources
, they'll use the default.
3. When you want to toggle to the other resolve, simply update [python].default_resolve
. All your first party targets will use that one without needing to change any BUILD files. FYI you can set this option via env var and CLI arg, too: https://www.pantsbuild.org/docs/options
How does that sound?hundreds-father-404
02/07/2022, 4:47 PMacceptable-football-32760
02/07/2022, 6:38 PMhundreds-father-404
02/07/2022, 6:42 PMhundreds-father-404
02/07/2022, 6:44 PMhundreds-father-404
02/08/2022, 3:55 PMpants_version = "2.10.0rc0"
You will need to set these options:
[GLOBAL]
use_deprecated_python_macros = false
[python]
enable_resolves = true
Although before setting that, first run ./pants --version
for special instructions on how to fix the deprecation with use_deprecated_python_macros
by using the update-build-files
goal.hundreds-father-404
02/08/2022, 3:56 PM