Comments (4)
I'm glad that you've found a setup that works well for you. I'm not sure how much benefit you are getting from having a multi-stage build vs. combining the poetry install
and poetry cache clear
into one RUN step, since it does not look like your builder has any additional package requirements.
The current approach taken by docker-pytorch is a result of many considerations (including the use of mamba/conda to make binary dependencies easier to manage). I have experimented with poetry a few times in the past and ran into issues as the list of dependencies got more complex. Thank you nonetheless, and I might look into the Python/Pip environment variables that you set near the top as these look like good settings for a dockerised environment.
from docker-pytorch.
Note: Please do not use poetry. I especially dont encourage it to use with torch.
This is about the old trick, of using two docker files to achieve a higher compression rate. In my case this led from a 8gb image to ~2.5GB. I would recommend copy the conda result / encironment over. This will have no effects, but e.g. the apt-get update is not required.
from docker-pytorch.
That is very interesting. Do you have some kind of link/reference describing in more detail how this works?
from docker-pytorch.
I experimented a bit and unfortunately I don't think multi-stage builds will help in this case. The Conda prefix is 7.2G, and no amount of Docker trickery will really be able to change that. Most of this space is occupied by PyTorch and its CUDA dependencies.
Here is what I tried, with no real benefit:
FROM nvidia/cuda:11.8.0-base-ubuntu22.04 as base
# Remove any third-party apt sources to avoid issues with expiring keys.
RUN rm -f /etc/apt/sources.list.d/*.list
# Install some basic utilities.
RUN apt-get update && apt-get install -y \
curl \
ca-certificates \
sudo \
git \
bzip2 \
libx11-6 \
&& rm -rf /var/lib/apt/lists/*
# Create a working directory.
RUN mkdir /app
WORKDIR /app
# Create a non-root user and switch to it.
RUN adduser --disabled-password --gecos '' --shell /bin/bash user \
&& chown -R user:user /app
RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
USER user
# All users can use /home/user as their home directory.
ENV HOME=/home/user
RUN mkdir $HOME/.cache $HOME/.config \
&& chmod -R 777 $HOME
# Set up environment variables for Conda/Mamba
ENV MAMBA_EXE=/usr/local/bin/micromamba \
MAMBA_ROOT_PREFIX=/home/user/micromamba \
CONDA_PREFIX=/home/user/micromamba \
PATH=/home/user/micromamba/bin:$PATH
#########
FROM base as builder
# Download and install Micromamba.
RUN curl -sL https://micro.mamba.pm/api/micromamba/linux-64/1.1.0 \
| sudo tar -xvj -C /usr/local bin/micromamba
# Set up the base Conda environment by installing PyTorch and friends.
COPY conda-linux-64.lock /app/conda-linux-64.lock
RUN micromamba create -qy -n base -f /app/conda-linux-64.lock \
&& rm /app/conda-linux-64.lock \
&& micromamba shell init --shell=bash --prefix="$MAMBA_ROOT_PREFIX" \
&& micromamba clean -qya
# Fix for https://github.com/pytorch/pytorch/issues/97041
RUN ln -s "$CONDA_PREFIX/lib/libnvrtc.so.11.8.89" "$CONDA_PREFIX/lib/libnvrtc.so"
#########
FROM base as final
# Copy across the Conda prefix.
COPY --from=builder $CONDA_PREFIX $CONDA_PREFIX
# Set the default command to python3.
CMD ["python3"]
from docker-pytorch.
Related Issues (20)
- this is the issue which it's showing while running the docker file HOT 2
- Cuda not found after pulling docker image at docker pull anibali/pytorch:1.4.0-cuda10.1 HOT 2
- can we have a docker image with torch 1.4+ cuda 10.2 and ubuntu 16.04 HOT 1
- Any ideas regarding reducing Image size? HOT 1
- pytorch 1.3 with cuda 10 on ubuntu 18.04 image HOT 1
- could not install software HOT 5
- Is CUDA being downloaded twice? HOT 4
- python3: can't open file 'script.py': [Errno 2] No such file or directory HOT 4
- CUDA Version Problem HOT 1
- Disable user prompt when building dockerfile HOT 1
- install HOT 1
- docker image failed to build HOT 2
- why do we use miniconda with pytorch cuda image? HOT 2
- Images to work with for Google Cloud SDK HOT 1
- About the permissions of docekr images HOT 1
- Key errors when deriving from 2.0 images & installing packages HOT 2
- How to enter the container with su mode HOT 1
- ERROR: failed to solve -> 1.7.0-cuda11.0-ubuntu20.04 HOT 1
- Support arm64 platform image HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docker-pytorch.