Docker support?
It would be nice to run this model in docker. I have docker running using WSL. I do have the buildtools and cuda toolkit on my main machine installed (I have this AI running on my machine, but want to move it to docker to make things easier). I tried to set this up, but havent get it to work yet. So any help would be appreciated since Im no docker expert by any means.
Dockerfile
FROM nvidia/cuda:12.4.0-devel-ubuntu22.04
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV TORCH_CUDA_ARCH_LIST="6.0;6.1;7.0;7.5;8.0;8.6;8.9;9.0"
# System dependencies
RUN apt-get update && apt-get install -y \
git \
python3.11 \
python3.11-dev \
python3.11-distutils \
python3-pip \
python3.11-venv \
wget \
build-essential \
libgl1-mesa-glx \
libglib2.0-0 \
ninja-build \
&& rm -rf /var/lib/apt/lists/*
# Set Python 3.11 as default
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 \
&& update-alternatives --set python3 /usr/bin/python3.11 \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 1
# Install pip for Python 3.11
RUN wget https://bootstrap.pypa.io/get-pip.py && \
python3 get-pip.py && \
rm get-pip.py
# Install PyTorch with CUDA support
RUN python3 -m pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
# Clone the repository
WORKDIR /app
RUN git clone https://github.com/Tencent/Hunyuan3D-2.git
# Install requirements
WORKDIR /app/Hunyuan3D-2
RUN python3 -m pip install --no-cache-dir -r requirements.txt
# Build custom rasterizer with explicit CUDA architecture settings
WORKDIR /app/Hunyuan3D-2/hy3dgen/texgen/custom_rasterizer
RUN python3 setup.py build_ext --inplace && python3 setup.py install
# Build differentiable renderer
WORKDIR /app/Hunyuan3D-2/hy3dgen/texgen/differentiable_renderer
RUN python3 setup.py build_ext --inplace && python3 setup.py install
# Install Gradio
WORKDIR /app/Hunyuan3D-2
RUN python3 -m pip install --no-cache-dir gradio==3.39.0
# Expose port 8080
EXPOSE 8080
# Run Gradio app on custom port
CMD ["bash", "-c", "python3 gradio_app.py --host 0.0.0.0 --port 8080 || tail -f /dev/null"]
Commands
Build it: docker build -t hunyuan3d .
Run it: docker run --gpus all -p 9000:8080 -it -v /path/to/local/models:/models hunyuan3d
Error
Unfortunately i keep running into an error
Try to load model from local path: /root/.cache/hy3dgen/tencent/Hunyuan3D-2/hunyuan3d-dit-v2-0
Model path not exists, try to download from huggingface
Fetching 48 files: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 48/48 [00:00<00:00, 26822.09it/s]
bash: line 1: 27 Killed python3 gradio_app.py --host 0.0.0.0 --port 8080
Hi,
Thanks for sharing the Dockerfile. It was very close to functional for me under podman running on linux but The pinned gradio version of 3.39.0 is incompatible with the latest gradio_app.py. The latest version seems to work very well.
Additionally, text 2 3d capability must be explicitly enabled. Here is a diff of the changes that make it fully functional for me. Note that this adds a bit of space but only approximately 34g are required in total.
--- Dockerfile.github 2025-03-20 16:20:14.336109005 -0600
+++ Dockerfile 2025-03-20 17:41:09.676421672 -0600
@@ -50,10 +50,13 @@
# Install Gradio
WORKDIR /app/Hunyuan3D-2
-RUN python3 -m pip install --no-cache-dir gradio==3.39.0
+RUN python3 -m pip install --no-cache-dir gradio
+
+# Install text to 3d requirements
+RUN python3 -m pip install --no-cache-dir sentencepiece
# Expose port 8080
EXPOSE 8080
# Run Gradio app on custom port
-CMD ["bash", "-c", "python3 gradio_app.py --host 0.0.0.0 --port 8080 || tail -f /dev/null"]
+CMD ["bash", "-c", "python3 gradio_app.py --enable_t23d --host 0.0.0.0 --port 8080 || tail -f /dev/null"]
It's also important to note that /models doesn't appear to be used by default but /root/.cache is where the huggingface models are stored. I used a command like this for testing: podman run --gpus all -network=pasta:-t,9000:8080 -it -v ./cache:/root/.cache -v ./models:/models hunyuan3d.
Regarding your WSL woes, could you be hitting resource limits somewhere? I think you might need to scour your docker and windows event logs to diagnose your problem.
Ghost thanks for sharing your code. I got it to build but the gradio app won't load in the browser. The Docker log says it requests /manifest.json but it is not found.
edit:
I found the problem: https://github.com/Tencent-Hunyuan/Hunyuan3D-2/pull/296
I fixed it by running the following command in console in the folder containing grapio_app.py:
sed -i 's|app = gr.mount_gradio_app(app, demo, path="/")|app = gr.mount_gradio_app(app, demo, path="")|' gradio_app.py
Folder with grapio_app.py:
root@9127afe2bc15:/app/Hunyuan3D-2# ls -al total 224 drwxr-xr-x 1 root root 4096 Aug 19 07:59 . drwxr-xr-x 1 root root 4096 Aug 18 14:58 .. drwxr-xr-x 8 root root 4096 Aug 18 14:58 .git -rw-r--r-- 1 root root 3441 Aug 18 14:58 .gitignore -rw-r--r-- 1 root root 596 Aug 18 14:58 .readthedocs.yaml -rw-r--r-- 1 root root 16993 Aug 18 14:58 LICENSE -rw-r--r-- 1 root root 32065 Aug 18 14:58 NOTICE -rw-r--r-- 1 root root 18798 Aug 18 14:58 README.md -rw-r--r-- 1 root root 10231 Aug 18 14:58 README_ja_jp.md -rw-r--r-- 1 root root 11719 Aug 18 14:58 README_zh_cn.md -rw-r--r-- 1 root root 11066 Aug 18 14:58 api_server.py drwxr-xr-x 8 root root 4096 Aug 18 14:58 assets -rw-r--r-- 1 root root 13508 Aug 18 14:58 blender_addon.py drwxr-xr-x 3 root root 4096 Aug 18 14:58 docs drwxr-xr-x 2 root root 4096 Aug 18 14:58 examples -rwxr-xr-x 1 root root 30987 Aug 19 07:59 gradio_app.py drwxr-xr-x 5 root root 4096 Aug 19 08:26 gradio_cache drwxr-xr-x 1 root root 4096 Aug 19 07:39 hy3dgen -rw-r--r-- 1 root root 1555 Aug 18 14:58 minimal_demo.py -rw-r--r-- 1 root root 805 Aug 18 14:58 minimal_vae_demo.py -rw-r--r-- 1 root root 387 Aug 18 14:58 requirements.txt -rw-r--r-- 1 root root 1625 Aug 18 14:58 setup.py root@9127afe2bc15:/app/Hunyuan3D-2#