Optimize Docker performance and storage
mainCache HuggingFace Models
To avoid re-downloading models on every run, mount your host's HuggingFace cache directory to the container's cache directory:
docker run -it --rm \
-e HUGGINGFACE_TOKEN=your_token \
-v /path/on/host/huggingface_cache:/root/.cache/huggingface \
layerskip:latest \
python generate.py --helpOptimize Docker Layers
- Leverage Caching: Copy
requirements.txtand install dependencies before copying the rest of the source code. - Combine RUN Commands: Reduce layer count by combining commands:
RUN conda install pytorch==2.2.1 torchvision==0.17.1 torchaudio==2.2.1 cpuonly -c pytorch -y && \
pip install --upgrade pip && \
pip install --no-cache-dir -r /app/requirements.txt