Skip to content

Commit b2f55c3

Browse files
committed
feat(agent): 优化Docker全流程,新增Docker启动脚本.
1 parent 704fda9 commit b2f55c3

8 files changed

Lines changed: 246 additions & 63 deletions

File tree

Dockerfile

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,51 @@
1-
# Stage 1: Base environment build
2-
FROM ubuntu:22.04 as builder
1+
# Copyright 2025 IDDM Authors
32

4-
# Disable interactive prompts and configure time zone
5-
ENV DEBIAN_FRONTEND=noninteractive \
6-
TZ=Etc/UTC
7-
8-
# Install apt-get dependencies
9-
RUN apt-get update && \
10-
apt-get install -y --no-install-recommends ca-certificates wget git openssh-client && \
11-
rm -rf /var/lib/apt/lists/*
12-
13-
# Install Miniconda
14-
ARG MINICONDA_VERSION=py310_25.1.1-2
15-
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-${MINICONDA_VERSION}-Linux-x86_64.sh -O ~/miniconda.sh && \
16-
/bin/bash ~/miniconda.sh -b -p /opt/conda && \
17-
rm ~/miniconda.sh
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
186

19-
# Set conda environment
20-
ENV PATH=/opt/conda/bin:$PATH
7+
# http://www.apache.org/licenses/LICENSE-2.0
218

22-
# Stage 2: App deployment
23-
FROM ubuntu:22.04
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
2414

25-
# Copy necessary content from the stage 1 (builder)
26-
COPY --from=builder /opt/conda /opt/conda
15+
# Use NVIDIA CUDA base image for GPU support
16+
FROM nvidia/cuda:12.8.0-cudnn-runtime-ubuntu22.04
17+
# For China region
18+
# FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nvidia/cuda:12.8.0-cudnn-runtime-ubuntu22.04
2719

28-
# Set environment variables
29-
ENV PATH=/opt/conda/bin:$PATH \
20+
# Disable interactive prompts and configure time zone
21+
ENV DEBIAN_FRONTEND=noninteractive \
22+
TZ=Etc/UTC \
3023
LANG=C.UTF-8 \
3124
PYTHONUNBUFFERED=1
3225

33-
# Git clone the repository
26+
# Install system dependencies
27+
RUN apt-get update && \
28+
apt-get install -y --no-install-recommends python3 python3-pip git && \
29+
rm -rf /var/lib/apt/lists/* && \
30+
ln -sf /usr/bin/python3 /usr/bin/python
31+
32+
# Clone the repository
3433
RUN git clone --depth 1 https://github.com/chairc/Integrated-Design-Diffusion-Model.git /app
34+
# For China region
35+
# RUN git clone --depth 1 https://gitee.com/chairc/Integrated-Design-Diffusion-Model.git /app
3536

3637
# Set working directory
3738
WORKDIR /app
3839

39-
# Install (conda + pip)
40-
# If pip is not available, use conda
41-
RUN conda install -y pytorch=1.13.0 torchvision=0.14.0 torchaudio=0.13.0 pytorch-cuda=11.8 -c pytorch -c nvidia && \
42-
conda clean -ya
43-
44-
# If conda is not available, use pip
45-
# RUN pip install torch==1.13.0+cu116 torchvision==0.14.0+cu116 -f https://download.pytorch.org/whl/torch_stable.html
40+
# Install PyTorch (compatible with CUDA 12.8)
41+
RUN pip install torch==2.7.0 torchvision==0.22.0 torchaudio==2.7.0 --index-url https://download.pytorch.org/whl/cu128
42+
# For China region
43+
# RUN pip install torch==2.7.0 torchvision==0.22.0 torchaudio==2.7.0 --index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
4644

47-
RUN cd /app/Integrated-Design-Diffusion-Model && \
48-
pip install -r requirements.txt && \
49-
pip cache purge
45+
# Install project dependencies
46+
RUN pip install --no-cache-dir --trusted-host pypi.org --trusted-host files.pythonhosted.org --no-deps -r requirements.txt
47+
# For China region
48+
# RUN pip install --no-cache-dir -r requirements.txt --index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
5049

5150
# Verify installation
5251
RUN python -c "import torch; print(f'PyTorch version: {torch.__version__}')" && \

README.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ python train.py --xxx xxx # Replace --xxx with your training parameters
8282
python generate.py --xxx xxx # Replace --xxx with your generation parameters
8383
```
8484

85+
#### Docker Running
86+
87+
Modification contents, please refer to the `docker_run.sh` script.
88+
89+
```bash
90+
# Mount and build the entire project
91+
bash docker_run.sh -a /path/to/project
92+
# Mount and build specified paths
93+
bash docker_run.sh \
94+
-d /path/to/datasets \
95+
-r /path/to/results \
96+
-w /path/to/weights
97+
```
98+
99+
`/path/to/project`, `/path/to/datasets`, `/path/to/results` and `/path/to/weights` are local paths, used to mount the full project, dataset, result and weight directories respectively.
100+
85101
#### Installation
86102

87103
In addition to running locally, there are also the following two approachs for installing this code.
@@ -96,19 +112,19 @@ The following packages are required.
96112

97113
```yaml
98114
coloredlogs==15.0.1
99-
gradio>=6.0.0
115+
gradio==6.0.0
100116
matplotlib==3.7.1
101-
numpy>=1.25.0
102-
Pillow>=12.2.0
103-
Requests>=2.32.4
117+
numpy==1.25.0
118+
Pillow==12.2.0
119+
Requests==2.32.4
104120
scikit-image==0.22.0
105121
torch_summary==1.4.5
106122
tqdm==4.66.3
107123
pytorch_fid==0.3.0
108124
fastapi==0.115.6
109125
tensorboard==2.19.0
110126
tensorboardX==2.6.1
111-
transformers>=5.0.0
127+
transformers==5.0.0
112128

113129
# If you want to use flash attention, please install flash-attn.
114130
# Compile your own environment: pip install flash-attn --no-build-isolation

README_zh.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ python train.py --xxx xxx # 用个人参数替换-xxx
8282
python generate.py --xxx xxx # 用个人参数替换-xxx
8383
```
8484

85+
#### Docker运行
86+
87+
运行`构建脚本+运行容器`bash脚本,详细修改内容请参考`docker_run.sh`脚本,如遇下载问题请修改`Dockerfile`的中国区域下载地址
88+
89+
```bash
90+
# 构建项目挂载
91+
bash docker_run.sh -a /path/to/project
92+
# 构建指定路径挂载
93+
bash docker_run.sh \
94+
-d /path/to/datasets \
95+
-r /path/to/results \
96+
-w /path/to/weights
97+
```
98+
99+
其中,`/path/to/project``/path/to/datasets``/path/to/results``/path/to/weights`为本地的路径,用于挂载全项目、数据集、结果和权重目录
100+
85101
#### 安装
86102

87103
除了本地运行外,也可采用下列两种方式安装本代码
@@ -96,19 +112,19 @@ pip install iddm
96112

97113
```yaml
98114
coloredlogs==15.0.1
99-
gradio>=6.0.0
115+
gradio==6.0.0
100116
matplotlib==3.7.1
101-
numpy>=1.25.0
102-
Pillow>=12.2.0
103-
Requests>=2.32.4
117+
numpy==1.25.0
118+
Pillow==12.2.0
119+
Requests==2.32.4
104120
scikit-image==0.22.0
105121
torch_summary==1.4.5
106122
tqdm==4.66.3
107123
pytorch_fid==0.3.0
108124
fastapi==0.115.6
109125
tensorboard==2.19.0
110126
tensorboardX==2.6.1
111-
transformers>=5.0.0
127+
transformers==5.0.0
112128

113129
# 如果您想使用 flash attention,请安装 flash-attn
114130
# 编译自己的环境:pip install flash-attn --no-build-isolation

docker_run.sh

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/bin/bash
2+
3+
# Copyright 2025 IDDM Authors
4+
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -e
18+
19+
IMAGE_NAME="iddm-image"
20+
CONTAINER_NAME="iddm-container"
21+
22+
HOST_DATASET_DIR=""
23+
HOST_OUTPUT_DIR=""
24+
HOST_WEIGHT_DIR=""
25+
HOST_PROJECT_DIR=""
26+
27+
show_help() {
28+
echo "Usage: bash docker_run.sh [options]"
29+
echo ""
30+
echo "Options:"
31+
echo " -a, --all Host project root directory (mapped to /app)"
32+
echo " -d, --dataset Host dataset directory (mapped to /app/datasets)"
33+
echo " -r, --result Host result directory (mapped to /app/results)"
34+
echo " -w, --weight Host weight directory (mapped to /app/weights)"
35+
echo " -b, --build Only build image, do not run container"
36+
echo " -h, --help Show this help message"
37+
echo ""
38+
echo "Example:"
39+
echo " bash docker_run.sh -a /home/user/project"
40+
echo " bash docker_run.sh -d /home/user/datasets -r /home/user/results -w /home/user/weights"
41+
}
42+
43+
while [[ $# -gt 0 ]]; do
44+
case "$1" in
45+
-a|--all)
46+
HOST_PROJECT_DIR="$2"; shift 2 ;;
47+
-d|--dataset)
48+
HOST_DATASET_DIR="$2"; shift 2 ;;
49+
-r|--result)
50+
HOST_OUTPUT_DIR="$2"; shift 2 ;;
51+
-w|--weight)
52+
HOST_WEIGHT_DIR="$2"; shift 2 ;;
53+
-b|--build)
54+
BUILD_ONLY=true; shift ;;
55+
-h|--help)
56+
show_help; exit 0 ;;
57+
*)
58+
echo "Unknown option: $1"; show_help; exit 1 ;;
59+
esac
60+
done
61+
62+
echo "=============================="
63+
echo " Step 1: Building Docker image"
64+
echo "=============================="
65+
sudo docker build -t "${IMAGE_NAME}" .
66+
echo "Image '${IMAGE_NAME}' built successfully."
67+
echo ""
68+
69+
if [ "${BUILD_ONLY}" = true ]; then
70+
echo "Build-only mode. Exiting."
71+
exit 0
72+
fi
73+
74+
MOUNT_ARGS=""
75+
if [ -n "${HOST_PROJECT_DIR}" ]; then
76+
if [ -n "${HOST_DATASET_DIR}" ] || [ -n "${HOST_OUTPUT_DIR}" ] || [ -n "${HOST_WEIGHT_DIR}" ]; then
77+
echo "Warning: -a/--all is specified, individual mounts (-d/-r/-w) will be ignored."
78+
fi
79+
mkdir -p "${HOST_PROJECT_DIR}"
80+
MOUNT_ARGS="${MOUNT_ARGS} -v ${HOST_PROJECT_DIR}:/app"
81+
echo "Mount project: ${HOST_PROJECT_DIR} -> /app"
82+
else
83+
if [ -n "${HOST_DATASET_DIR}" ]; then
84+
mkdir -p "${HOST_DATASET_DIR}"
85+
MOUNT_ARGS="${MOUNT_ARGS} -v ${HOST_DATASET_DIR}:/app/datasets"
86+
echo "Mount dataset: ${HOST_DATASET_DIR} -> /app/datasets"
87+
fi
88+
if [ -n "${HOST_OUTPUT_DIR}" ]; then
89+
mkdir -p "${HOST_OUTPUT_DIR}"
90+
MOUNT_ARGS="${MOUNT_ARGS} -v ${HOST_OUTPUT_DIR}:/app/results"
91+
echo "Mount results: ${HOST_OUTPUT_DIR} -> /app/results"
92+
fi
93+
if [ -n "${HOST_WEIGHT_DIR}" ]; then
94+
mkdir -p "${HOST_WEIGHT_DIR}"
95+
MOUNT_ARGS="${MOUNT_ARGS} -v ${HOST_WEIGHT_DIR}:/app/weights"
96+
echo "Mount weights: ${HOST_WEIGHT_DIR} -> /app/weights"
97+
fi
98+
fi
99+
echo ""
100+
101+
echo "=============================="
102+
echo " Step 2: Running container"
103+
echo "=============================="
104+
sudo docker run --gpus all -it --rm --name "${CONTAINER_NAME}" \
105+
${MOUNT_ARGS} \
106+
"${IMAGE_NAME}"

docs/en-US/01_get_started.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,32 @@ Use the `git clone` or directly download the `zip` file of this repository's cod
77
```bash
88
git clone https://github.com/chairc/Integrated-Design-Diffusion-Model.git
99
cd Integrated-Design-Diffusion-Model
10+
# Run the project in a virtual environment (recommended)
11+
conda create -n iddm python=3.10
12+
pip install -r requirements.txt
13+
# Train the model
14+
cd iddm/tools
15+
python train.py --xxx xxx # Replace --xxx with your training parameters
16+
# Generate images
17+
python generate.py --xxx xxx # Replace --xxx with your generation parameters
1018
```
1119

20+
#### Docker Running
21+
22+
Modification contents, please refer to the `docker_run.sh` script.
23+
24+
```bash
25+
# Mount and build the entire project
26+
bash docker_run.sh -a /path/to/project
27+
# Mount and build specified paths
28+
bash docker_run.sh \
29+
-d /path/to/datasets \
30+
-r /path/to/results \
31+
-w /path/to/weights
32+
```
33+
34+
`/path/to/project`, `/path/to/datasets`, `/path/to/results` and `/path/to/weights` are local paths, used to mount the full project, dataset, result and weight directories respectively.
35+
1236
#### Installation
1337

1438
> [!NOTE]
@@ -26,19 +50,19 @@ The following packages are required.
2650

2751
```yaml
2852
coloredlogs==15.0.1
29-
gradio>=6.0.0
53+
gradio==6.0.0
3054
matplotlib==3.7.1
31-
numpy>=1.25.0
32-
Pillow>=12.2.0
33-
Requests>=2.32.4
55+
numpy==1.25.0
56+
Pillow==12.2.0
57+
Requests==2.32.4
3458
scikit-image==0.22.0
3559
torch_summary==1.4.5
3660
tqdm==4.66.3
3761
pytorch_fid==0.3.0
3862
fastapi==0.115.6
3963
tensorboard==2.19.0
4064
tensorboardX==2.6.1
41-
transformers>=5.0.0
65+
transformers==5.0.0
4266

4367
# If you want to use flash attention, please install flash-attn.
4468
# Compile your own environment: pip install flash-attn --no-build-isolation

0 commit comments

Comments
 (0)