File size: 4,309 Bytes
d799084
3b5376c
 
 
 
d74b0c4
 
 
d799084
1841904
d799084
1841904
d799084
 
 
 
 
 
 
 
1841904
e56321b
 
 
 
1841904
d799084
 
 
961a1ab
d799084
1841904
d799084
 
 
 
 
 
 
 
 
 
 
 
 
1841904
d799084
 
 
 
 
 
d74b0c4
d799084
 
1841904
d799084
 
1841904
d799084
 
 
 
 
 
 
 
 
 
 
 
1841904
 
d799084
 
 
 
 
1841904
 
 
 
d799084
1841904
d799084
 
 
1841904
 
 
 
 
 
d799084
1841904
 
56be2fd
1841904
d799084
1841904
 
b27c3b5
 
 
 
 
 
 
 
 
 
 
 
 
 
ca4136c
1841904
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
FROM nvidia/cuda:12.8.0-devel-ubuntu22.04

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV HOME=/root
ENV CUDA_HOME=/usr/local/cuda
ENV PATH=${CUDA_HOME}/bin:${PATH}
ENV LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}
ENV TORCH_CUDA_ARCH_LIST="12.0"

# Install system dependencies and build tools
RUN apt-get update && \
    apt-get install -y \
    curl wget gpg apt-transport-https git software-properties-common \
    build-essential cmake ninja-build \
    libopenblas-dev libomp-dev \
    && rm -rf /var/lib/apt/lists/*

# Install Python 3.12 (as recommended)
RUN add-apt-repository ppa:deadsnakes/ppa && \
    apt-get update && \
    apt-get install -y python3.11 python3.11-venv python3.11-dev && \
    update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 && \
    update-alternatives --set python3 /usr/bin/python3.11 && \
    curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11

# Install uv for faster dependency management
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
    echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc

# Create workspace
RUN mkdir -p /workspace
WORKDIR /workspace

# CRITICAL: Install in the EXACT order specified in the README
# Step 1: Create venv
RUN python3 -m venv /opt/unsloth-env
ENV PATH="/opt/unsloth-env/bin:$PATH"

# Step 2: Install vllm with cu128 (MUST be first)
RUN /opt/unsloth-env/bin/pip install --upgrade pip setuptools wheel && \
    /opt/unsloth-env/bin/pip install -U vllm --extra-index-url https://wheels.vllm.ai/nightly

# Step 3: Install unsloth dependencies
RUN /opt/unsloth-env/bin/pip install unsloth unsloth_zoo bitsandbytes

# Step 4: Build xformers from source (no Blackwell wheels exist yet)
RUN git clone --depth=1 https://github.com/facebookresearch/xformers --recursive /tmp/xformers && \
    cd /tmp/xformers && \
    /opt/unsloth-env/bin/pip uninstall -y xformers && \
    /opt/unsloth-env/bin/python setup.py install && \
    rm -rf /tmp/xformers

# Step 5: Update triton to >=3.3.1 for Blackwell
RUN /opt/unsloth-env/bin/pip install -U "triton>=3.3.1"

# Step 6: Pin transformers to avoid gradient checkpointing bug
RUN /opt/unsloth-env/bin/pip install -U "transformers==4.52.4"

# Step 7: Might need to downgrade numpy
RUN /opt/unsloth-env/bin/pip install "numpy<=2.2"

# Now install your dev tools (code-server, Node.js, etc)
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
    apt-get install -y nodejs && \
    curl -fsSL https://code-server.dev/install.sh | sh && \
    npm install -g @anthropic-ai/claude-code @anthropic-ai/dxt && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Install Ollama
RUN curl -fsSL https://ollama.com/install.sh | sh || true

# Configure code-server
RUN mkdir -p /root/.config/code-server /root/.ollama && \
    echo "bind-addr: 0.0.0.0:8443\nauth: none\ncert: false" > /root/.config/code-server/config.yaml

# Install VS Code extensions
RUN code-server --install-extension ms-python.python && \
    code-server --install-extension ritwickdey.LiveServer && \
    code-server --install-extension ms-toolsai.jupyter

# Create startup script with proper env activation
RUN echo '#!/bin/bash\n\
# Activate the unsloth environment\n\
source /opt/unsloth-env/bin/activate\n\
\n\
# Start Ollama in the background\n\
/usr/local/bin/ollama serve &\n\
\n\
# Give Ollama a moment to start\n\
sleep 2\n\
\n\
# Start code-server with the activated environment\n\
exec code-server --disable-telemetry --bind-addr 0.0.0.0:8443 /workspace\n\
' > /start.sh && \
    chmod +x /start.sh

# Expose ports
EXPOSE 8443 11434

# Copy requirements.txt to workspace (will fail build if not present)
COPY requirements.txt /workspace/requirements.txt

# Create a script to install from requirements.txt with proper environment
RUN echo '#!/bin/bash\n\
echo "Installing from requirements.txt..."\n\
source /opt/unsloth-env/bin/activate\n\
pip install -r /workspace/requirements.txt\n\
echo "Installation complete!"\n\
' > /workspace/install-requirements.sh && \
    chmod +x /workspace/install-requirements.sh

# Optional: Install requirements.txt if you want it done at build time
# Uncomment the next line if you want automatic installation
RUN /opt/unsloth-env/bin/pip install -r /workspace/requirements.txt

CMD ["/start.sh"]