Test engine compilation
Browse files- test_engine_compile.py +76 -0
test_engine_compile.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Test if the Lila engine compiles correctly."""
|
| 3 |
+
import subprocess, os
|
| 4 |
+
|
| 5 |
+
TOKEN = "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"
|
| 6 |
+
subprocess.run(["git", "clone", f"https://{TOKEN}@github.com/ticketguy/Lila.git", "/app/lila"], check=True)
|
| 7 |
+
os.chdir("/app/lila/engine")
|
| 8 |
+
|
| 9 |
+
# Install nasm for x86_64 assembly
|
| 10 |
+
subprocess.run(["apt-get", "update", "-qq"], check=False)
|
| 11 |
+
subprocess.run(["apt-get", "install", "-y", "-qq", "nasm", "gcc", "make"], check=False)
|
| 12 |
+
|
| 13 |
+
print("\n=== Checking tools ===")
|
| 14 |
+
subprocess.run(["gcc", "--version"], check=False)
|
| 15 |
+
subprocess.run(["nasm", "--version"], check=False)
|
| 16 |
+
subprocess.run(["uname", "-m"], check=False)
|
| 17 |
+
|
| 18 |
+
print("\n=== Attempting build ===")
|
| 19 |
+
result = subprocess.run(["make"], capture_output=True, text=True)
|
| 20 |
+
print("STDOUT:", result.stdout)
|
| 21 |
+
print("STDERR:", result.stderr)
|
| 22 |
+
print("Return code:", result.returncode)
|
| 23 |
+
|
| 24 |
+
if result.returncode == 0:
|
| 25 |
+
print("\n✅ ENGINE COMPILED SUCCESSFULLY")
|
| 26 |
+
# Test it
|
| 27 |
+
result2 = subprocess.run(["./lila-engine", "--test"], capture_output=True, text=True)
|
| 28 |
+
print("Test output:", result2.stdout)
|
| 29 |
+
print("Test errors:", result2.stderr)
|
| 30 |
+
else:
|
| 31 |
+
print("\n❌ COMPILATION FAILED")
|
| 32 |
+
print("Errors:", result.stderr[:2000])
|
| 33 |
+
|
| 34 |
+
# Try compiling just the C files without assembly (to test C code correctness)
|
| 35 |
+
print("\n=== Trying C-only build (no assembly) ===")
|
| 36 |
+
c_files = [
|
| 37 |
+
"runtime/model.c", "runtime/inference.c", "runtime/attention.c",
|
| 38 |
+
"runtime/transformer.c", "runtime/tokenizer.c", "runtime/detect.c",
|
| 39 |
+
"runtime/dispatch.c", "interface/cli.c"
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
# Create stub for assembly symbols
|
| 43 |
+
with open("/tmp/stubs.c", "w") as f:
|
| 44 |
+
f.write("""
|
| 45 |
+
#include <stdint.h>
|
| 46 |
+
void lila_matvec_avx2(float *out, const float *mat, const float *vec, int rows, int cols) {
|
| 47 |
+
for (int i = 0; i < rows; i++) {
|
| 48 |
+
float sum = 0.0f;
|
| 49 |
+
for (int j = 0; j < cols; j++) sum += mat[i*cols+j] * vec[j];
|
| 50 |
+
out[i] = sum;
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
void lila_rmsnorm_avx2(float *out, const float *x, const float *weight, int size, float eps) {
|
| 54 |
+
float ss = 0.0f;
|
| 55 |
+
for (int i = 0; i < size; i++) ss += x[i]*x[i];
|
| 56 |
+
ss = 1.0f / __builtin_sqrtf(ss/size + eps);
|
| 57 |
+
for (int i = 0; i < size; i++) out[i] = x[i] * ss * weight[i];
|
| 58 |
+
}
|
| 59 |
+
void lila_dequant_int4_avx2(float *o, const uint8_t *idx, const float *cb, const float *sc, int n, int gs) {}
|
| 60 |
+
""")
|
| 61 |
+
|
| 62 |
+
cmd = ["gcc", "-O2", "-Wall", "-std=c11", "-o", "lila-engine-c"] + c_files + ["/tmp/stubs.c", "-lm", "-lpthread", "-I", "runtime/"]
|
| 63 |
+
result3 = subprocess.run(cmd, capture_output=True, text=True)
|
| 64 |
+
print("C-only STDOUT:", result3.stdout)
|
| 65 |
+
print("C-only STDERR:", result3.stderr[:2000])
|
| 66 |
+
|
| 67 |
+
if result3.returncode == 0:
|
| 68 |
+
print("\n✅ C CODE COMPILES (assembly stubs used)")
|
| 69 |
+
result4 = subprocess.run(["./lila-engine-c", "--test"], capture_output=True, text=True)
|
| 70 |
+
print("Test:", result4.stdout, result4.stderr)
|
| 71 |
+
else:
|
| 72 |
+
print("\n❌ C compilation also failed")
|
| 73 |
+
# Show specific errors
|
| 74 |
+
for line in result3.stderr.split('\n')[:20]:
|
| 75 |
+
if 'error' in line.lower():
|
| 76 |
+
print(f" ERROR: {line}")
|