-
Notifications
You must be signed in to change notification settings - Fork 1
295 lines (238 loc) · 10.3 KB
/
production.yml
File metadata and controls
295 lines (238 loc) · 10.3 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
name: Xerv Crayon Production Build
# ============================================================================
# TRIGGER CONDITIONS
# ============================================================================
on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main" ]
jobs:
# ==========================================================================
# JOB 1: INTEL/AMD CPU ENGINE (AVX2/AVX-512 Check)
# ==========================================================================
build-cpu:
name: 🔵 Build CPU (Intel/AMD)
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install pytest setuptools wheel build
- name: Compile Crayon (CPU Mode)
run: |
# This triggers setup.py to build CPU extensions
pip install -v . --no-build-isolation
- name: Verify CPU Extension
run: |
python -c "from crayon.c_ext import crayon_cpu; print('✅ CPU Engine Loaded')"
python -c "from crayon.c_ext import crayon_cpu; print(f'Hardware: {crayon_cpu.get_hardware_info()}')"
- name: Verify Trainer Extension
run: |
python -c "from crayon.c_ext import crayon_trainer; print('✅ Trainer Engine Loaded')"
python -c "from crayon.c_ext import crayon_trainer; print(f'Version: {crayon_trainer.get_version()}')"
python -c "from crayon.c_ext import crayon_trainer; print(f'Algorithm: {crayon_trainer.get_algorithm_info()}')"
- name: Run Basic Tokenization Test
run: |
python -c "
from crayon import CrayonVocab
v = CrayonVocab(device='cpu')
v.load_profile('lite') # LOAD PROFILE FIRST
result = v.tokenize('Hello Cloud! Testing CRAYON on GitHub Actions.')
print(f'✅ Tokenized to {len(result)} tokens')
print(f' Tokens: {result[:10]}...')
"
- name: Run Trainer Test
run: |
python -c "
from crayon.c_ext import crayon_trainer
# Test with minimal corpus
corpus = b'The quick brown fox jumps over the lazy dog. ' * 100
merges = crayon_trainer.train_fast(corpus, 300, min_freq=2, verbose=0)
print(f'✅ Trainer generated {len(merges)} merge rules')
print(f' First 3 merges: {merges[:3]}')
"
- name: Run pytest (Unit Tests)
run: |
pytest tests/ -v --tb=short || true
# ==========================================================================
# JOB 2: NVIDIA CUDA ENGINE (Compilation Verification)
# ==========================================================================
build-cuda:
name: 🟢 Build NVIDIA (CUDA 12)
runs-on: ubuntu-latest
# Use NVIDIA's official CUDA development container
container: nvidia/cuda:12.2.0-devel-ubuntu22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install Python & Dependencies
run: |
apt-get update
apt-get install -y python3 python3-pip python3-venv python3-dev git
python3 -m pip install --upgrade pip setuptools wheel
- name: Install PyTorch (CUDA)
run: |
# Install PyTorch with CUDA support for CUDAExtension
pip install torch --index-url https://download.pytorch.org/whl/cu121
- name: Compile Crayon (CUDA Mode)
run: |
# Force CUDA build
export CRAYON_FORCE_CUDA=1
pip install -v . --no-build-isolation
- name: Verify CUDA Extension Built
run: |
# Check if the CUDA shared object was created
find . -name "*crayon_cuda*.so" -o -name "*crayon_cuda*.pyd" | grep . && echo "✅ CUDA Binary Built!"
- name: Verify CPU Extension (Sanity Check)
run: |
python3 -c "from crayon.c_ext import crayon_cpu; print('✅ CPU Engine Loaded')"
- name: Verify Trainer Extension
run: |
python3 -c "from crayon.c_ext import crayon_trainer; print('✅ Trainer Engine Loaded')"
# ==========================================================================
# JOB 3: AMD ROCm ENGINE (Compilation Verification)
# ==========================================================================
build-rocm:
name: 🔴 Build AMD (ROCm 6.0)
runs-on: ubuntu-latest
# Use AMD's official ROCm development container
container: rocm/dev-ubuntu-22.04:6.0
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install Python & Dependencies
run: |
apt-get update
apt-get install -y python3 python3-pip python3-venv python3-dev git
python3 -m pip install --upgrade pip setuptools wheel
- name: Verify ROCm Installation
run: |
hipcc --version
echo "ROCM_HOME=${ROCM_HOME:-/opt/rocm}"
ls -la /opt/rocm/bin/ | head -20
- name: Compile Crayon (ROCm Mode)
run: |
# Force ROCm build
export CRAYON_FORCE_ROCM=1
export ROCM_HOME=/opt/rocm
pip install -v . --no-build-isolation
- name: Verify ROCm Extension Built
run: |
# Check if the ROCm shared object was created
find . -name "*crayon_rocm*.so" | grep . && echo "✅ ROCm Binary Built!"
- name: Verify CPU Extension (Sanity Check)
run: |
python3 -c "from crayon.c_ext import crayon_cpu; print('✅ CPU Engine Loaded')"
- name: Verify Trainer Extension
run: |
python3 -c "from crayon.c_ext import crayon_trainer; print('✅ Trainer Engine Loaded')"
# ==========================================================================
# JOB 4: WINDOWS CPU BUILD
# ==========================================================================
build-windows:
name: 🪟 Build Windows (CPU)
runs-on: windows-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install pytest setuptools wheel build
- name: Compile Crayon (Windows CPU)
run: |
pip install -v . --no-build-isolation
- name: Verify Extensions
run: |
python -c "from crayon.c_ext import crayon_cpu; print('✅ CPU Engine Loaded')"
python -c "from crayon.c_ext import crayon_trainer; print('✅ Trainer Engine Loaded')"
- name: Run Basic Test
run: |
python -c "from crayon import CrayonVocab; v = CrayonVocab(device='cpu'); v.load_profile('lite'); print(v.tokenize('Hello Windows!'))"
# ==========================================================================
# JOB 5: BENCHMARK (CPU Performance Validation)
# ==========================================================================
benchmark:
name: 📊 Benchmark Performance
runs-on: ubuntu-latest
needs: [build-cpu] # Only run after CPU build succeeds
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Crayon
run: |
pip install --upgrade pip setuptools wheel
pip install -v . --no-build-isolation
- name: Run Trainer Benchmark
run: |
python -c "
import time
from crayon.c_ext import crayon_trainer
# Generate test corpus
corpus = b'The quick brown fox jumps over the lazy dog. ' * 10000
corpus_mb = len(corpus) / (1024 * 1024)
print(f'Corpus Size: {corpus_mb:.2f} MB')
# Warmup
_ = crayon_trainer.train_fast(corpus[:10000], 300, verbose=0)
# Benchmark
start = time.perf_counter()
merges = crayon_trainer.train_fast(corpus, 1000, verbose=1)
elapsed = time.perf_counter() - start
print(f'\\n=== BENCHMARK RESULTS ===')
print(f'Merge Rules: {len(merges):,}')
print(f'Time: {elapsed:.2f}s')
print(f'Speed: {corpus_mb / elapsed:.2f} MB/s')
print(f'Merges/sec: {len(merges) / elapsed:,.0f}')
# Performance gate
if elapsed > 30:
print('⚠️ Warning: Training took longer than expected')
else:
print('✅ Performance acceptable')
"
- name: Run Tokenization Benchmark
run: |
python -c "
import time
from crayon import CrayonVocab
v = CrayonVocab(device='cpu')
v.load_profile('lite')
# Generate test text
text = 'The quick brown fox jumps over the lazy dog. ' * 10000
text_mb = len(text.encode('utf-8')) / (1024 * 1024)
# Warmup
_ = v.tokenize(text[:1000])
# Benchmark
iterations = 5
total_time = 0
total_tokens = 0
for _ in range(iterations):
start = time.perf_counter()
tokens = v.tokenize(text)
elapsed = time.perf_counter() - start
total_time += elapsed
total_tokens += len(tokens)
avg_time = total_time / iterations
avg_tokens = total_tokens / iterations
print(f'=== TOKENIZATION BENCHMARK ===')
print(f'Text Size: {text_mb:.2f} MB')
print(f'Avg Tokens: {avg_tokens:,.0f}')
print(f'Avg Time: {avg_time * 1000:.2f} ms')
print(f'Tokens/sec: {avg_tokens / avg_time:,.0f}')
print(f'MB/sec: {text_mb / avg_time:.2f}')
print('✅ Benchmark complete')
"