WAN2.2をDocker Containerで実行する際のDockerfile
エラー:No module named ‘transformers.modeling_layers’などの依存関係問題でハマりまくったのでメモ
# Use NVIDIA's official PyTorch image
FROM nvcr.io/nvidia/pytorch:24.10-py3
# 1. Install system tools
RUN apt-get update && apt-get install -y \
ffmpeg \
libgl1-mesa-glx \
libglib2.0-0 \
git \
&& rm -rf /var/lib/apt/lists/*
# 2. GLOBAL CONSTRAINT (Keep this!)
# Prevents NumPy 2.x and accidental Torch upgrades
RUN echo "numpy<2" > /tmp/constraints.txt
ENV PIP_CONSTRAINT="/tmp/constraints.txt"
WORKDIR /app
# 3. Upgrade pip
RUN pip install --upgrade pip
# 4. Clone repo (Clean /app ensures this works)
RUN git clone https://github.com/Wan-Video/Wan2.2.git .
# 5. Sanitize requirements.txt
# Strip everything that could cause a downgrade or conflict
RUN sed -i '/torch/d' requirements.txt && \
sed -i '/torchvision/d' requirements.txt && \
sed -i '/torchaudio/d' requirements.txt && \
sed -i '/flash-attn/d' requirements.txt && \
sed -i '/flash_attn/d' requirements.txt && \
sed -i '/opencv/d' requirements.txt && \
sed -i '/peft/d' requirements.txt && \
sed -i '/diffusers/d' requirements.txt && \
sed -i '/transformers/d' requirements.txt
# 6. MANUAL CLEANUP & INSTALL (The Solution)
# FIX: Pinned transformers to 4.48.3.
# Transformers 4.49+ removed 'modeling_layers', which crashes Peft 0.17.1.
RUN pip uninstall -y opencv-python opencv-python-headless opencv-contrib-python peft && \
rm -rf /usr/local/lib/python3.10/dist-packages/cv2 && \
rm -rf /usr/local/lib/python3.10/dist-packages/peft && \
rm -rf /usr/local/lib/python3.10/dist-packages/peft-* && \
pip install --no-cache-dir \
"opencv-python-headless==4.10.0.84" \
"transformers==4.48.3" \
"peft==0.17.1" \
"diffusers>=0.31.0" \
sentencepiece \
decord \
protobuf
# 7. Install remaining requirements
RUN pip install --no-cache-dir -r requirements.txt
# Default command
CMD ["/bin/bash"]