Skip to content

Commit 18f3cff

Browse files
committed
dev container
1 parent a70929d commit 18f3cff

File tree

7 files changed

+588
-40
lines changed

7 files changed

+588
-40
lines changed

.devcontainer/CONFIGURATIONS.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# DevContainer Configuration Examples
2+
3+
Copy and paste these configurations into your `.devcontainer/devcontainer.json` file, replacing the existing `"build"` section.
4+
5+
## Minimal Setup (Default)
6+
Fastest build time, CPU-only development.
7+
```json
8+
"build": {
9+
"args": {
10+
"INSTALL_CUDA": "false",
11+
"INSTALL_ROCM": "false",
12+
"INSTALL_PYTHON_DEPS": "false"
13+
}
14+
}
15+
```
16+
17+
## CPU + Python Tools
18+
For model conversion and CPU inference.
19+
```json
20+
"build": {
21+
"args": {
22+
"INSTALL_CUDA": "false",
23+
"INSTALL_ROCM": "false",
24+
"INSTALL_PYTHON_DEPS": "true"
25+
}
26+
}
27+
```
28+
29+
## NVIDIA GPU Development
30+
For CUDA acceleration with model tools.
31+
```json
32+
"build": {
33+
"args": {
34+
"INSTALL_CUDA": "true",
35+
"INSTALL_ROCM": "false",
36+
"INSTALL_PYTHON_DEPS": "true"
37+
}
38+
}
39+
```
40+
41+
## AMD GPU Development
42+
For ROCm acceleration with model tools.
43+
```json
44+
"build": {
45+
"args": {
46+
"INSTALL_CUDA": "false",
47+
"INSTALL_ROCM": "true",
48+
"INSTALL_PYTHON_DEPS": "true"
49+
}
50+
}
51+
```
52+
53+
## Multi-GPU Research Setup
54+
For testing both NVIDIA and AMD GPU paths (large build).
55+
```json
56+
"build": {
57+
"args": {
58+
"INSTALL_CUDA": "true",
59+
"INSTALL_ROCM": "true",
60+
"INSTALL_PYTHON_DEPS": "true"
61+
}
62+
}
63+
```
64+
65+
## Build Time Estimates
66+
- Minimal: 2-3 minutes
67+
- CPU + Python: 3-5 minutes
68+
- NVIDIA GPU: 5-8 minutes
69+
- AMD GPU: 8-12 minutes
70+
- Multi-GPU: 12-15 minutes
71+
72+
## After Changing Configuration
73+
1. Save the `devcontainer.json` file
74+
2. In VS Code: `Ctrl+Shift+P` → "Dev Containers: Rebuild Container"
75+
3. Wait for the build to complete

.devcontainer/Dockerfile

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
FROM ubuntu:24.04
22

3+
# Build arguments for optional components (default: disabled)
4+
ARG INSTALL_CUDA=false
5+
ARG INSTALL_ROCM=false
6+
ARG INSTALL_PYTHON_DEPS=false
7+
38
# Avoid prompts from apt
49
ENV DEBIAN_FRONTEND=noninteractive
510

@@ -36,30 +41,53 @@ RUN apt-get update && \
3641
valgrind \
3742
gh && \
3843
update-ca-certificates && \
39-
mkdir -p --mode=0755 /etc/apt/keyrings && \
40-
wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | \
41-
gpg --dearmor | tee /etc/apt/keyrings/rocm.gpg > /dev/null && \
42-
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/6.4.2 noble main" \
43-
| tee /etc/apt/sources.list.d/rocm.list && \
44-
echo 'Package: *' \
45-
| tee /etc/apt/preferences.d/rocm-pin-600 && \
46-
echo 'Pin: release o=repo.radeon.com' \
47-
| tee -a /etc/apt/preferences.d/rocm-pin-600 && \
48-
echo 'Pin-Priority: 600' \
49-
| tee -a /etc/apt/preferences.d/rocm-pin-600 && \
50-
apt-get update && \
51-
apt-get install -y rocm && \
5244
apt-get autoremove -y && \
53-
apt-get clean
45+
apt-get clean
46+
47+
# Install CUDA 12.9 (conditional)
48+
RUN if [ "$INSTALL_CUDA" = "true" ]; then \
49+
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb -O cuda-keyring.deb && \
50+
dpkg -i cuda-keyring.deb && \
51+
apt-get update && \
52+
apt-get -y install cuda-toolkit-12-9 && \
53+
rm cuda-keyring.deb; \
54+
else \
55+
echo "Skipping CUDA installation"; \
56+
fi
57+
58+
# Install ROCm 6.4 (conditional)
59+
RUN if [ "$INSTALL_ROCM" = "true" ]; then \
60+
mkdir -p --mode=0755 /etc/apt/keyrings && \
61+
wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | \
62+
gpg --dearmor | tee /etc/apt/keyrings/rocm.gpg > /dev/null && \
63+
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/6.4.2 noble main" \
64+
| tee /etc/apt/sources.list.d/rocm.list && \
65+
echo 'Package: *' \
66+
| tee /etc/apt/preferences.d/rocm-pin-600 && \
67+
echo 'Pin: release o=repo.radeon.com' \
68+
| tee -a /etc/apt/preferences.d/rocm-pin-600 && \
69+
echo 'Pin-Priority: 600' \
70+
| tee -a /etc/apt/preferences.d/rocm-pin-600 && \
71+
apt-get update && \
72+
apt-get install -y rocm && \
73+
apt-get autoremove -y && \
74+
apt-get clean; \
75+
else \
76+
echo "Skipping ROCm installation"; \
77+
fi
5478

55-
# Install Python dependencies for gguf conversion tools
56-
RUN python3 -m pip install --break-system-packages \
57-
numpy \
58-
torch \
59-
transformers \
60-
sentencepiece \
61-
protobuf \
62-
gguf
79+
# Install Python dependencies for gguf conversion tools (conditional)
80+
RUN if [ "$INSTALL_PYTHON_DEPS" = "true" ]; then \
81+
python3 -m pip install --break-system-packages \
82+
numpy \
83+
torch \
84+
transformers \
85+
sentencepiece \
86+
protobuf \
87+
gguf; \
88+
else \
89+
echo "Skipping Python dependencies installation"; \
90+
fi
6391

6492
# Set up ccache for faster compilation
6593
ENV PATH="/usr/lib/ccache:${PATH}"

.devcontainer/README.md

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,92 @@
11
# llama.cpp Development Container
22

3-
This dev container provides a complete Ubuntu 24.04 environment for building and testing llama.cpp with NUMA support.
3+
This dev container provides a complete Ubuntu 24.04 environment for building and testing llama.cpp with NUMA support and optional GPU acceleration.
4+
5+
## Quick Start
6+
7+
1. Open the project in VS Code
8+
2. When prompted, click "Reopen in Container" or use `Ctrl+Shift+P` → "Dev Containers: Reopen in Container"
9+
3. The container will build with the basic development tools (no GPU support by default)
10+
11+
## Optional Components
12+
13+
By default, the container includes only the essential build tools. You can enable additional components by editing `.devcontainer/devcontainer.json`:
14+
15+
### CUDA Support (NVIDIA GPUs)
16+
```json
17+
"INSTALL_CUDA": "true"
18+
```
19+
Installs CUDA 12.9 toolkit for NVIDIA GPU acceleration.
20+
21+
### ROCm Support (AMD GPUs)
22+
```json
23+
"INSTALL_ROCM": "true"
24+
```
25+
Installs ROCm 6.4 for AMD GPU acceleration.
26+
27+
### Python Dependencies
28+
```json
29+
"INSTALL_PYTHON_DEPS": "true"
30+
```
31+
Installs Python packages for model conversion tools:
32+
- numpy, torch, transformers, sentencepiece, protobuf, gguf
33+
34+
## Example Configurations
35+
36+
### Full GPU Development (NVIDIA + Python)
37+
```json
38+
"build": {
39+
"args": {
40+
"INSTALL_CUDA": "true",
41+
"INSTALL_ROCM": "false",
42+
"INSTALL_PYTHON_DEPS": "true"
43+
}
44+
}
45+
```
46+
47+
### AMD GPU Development
48+
```json
49+
"build": {
50+
"args": {
51+
"INSTALL_CUDA": "false",
52+
"INSTALL_ROCM": "true",
53+
"INSTALL_PYTHON_DEPS": "true"
54+
}
55+
}
56+
```
57+
58+
### CPU-only with Python tools
59+
```json
60+
"build": {
61+
"args": {
62+
"INSTALL_CUDA": "false",
63+
"INSTALL_ROCM": "false",
64+
"INSTALL_PYTHON_DEPS": "true"
65+
}
66+
}
67+
```
68+
69+
## Making Changes
70+
71+
### Method 1: Interactive Configuration Script (Recommended)
72+
```bash
73+
# Run the configuration helper
74+
chmod +x .devcontainer/configure.sh
75+
./.devcontainer/configure.sh
76+
```
77+
78+
### Method 2: Manual Configuration
79+
1. Edit `.devcontainer/devcontainer.json`
80+
2. Set the desired components to `"true"` or `"false"`
81+
3. Rebuild the container: `Ctrl+Shift+P` → "Dev Containers: Rebuild Container"
482

583
## Features
684

785
- **Ubuntu 24.04 LTS** base image
886
- **Complete build toolchain**: gcc, cmake, ninja, ccache
987
- **NUMA support**: libnuma-dev, numactl, hwloc for CPU topology detection
10-
- **Python environment**: with all necessary packages for GGUF conversion tools
88+
- **Optional GPU acceleration**: CUDA 12.9 and/or ROCm 6.4 support
89+
- **Optional Python environment**: with packages for GGUF conversion tools
1190
- **VS Code integration**: with C/C++, CMake, and Python extensions
1291
- **Development tools**: gdb, valgrind for debugging
1392

.devcontainer/configure.sh

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/bin/bash
2+
3+
# llama.cpp DevContainer Configuration Script
4+
# This script helps you quickly configure optional components for the development container.
5+
6+
set -e
7+
8+
CONFIG_FILE=".devcontainer/devcontainer.json"
9+
10+
if [[ ! -f "$CONFIG_FILE" ]]; then
11+
echo "❌ Error: $CONFIG_FILE not found. Are you in the llama.cpp root directory?"
12+
exit 1
13+
fi
14+
15+
echo "🔧 llama.cpp DevContainer Configuration"
16+
echo "======================================"
17+
echo
18+
echo "This script will help you configure optional components for your development environment."
19+
echo "After making changes, you'll need to rebuild the container in VS Code."
20+
echo
21+
22+
# Function to get current setting
23+
get_current_setting() {
24+
local component=$1
25+
local current=$(grep -A 10 '"build"' "$CONFIG_FILE" | grep "\"$component\"" | sed 's/.*"\([^"]*\)".*/\1/')
26+
echo "${current:-false}"
27+
}
28+
29+
# Function to update setting
30+
update_setting() {
31+
local component=$1
32+
local value=$2
33+
34+
# Use a more robust sed command that works across platforms
35+
if [[ "$OSTYPE" == "darwin"* ]]; then
36+
# macOS
37+
sed -i '' "s/\(\"$component\":\s*\)\"[^\"]*\"/\1\"$value\"/" "$CONFIG_FILE"
38+
else
39+
# Linux/WSL
40+
sed -i "s/\(\"$component\":\s*\)\"[^\"]*\"/\1\"$value\"/" "$CONFIG_FILE"
41+
fi
42+
}
43+
44+
# Get current settings
45+
cuda_current=$(get_current_setting "INSTALL_CUDA")
46+
rocm_current=$(get_current_setting "INSTALL_ROCM")
47+
python_current=$(get_current_setting "INSTALL_PYTHON_DEPS")
48+
49+
echo "Current configuration:"
50+
echo " • CUDA support: $cuda_current"
51+
echo " • ROCm support: $rocm_current"
52+
echo " • Python dependencies: $python_current"
53+
echo
54+
55+
# CUDA Configuration
56+
echo "🎯 CUDA Support (NVIDIA GPUs)"
57+
echo " Installs CUDA 12.9 toolkit (~5-8 minutes build time)"
58+
read -p " Enable CUDA support? [y/N]: " cuda_choice
59+
cuda_choice=${cuda_choice,,} # to lowercase
60+
if [[ $cuda_choice =~ ^(yes|y)$ ]]; then
61+
cuda_new="true"
62+
else
63+
cuda_new="false"
64+
fi
65+
66+
# ROCm Configuration
67+
echo
68+
echo "🎯 ROCm Support (AMD GPUs)"
69+
echo " Installs ROCm 6.4 for AMD GPU acceleration (~8-12 minutes build time)"
70+
read -p " Enable ROCm support? [y/N]: " rocm_choice
71+
rocm_choice=${rocm_choice,,}
72+
if [[ $rocm_choice =~ ^(yes|y)$ ]]; then
73+
rocm_new="true"
74+
else
75+
rocm_new="false"
76+
fi
77+
78+
# Python Dependencies
79+
echo
80+
echo "🎯 Python Dependencies"
81+
echo " Installs packages for model conversion: numpy, torch, transformers, etc."
82+
read -p " Enable Python dependencies? [y/N]: " python_choice
83+
python_choice=${python_choice,,}
84+
if [[ $python_choice =~ ^(yes|y)$ ]]; then
85+
python_new="true"
86+
else
87+
python_new="false"
88+
fi
89+
90+
# Summary and confirmation
91+
echo
92+
echo "📋 Configuration Summary:"
93+
echo " • CUDA support: $cuda_current$cuda_new"
94+
echo " • ROCm support: $rocm_current$rocm_new"
95+
echo " • Python dependencies: $python_current$python_new"
96+
echo
97+
98+
# Estimate build time
99+
build_time="2-3 minutes"
100+
if [[ $cuda_new == "true" ]]; then
101+
build_time="5-8 minutes"
102+
fi
103+
if [[ $rocm_new == "true" ]]; then
104+
build_time="8-12 minutes"
105+
fi
106+
if [[ $python_new == "true" && $cuda_new == "false" && $rocm_new == "false" ]]; then
107+
build_time="3-5 minutes"
108+
fi
109+
110+
echo "⏱️ Estimated build time: $build_time"
111+
echo
112+
113+
read -p "Apply these changes? [Y/n]: " confirm
114+
confirm=${confirm,,}
115+
if [[ ! $confirm =~ ^(no|n)$ ]]; then
116+
echo
117+
echo "✅ Applying configuration..."
118+
119+
update_setting "INSTALL_CUDA" "$cuda_new"
120+
update_setting "INSTALL_ROCM" "$rocm_new"
121+
update_setting "INSTALL_PYTHON_DEPS" "$python_new"
122+
123+
echo "✅ Configuration updated successfully!"
124+
echo
125+
echo "🔄 Next steps:"
126+
echo " 1. Open VS Code in this directory"
127+
echo " 2. Press Ctrl+Shift+P and select 'Dev Containers: Rebuild Container'"
128+
echo " 3. Wait for the container to build with your new configuration"
129+
echo
130+
else
131+
echo "❌ Configuration cancelled."
132+
fi

0 commit comments

Comments
 (0)