-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
140 lines (117 loc) · 4.43 KB
/
Dockerfile
File metadata and controls
140 lines (117 loc) · 4.43 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
# =============================================================================
# HyperTensor — Dockerfile
#
# Produces a reproducible research image with:
# - All C build tools and LAPACKE
# - Python 3.12 + core research dependencies
# - libhypercore.so compiled and installed
# - A non-root user `researcher` ready to run reproducibility scripts
#
# Build:
# docker build -t hypertensor .
#
# Run Path A (CPU mathematical verification, no GPU needed):
# docker run --rm hypertensor python scripts/faithfulness_rigorous.py
#
# Interactive shell:
# docker run --rm -it hypertensor bash
#
# Core reproducibility scripts are the intended default entry point.
# =============================================================================
FROM ubuntu:24.04 AS base
# Avoid interactive prompts from apt
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=UTC
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
RUN apt-get update && apt-get install -y --no-install-recommends \
# Build toolchain
build-essential \
cmake \
ninja-build \
pkg-config \
git \
# LAPACK / BLAS (OpenBLAS ships LAPACKE)
libopenblas-dev \
liblapacke-dev \
# Python
python3.12 \
python3.12-dev \
python3.12-venv \
python3-pip \
# Utilities
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Make python3.12 the default python3
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1
# =============================================================================
# Stage: build — compile libhypercore.so
# =============================================================================
FROM base AS build
WORKDIR /src
# Copy only the files needed for the C build (keeps this layer cache-friendly)
COPY CMakeLists.txt .
COPY hypercore/hypercore.c hypercore/hypercore.h hypercore/
COPY lib/ lib/
RUN cmake -B /build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DHT_BUILD_RUNTIME=OFF \
-DHT_BUILD_TESTS=OFF \
-GNinja \
&& cmake --build /build --parallel \
&& cmake --install /build
# =============================================================================
# Stage: python-deps — install Python packages into a venv
# =============================================================================
FROM base AS python-deps
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Core research dependencies (no GPU torch; override with build-arg if needed)
ARG TORCH_INDEX="https://download.pytorch.org/whl/cpu"
RUN pip install --no-cache-dir \
numpy>=1.24 \
scipy>=1.11 \
mpmath>=1.3 \
sympy>=1.12 \
safetensors>=0.4
# Install torch CPU — override TORCH_INDEX for CUDA wheels:
# docker build --build-arg TORCH_INDEX=https://download.pytorch.org/whl/cu121 .
RUN pip install --no-cache-dir torch --index-url "${TORCH_INDEX}"
# HuggingFace stack (needed for Path B / model analysis)
RUN pip install --no-cache-dir \
transformers>=4.40 \
huggingface-hub>=0.22 \
accelerate>=0.29 \
bitsandbytes>=0.43 || true # bitsandbytes may fail on pure-CPU; that's OK
# =============================================================================
# Stage: final — lean runtime image
# =============================================================================
FROM base AS final
# Pull in compiled shared libraries
COPY --from=build /usr/local/lib/libhypercore* /usr/local/lib/
COPY --from=build /usr/local/include/hypertensor/ /usr/local/include/hypertensor/
RUN ldconfig
# Pull in Python venv
COPY --from=python-deps /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
ENV VIRTUAL_ENV=/opt/venv
# Copy project source
WORKDIR /workspace
COPY . /workspace
# Tell the ctypes wrapper where to find libhypercore.so
ENV HT_LIB_DIR=/usr/local/lib
# Create non-root user
RUN useradd -m -s /bin/bash researcher \
&& chown -R researcher:researcher /workspace
USER researcher
# Smoke-test that the library loads and Python imports work
RUN python -c "import sys; sys.path.insert(0, '.'); \
from hypercore import GeodesicMetric; \
print('hypercore import OK')"
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD python -c "import sys; sys.path.insert(0, '.'); import hypercore; print('healthy')"
# Default: run the CPU mathematical verification suite (Path A)
CMD ["python", "scripts/faithfulness_rigorous.py"]