Added: Cuda Dockerfile. Edit: Initialize.sh to fix perms issue by adding -f force.
Added: Cuda Dockerfile. Edit: Initialize.sh to fix perms issue by adding -f force.
deci committed
May 10, 2025 at 16:40 UTC
b2d1aacd03e2f89acf958852811209f42cd9d802
5 files changed
+283
-1
.gitignore
+6
@@ -4,6 +4,12 @@
4
**/__pycache__/
5
**/.conda/
6
7
+# Ignore docker/run/agent-zero directory
8
+docker/run/agent-zero/
9
+
10
+#Ignore cursor rules
11
+.cursor/
12
+
13
# ignore test files in root dir
14
/*.test.py
15
docker/run/Dockerfile.cuda
new
+152
@@ -0,0 +1,152 @@
1
+# Use the NVIDIA CUDA base image with Ubuntu
2
+FROM nvidia/cuda:12.8.1-base-ubuntu22.04
3
+
4
+# Set non-interactive installation and timezone
5
+ENV DEBIAN_FRONTEND=noninteractive
6
+ENV TZ=UTC
7
+
8
+# Check if the argument is provided, else throw an error
9
+ARG BRANCH
10
+RUN if [ -z "$BRANCH" ]; then echo "ERROR: BRANCH is not set!" >&2; exit 1; fi
11
+ENV BRANCH=$BRANCH
12
+
13
+# Set locale to en_US.UTF-8 and timezone to UTC (matching main Dockerfile)
14
+RUN apt-get update && apt-get install -y locales tzdata
15
+RUN sed -i -e 's/# \(en_US\.UTF-8 .*\)/\1/' /etc/locale.gen && \
16
+ dpkg-reconfigure --frontend=noninteractive locales && \
17
+ update-locale LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8
18
+RUN ln -sf /usr/share/zoneinfo/UTC /etc/localtime
19
+RUN echo "UTC" > /etc/timezone
20
+RUN dpkg-reconfigure -f noninteractive tzdata
21
+ENV LANG=en_US.UTF-8
22
+ENV LANGUAGE=en_US:en
23
+ENV LC_ALL=en_US.UTF-8
24
+ENV TZ=UTC
25
+
26
+# Copy contents of the project to root directory
27
+COPY ./fs/ /
28
+
29
+# Fix permissions for cron files from pre_install.sh
30
+RUN chmod 0644 /etc/cron.d/*
31
+
32
+# Install essential packages (from pre_install.sh but avoiding supervisor from apt)
33
+RUN apt-get update && apt-get upgrade -y && apt-get install -y \
34
+ python3 \
35
+ python3-venv \
36
+ python3-pip \
37
+ nodejs \
38
+ openssh-server \
39
+ sudo \
40
+ curl \
41
+ wget \
42
+ git \
43
+ ffmpeg \
44
+ cron
45
+
46
+# Prepare SSH daemon (from pre_install.sh)
47
+RUN bash /ins/setup_ssh.sh $BRANCH
48
+
49
+# Configure Python 3.12 (specific to Ubuntu-based CUDA image)
50
+RUN apt-get update && apt-get install -y \
51
+ software-properties-common && \
52
+ add-apt-repository -y ppa:deadsnakes/ppa && \
53
+ apt-get update && \
54
+ apt-get install -y python3.12 python3.12-venv python3.12-dev && \
55
+ update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 && \
56
+ update-alternatives --set python3 /usr/bin/python3.12
57
+
58
+# Bootstrap pip for Python 3.12 and install supervisor
59
+RUN python3 -m ensurepip --upgrade && \
60
+ python3 -m pip install --upgrade pip setuptools wheel && \
61
+ python3 -m pip install supervisor
62
+
63
+# Create supervisor directories
64
+RUN mkdir -p /var/log/supervisor /etc/supervisor/conf.d
65
+
66
+# Create root dotfiles with appropriate permissions
67
+RUN touch /root/.bashrc /root/.profile && \
68
+ chmod 644 /root/.bashrc /root/.profile
69
+
70
+# Create a symlink for supervisord to the expected location
71
+RUN ln -sf $(which supervisord) /usr/bin/supervisord
72
+
73
+# Install additional software
74
+RUN bash /ins/install_additional.sh $BRANCH
75
+
76
+# Install core CUDA dependencies (minimized to essentials)
77
+RUN apt-get update && apt-get install -y --no-install-recommends \
78
+ cuda-cudart-dev-12-8 \
79
+ libcublas-dev-12-8 \
80
+ libcudnn8 \
81
+ && apt-get clean \
82
+ && rm -rf /var/lib/apt/lists/*
83
+
84
+# Set CUDA environment variables
85
+ENV PATH=/usr/local/cuda/bin:${PATH}
86
+ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}
87
+ENV CUDA_HOME=/usr/local/cuda
88
+ENV CUDA_VERSION=12.8.1
89
+
90
+# Install A0
91
+RUN bash /ins/install_A0.sh $BRANCH
92
+
93
+# Create and set up the shared instruments virtual environment
94
+ENV INSTRUMENTS_VENV_PATH=/opt/instruments_venv
95
+RUN python3 -m venv $INSTRUMENTS_VENV_PATH
96
+
97
+# Switch to bash for the next RUN step (required for set -o pipefail)
98
+SHELL ["/bin/bash", "-c"]
99
+
100
+# Install all heavy dependencies into the instruments venv, with explicit checks
101
+RUN set -euxo pipefail; \
102
+ . $INSTRUMENTS_VENV_PATH/bin/activate; \
103
+ echo "=== Upgrading pip, setuptools, wheel ==="; \
104
+ pip install --upgrade pip setuptools wheel; \
105
+ echo "=== Installing PyTorch with CUDA ==="; \
106
+ pip install --no-cache-dir torch==2.6.0+cu124 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124; \
107
+ echo "=== Installing other heavy dependencies ==="; \
108
+ pip install --no-cache-dir \
109
+ huggingface-hub==0.20.3 \
110
+ safetensors==0.4.1 \
111
+ accelerate==0.21.0 \
112
+ diffusers==0.25.0 \
113
+ transformers==4.38.2 \
114
+ scipy==1.15.2 \
115
+ xformers==0.0.29.post3; \
116
+ echo "=== Checking all critical imports ==="; \
117
+ python -c "import torch; print(f'PyTorch {torch.__version__} imported successfully. CUDA: {getattr(torch, 'cuda', None) and torch.cuda.is_available()}')" || (echo 'PyTorch import failed!' && exit 1); \
118
+ python -c "import torchvision; print(f'Torchvision {torchvision.__version__} imported successfully.')" || (echo 'Torchvision import failed!' && exit 1); \
119
+ python -c "import torchaudio; print(f'Torchaudio {torchaudio.__version__} imported successfully.')" || (echo 'Torchaudio import failed!' && exit 1); \
120
+ python -c "import diffusers; print(f'Diffusers {diffusers.__version__} imported successfully.')" || (echo 'Diffusers import failed!' && exit 1); \
121
+ python -c "import transformers; print(f'Transformers {transformers.__version__} imported successfully.')" || (echo 'Transformers import failed!' && exit 1); \
122
+ python -c "import xformers; print(f'Xformers {xformers.__version__} imported successfully.')" || (echo 'Xformers import failed!' && exit 1); \
123
+ python -c "import accelerate; print(f'Accelerate {accelerate.__version__} imported successfully.')" || (echo 'Accelerate import failed!' && exit 1); \
124
+ python -c "import safetensors; print(f'Safetensors {safetensors.__version__} imported successfully.')" || (echo 'Safetensors import failed!' && exit 1); \
125
+ python -c "import scipy; print(f'Scipy {scipy.__version__} imported successfully.')" || (echo 'Scipy import failed!' && exit 1); \
126
+ python -c "import huggingface_hub; print(f'Huggingface_hub {huggingface_hub.__version__} imported successfully.')" || (echo 'Huggingface_hub import failed!' && exit 1); \
127
+ echo "=== All critical imports succeeded ==="
128
+
129
+# Optionally revert to sh for subsequent steps if needed
130
+SHELL ["/bin/sh", "-c"]
131
+
132
+# The existing global PyTorch install for /opt/venv (A0's main venv) is below.
133
+# It might be used by other core A0 components, so we keep it.
134
+# Our instruments will use the dedicated $INSTRUMENTS_VENV_PATH.
135
+RUN . /opt/venv/bin/activate && \
136
+ pip uninstall -y torch torchvision && \
137
+ pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cu124
138
+
139
+# Cleanup repo and install A0 without caching, this speeds up builds
140
+ARG CACHE_DATE=none
141
+RUN echo "cache buster $CACHE_DATE" && bash /ins/install_A02.sh $BRANCH
142
+
143
+# Post installation steps
144
+RUN bash /ins/post_install.sh $BRANCH
145
+
146
+# Expose ports
147
+EXPOSE 22 80
148
+
149
+RUN chmod +x /exe/initialize.sh /exe/run_A0.sh /exe/run_searxng.sh
150
+
151
+# Initialize runtime
152
+CMD ["/exe/initialize.sh", "$BRANCH"]
\ No newline at end of file
docker/run/README.cuda.md
new
+104
@@ -0,0 +1,104 @@
1
+# Agent Zero: CUDA GPU Support 🚀
2
+
3
+This guide explains how to build and run Agent Zero with NVIDIA GPU acceleration using CUDA. Running with CUDA enables faster performance for AI workloads by leveraging your GPU.
4
+
5
+---
6
+
7
+## Prerequisites
8
+
9
+Before you begin, ensure you have:
10
+
11
+1. **NVIDIA GPU** with CUDA capability
12
+2. **NVIDIA Driver** installed on your host system
13
+3. **NVIDIA Container Toolkit** ([Install Guide](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html))
14
+ _This enables Docker to access your GPU_
15
+4. **Docker** and **Docker Compose** installed
16
+
17
+---
18
+
19
+## 1. Build the CUDA Docker Image
20
+
21
+Open a terminal in this directory and run:
22
+
23
+```bash
24
+# Set the branch you want to build from (default: main)
25
+$branch="main"
26
+docker build --no-cache -t frdel/agent-zero-run-cuda:testing --build-arg BRANCH=$branch -f Dockerfile.cuda .
27
+```
28
+
29
+---
30
+
31
+## 2. Run Agent Zero with CUDA Support
32
+
33
+You can start Agent Zero with GPU support using Docker Compose:
34
+
35
+```bash
36
+# On Linux, macOS, or Windows PowerShell:
37
+docker-compose -f docker-compose.cuda.yml up -d
38
+```
39
+
40
+- This will launch Agent Zero in the background with GPU acceleration enabled.
41
+
42
+---
43
+
44
+## 3. Access Agent Zero
45
+
46
+Once the container is running, open your browser and go to:
47
+
48
+[http://localhost:50080](http://localhost:50080)
49
+
50
+---
51
+
52
+## 4. Stopping Agent Zero
53
+
54
+To stop the CUDA-enabled Agent Zero container:
55
+
56
+```bash
57
+docker-compose -f docker-compose.cuda.yml down
58
+```
59
+
60
+---
61
+
62
+## 5. Switching Between CPU and GPU Versions
63
+
64
+You can easily switch between the CPU and GPU versions:
65
+
66
+1. **Stop the currently running version:**
67
+ ```bash
68
+ # For CPU version:
69
+ docker-compose down
70
+ # For GPU version:
71
+ docker-compose -f docker-compose.cuda.yml down
72
+ ```
73
+
74
+2. **Start the version you want:**
75
+ ```bash
76
+ # CPU version:
77
+ docker-compose -f docker-compose.yml up -d
78
+
79
+ # GPU (CUDA) version:
80
+ docker-compose -f docker-compose.cuda.yml up -d
81
+ ```
82
+
83
+---
84
+
85
+## Troubleshooting & Tips
86
+
87
+- **First time setup may take several minutes** as dependencies are downloaded and installed.
88
+- If you encounter issues with GPU access, verify your NVIDIA drivers and the NVIDIA Container Toolkit are correctly installed.
89
+- To check if CUDA is available inside the container, you can run:
90
+ ```bash
91
+ docker exec -it <container_name> python3 -c "import torch; print(torch.cuda.is_available())"
92
+ ```
93
+- For advanced configuration, see the comments in [`Dockerfile.cuda`](mdc:docker/run/Dockerfile.cuda).
94
+
95
+---
96
+
97
+## More Information
98
+
99
+- [NVIDIA Container Toolkit Documentation](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html)
100
+- [Agent Zero Project](https://github.com/frdel/agent-zero) (replace with your actual repo link if different)
101
+
102
+---
103
+
104
+**Enjoy accelerated AI with Agent Zero and CUDA!**
docker/run/docker-compose.cuda.yml
new
+20
@@ -0,0 +1,20 @@
1
+services:
2
+ agent-zero-cuda:
3
+ container_name: agent-zero-cuda
4
+ image: frdel/agent-zero-run-cuda:testing
5
+ volumes:
6
+ - ./agent-zero:/a0
7
+ - ./agent-zero/work_dir:/root
8
+ ports:
9
+ - "50080:80"
10
+ environment:
11
+ - NVIDIA_VISIBLE_DEVICES=all
12
+ - NVIDIA_DRIVER_CAPABILITIES=compute,utility
13
+ - PYTHONUNBUFFERED=1
14
+ deploy:
15
+ resources:
16
+ reservations:
17
+ devices:
18
+ - driver: nvidia
19
+ count: all
20
+ capabilities: [gpu]
\ No newline at end of file
docker/run/fs/exe/initialize.sh
+1
-1
@@ -8,7 +8,7 @@ fi
8
BRANCH="$1"
9
10
# Copy all contents from persistent /per to root directory (/) without overwriting
11
-cp -r --no-preserve=ownership,mode /per/* /
11
+cp -r -f --no-preserve=ownership,mode /per/* /
12
13
# allow execution of /root/.bashrc and /root/.profile
14
chmod 444 /root/.bashrc