1

So, pytorch requires a rather large bundle of packages. The prebuilt docker pytorch gpu images (https://docs.nvidia.com/deeplearning/frameworks/pytorch-release-notes/running.html) are quite helpful in this regard.

On the other hand, uv and its lockfile are also a very handy utility.

How to marry those two? I.e. I am looking for a dockerfile, which roughly looks like

FROM nvcr.io/nvidia/pytorch:<xx.xx>-py3

# more preparation ...

RUN uv sync --locked # does NOT fetch pytorch again

# some more preparation ...

CMD ["python", "-m", ""src.main:train_model"]

or, alternatively: Is it possible to tell uv somehow that some deps, albeit mentioned in the uv.lock, are provided by the global environment which provides python and pytorch?

1 Answer 1

2

You can explicitly skip packages in the lockfile using --exclude or --no-install

FROM nvcr.io/nvidia/pytorch:<xx.xx>-py3

# more preparation ...

# Sync environment, but exclude torch-related deps already present in the base image
RUN uv sync --locked --exclude torch --exclude torchvision --exclude torchaudio

# some more preparation ...

CMD ["python", "-m", "src.main:train_model"]
Sign up to request clarification or add additional context in comments.

1 Comment

cool. And do you know how to stick to the provided python, too?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.