echoing-farmer-15630
05/05/2022, 12:55 PMjax , that needs some extras in most contexts (jax[cpu]) and in one particular context needs different extras (jax[mystical_cuda_requirements]). Honestly this should be true for torch as well but the cuda/cpu builds there are hellacious (and this is why we can't have nice things like sub-2GB containers).
Anyway.
We have pinned versions of packages in a constraints file, but at least a while ago you couldn't put extras in there (haven't tried again under the new resolvers). I generate a python_requirements based on that constraints.txt file, but if I have jax in the constraints file, it creates a target without any extras which does no one any good.
I can't figure out how to have extras in a python_requirements rule, so I have a separate requirement as
python_requirement(
name="jax", requirements=["jax[cpu]==0.3.10"], modules=["jax", "jaxlib"]
)
...and my guess for when I need the cuda version is to create a name="jaxcuda" which also provides the same modules and resolve in the necessary target. Maybe.
Is there a clean way to handle this sort of situation? I scanned the documentation but got mildly confused... I'd really prefer a "use the CPU unless specifically declared otherwise" rather than two separate "jax" targets which have to be resolved for every client target if we can...bitter-ability-32190
05/05/2022, 12:57 PMbitter-ability-32190
05/05/2022, 12:57 PMechoing-farmer-15630
05/05/2022, 1:10 PMechoing-farmer-15630
05/05/2022, 1:28 PMpython_requirement and list that in the dependencies for the one target which needs cuda?bitter-ability-32190
05/05/2022, 1:28 PMbitter-ability-32190
05/05/2022, 1:29 PMAny suggestions on the "changed extra" there when I need the cuda requirements in only some cases?I'm told that's a key feature for
paramterize but admittedly I haven't put all the pieces together in my head.echoing-farmer-15630
05/05/2022, 1:30 PMbitter-ability-32190
05/05/2022, 1:30 PMechoing-farmer-15630
05/05/2022, 1:33 PMpip ... -c constraints.txt and so pip still doesn't handle that. Eh, I'll do my workaround for now (I can't use pexes for docker builds because some of my folks use macs and I don't have the bandwidth right now to generate requirements.txt files via pants for each dockerfile to use). Thanks, though, will make notes that this is handled.bitter-ability-32190
05/05/2022, 1:34 PM.txt pip-style files.bitter-ability-32190
05/05/2022, 1:34 PMpex3 lock create I thinkechoing-farmer-15630
05/05/2022, 1:36 PMhundreds-father-404
05/05/2022, 2:56 PMpython_sources(
resolve=parametrize("python-gpu", "python-cpu"),
)
--
There is another workaround which I honestly might suggest you do...just thought of this one.
In your BUILD file, have a python_requirement target for the CPU version and a different one for GPU. Comment out whichever one you are not using
You can maintain two lockfiles in a kind of hacky way, update [python].resolves to point to python.cpu.lock vs python.gpu.lock, for example. When you want to change, you'll comment out the target you don't want, and update [python].resolves in pants.toml
There are some ways we could make that slightly less hacky, like you write a target generator that will inspect [python].resolves option and decide based on that whether to give you the CPU or GPU version
I don't love how hacky this all is, but might honestly be better than multiple resolves. Multiple resolves are super powerful, but do have additional cognitive overhead
https://www.pantsbuild.org/docs/python-third-party-dependencies#multiple-lockfilesechoing-farmer-15630
05/05/2022, 4:05 PMhundreds-father-404
05/05/2022, 4:07 PM"two different jax target definitions and now every time something needs jax you need to specify which one"That is a major benefit of multiple resolves: no more "ambiguous dependency" warnings! Pants only infers deps on things that share the same resolve But yeah, users would need to mark whether something is
resolve=parametrize("cpu", "gpu") vs just one of those two, which is a pain. (My priority this week is improving error message for that, at least)