-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
190 lines (157 loc) · 7.07 KB
/
Dockerfile
File metadata and controls
190 lines (157 loc) · 7.07 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# syntax=docker/dockerfile:1.6
# Multi-stage Docker build for BitNet-rs (CPU + CUDA)
# Uses cargo-chef for dependency caching.
#
# Build targets:
# docker build --target runtime . # CPU (default)
# docker build --target runtime-gpu . # CUDA GPU
# ── Stage 1: cargo-chef planner (shared) ────────────────────────────
FROM rust:1.92-bookworm AS planner
RUN cargo install cargo-chef --locked
WORKDIR /app
COPY Cargo.toml Cargo.lock build.rs ./
COPY src/ ./src/
COPY crates/ ./crates/
COPY crossval/ ./crossval/
COPY tests/ ./tests/
COPY xtask/ ./xtask/
COPY xtask-build-helper/ ./xtask-build-helper/
COPY benches/ ./benches/
COPY fuzz/ ./fuzz/
RUN cargo chef prepare --recipe-path recipe.json
# ── Stage 2a: CPU dependency cook ───────────────────────────────────
FROM rust:1.92-bookworm AS deps-cpu
RUN cargo install cargo-chef --locked
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential cmake pkg-config libssl-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=planner /app/recipe.json recipe.json
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,id=cpu-target,target=/app/target \
cargo chef cook --release --no-default-features --features cpu --recipe-path recipe.json
# ── Stage 2b: CUDA dependency cook ─────────────────────────────────
FROM nvidia/cuda:12.3.1-devel-ubuntu22.04 AS deps-gpu
RUN apt-get update && apt-get install -y --no-install-recommends \
curl build-essential cmake pkg-config libssl-dev ca-certificates git \
&& rm -rf /var/lib/apt/lists/*
RUN curl -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.92.0
ENV PATH=/root/.cargo/bin:$PATH
# Default compute capability for docker build (no nvidia-smi available).
ARG CUDA_COMPUTE_CAP=80
ENV CUDA_COMPUTE_CAP=${CUDA_COMPUTE_CAP}
RUN cargo install cargo-chef --locked
WORKDIR /app
COPY --from=planner /app/recipe.json recipe.json
RUN --mount=type=cache,target=/root/.cargo/registry \
--mount=type=cache,id=gpu-target,target=/app/target \
cargo chef cook --release --no-default-features --features gpu --recipe-path recipe.json
# ── Stage 3a: CPU builder ──────────────────────────────────────────
FROM deps-cpu AS builder-cpu
ARG VCS_REF
ARG VCS_BRANCH
ARG VCS_DESCRIBE
ENV VERGEN_GIT_SHA=${VCS_REF:-unknown} \
VERGEN_GIT_BRANCH=${VCS_BRANCH:-unknown} \
VERGEN_GIT_DESCRIBE=${VCS_DESCRIBE:-unknown} \
VERGEN_IDEMPOTENT=1
COPY Cargo.toml Cargo.lock build.rs ./
COPY src/ ./src/
COPY crates/ ./crates/
COPY crossval/ ./crossval/
COPY tests/ ./tests/
COPY xtask/ ./xtask/
COPY xtask-build-helper/ ./xtask-build-helper/
COPY benches/ ./benches/
COPY fuzz/ ./fuzz/
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,id=cpu-target,target=/app/target \
cargo build --locked --release --no-default-features --features cpu \
&& cp target/release/bitnet target/release/server /usr/local/bin/
# ── Stage 3b: CUDA builder ─────────────────────────────────────────
FROM deps-gpu AS builder-gpu
ARG VCS_REF
ARG VCS_BRANCH
ARG VCS_DESCRIBE
ENV VERGEN_GIT_SHA=${VCS_REF:-unknown} \
VERGEN_GIT_BRANCH=${VCS_BRANCH:-unknown} \
VERGEN_GIT_DESCRIBE=${VCS_DESCRIBE:-unknown} \
VERGEN_IDEMPOTENT=1
COPY Cargo.toml Cargo.lock build.rs ./
COPY src/ ./src/
COPY crates/ ./crates/
COPY crossval/ ./crossval/
COPY tests/ ./tests/
COPY xtask/ ./xtask/
COPY xtask-build-helper/ ./xtask-build-helper/
COPY benches/ ./benches/
COPY fuzz/ ./fuzz/
RUN --mount=type=cache,target=/root/.cargo/registry \
--mount=type=cache,id=gpu-target,target=/app/target \
cargo build --locked --release --no-default-features --features gpu \
&& cp target/release/bitnet target/release/server /usr/local/bin/
# ── Stage 4a: CPU runtime (minimal) ────────────────────────────────
FROM debian:bookworm-slim AS runtime
ARG VCS_REF
ARG VCS_BRANCH
ARG VCS_DESCRIBE
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates libssl3 curl \
&& rm -rf /var/lib/apt/lists/*
RUN groupadd -g 10001 bitnet && \
useradd -m -u 10001 -g 10001 -s /bin/false bitnet
COPY --from=builder-cpu /usr/local/bin/bitnet /usr/local/bin/bitnet
COPY --from=builder-cpu /usr/local/bin/server /usr/local/bin/server
RUN mkdir -p /data /models && chown bitnet:bitnet /data /models
USER bitnet
WORKDIR /home/bitnet
# RUST_LOG - log verbosity (default: info)
# BITNET_MODEL_PATH - directory for GGUF model files
# BITNET_DATA_PATH - writable data directory
ENV RUST_LOG=info \
BITNET_MODEL_PATH=/models \
BITNET_DATA_PATH=/data
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -sf http://localhost:8080/health || exit 1
LABEL org.opencontainers.image.revision="${VCS_REF}" \
org.opencontainers.image.version="${VCS_DESCRIBE}" \
org.opencontainers.image.ref.name="${VCS_BRANCH}" \
org.opencontainers.image.source="https://github.com/EffortlessMetrics/BitNet-rs" \
org.opencontainers.image.title="bitnet-rs" \
org.opencontainers.image.description="High-performance 1-bit LLM inference engine"
CMD ["server"]
# ── Stage 4b: GPU runtime (CUDA libs included) ─────────────────────
FROM nvidia/cuda:12.3.1-runtime-ubuntu22.04 AS runtime-gpu
ARG VCS_REF
ARG VCS_BRANCH
ARG VCS_DESCRIBE
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates libssl3 curl \
&& rm -rf /var/lib/apt/lists/*
RUN groupadd -g 10001 bitnet && \
useradd -m -u 10001 -g 10001 -s /bin/false bitnet
COPY --from=builder-gpu /usr/local/bin/bitnet /usr/local/bin/bitnet
COPY --from=builder-gpu /usr/local/bin/server /usr/local/bin/server
RUN mkdir -p /data /models && chown bitnet:bitnet /data /models
USER bitnet
WORKDIR /home/bitnet
# CUDA_VISIBLE_DEVICES - restrict visible GPUs (default: all)
# RUST_LOG - log verbosity (default: info)
# BITNET_MODEL_PATH - directory for GGUF model files
# BITNET_DATA_PATH - writable data directory
ENV RUST_LOG=info \
BITNET_MODEL_PATH=/models \
BITNET_DATA_PATH=/data \
NVIDIA_VISIBLE_DEVICES=all \
NVIDIA_DRIVER_CAPABILITIES=compute,utility
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -sf http://localhost:8080/health || exit 1
LABEL org.opencontainers.image.revision="${VCS_REF}" \
org.opencontainers.image.version="${VCS_DESCRIBE}" \
org.opencontainers.image.ref.name="${VCS_BRANCH}" \
org.opencontainers.image.source="https://github.com/EffortlessMetrics/BitNet-rs" \
org.opencontainers.image.title="bitnet-rs-gpu" \
org.opencontainers.image.description="High-performance 1-bit LLM inference engine (CUDA)"
CMD ["server"]