測試與 CI
TinyLoop 目前驗證分為三層:
- CUDA 側 unit 測試
- 生成與 parity regression
- self-hosted CUDA CI 串接
CTest 覆蓋
目前測試包含:
| 測試 | 用途 |
|---|---|
tinyloop.test_int2_kernel | INT2 kernel 正確性 |
tinyloop.test_ops | LayerNorm、residual、embedding、fused op 覆蓋 |
tinyloop.test_attention | Attention 正確性,含 production-shape prefill 檢查 |
tinyloop.test_kv_cache | KV-cache helper 正確性 |
tinyloop.test_fp16_gemm | FP16 GEMM 正確性 |
tinyloop.test_decode_parity | cached vs uncached decode 的 hidden/logit parity |
tinyloop.test_generate_regression | raw-byte CLI 生成 parity |
tinyloop.test_generate_tokenizer_regression | tokenizer-aware Python 生成 parity |
tinyloop.test_generate_eval_slice | 小型 eval-slice parity 覆蓋 |
tinyloop.test_speculative_greedy_regression | 推測式 greedy parity |
tinyloop.test_speculative_sampling_regression | 推測式 sampling parity |
tinyloop.test_prefix_cache_regression | prefix-cache parity |
tinyloop.test_int4_kernel | INT4 kernel 正確性 |
tinyloop.test_rope | RoPE kernel parity(prefill、decode、V-slice 不變性) |
tinyloop.test_gqa | GQA attention(MHA parity、較少 KV heads、cached decode、cache append) |
tinyloop.test_fused_ln_qkv | 融合 LN+QKV kernel parity 與 norm 輸出 |
tinyloop.test_variable_l_parity | Variable-L logit-lens parity(L=16) |
tinyloop.test_memory_leak | 5 次 load/unload GPU 記憶體成長偵測 |
tinyloop.test_fuzz | 隨機 seq_len/L/tokens fuzzing(50 次迭代) |
tinyloop.test_kv_cache_regression | 27 點 cached vs uncached 多 token parity 掃描 |
tinyloop.test_constrained_decoding | regex/choice/JSON-shape 約束式生成 |
tinyloop.test_paged_attention | Paged KV pool、page table、paged vs contiguous parity |
工具:
| 工具 | 用途 |
|---|---|
tools/perf_regression.py | 效能基線比較與回歸偵測 |
tools/trace_to_chrome.py | CUDA profile → chrome://tracing JSON |
tools/trace_tokens.py | Token 軌跡 — 每迭代 argmax 翻轉 |
tools/convert.py | 統一 PyTorch → .tinyloop 轉換器 |
本機指令
執行整套測試:
ctest --test-dir tinyloop/build --output-on-failure
搭配模型 artifact:
TINYLOOP_TEST_MODEL_PATH=/absolute/path/to/model.tinyloop \
ctest --test-dir tinyloop/build --output-on-failure
Skip 語義
模型相依測試在缺少前置時會使用 skip code 77。
這表示:
- 缺少模型 artifact 不會污染整體測試結果
- 缺少 Python 綁定支援不會把可選測試誤判為失敗
Python 相依 regression
Tokenizer-aware 與 eval 相關 regression 需要:
pybind11- Python 模組建置支援
numpytransformers- 有時需
datasets
若環境缺少,測試會乾淨地 skip。
直接 regression 腳本
執行 raw-byte CLI regression:
TINYLOOP_TEST_BINARY=/path/to/tinyloop \
TINYLOOP_TEST_MODEL_PATH=/path/to/model.tinyloop \
python tinyloop/tests/test_generate_regression.py
執行 tokenizer-aware parity:
TINYLOOP_TEST_BUILD_DIR=/path/to/tinyloop/build \
TINYLOOP_TEST_MODEL_PATH=/path/to/model.tinyloop \
python tinyloop/tests/test_generate_tokenizer_regression.py
執行 prefix-cache parity:
TINYLOOP_TEST_BUILD_DIR=/path/to/tinyloop/build \
TINYLOOP_TEST_MODEL_PATH=/path/to/model.tinyloop \
python tinyloop/tests/test_prefix_cache_regression.py
Microbenchmark
bench_hot_ops 不只是方便用的 binary,它是驗證 hot path 變更最快的方法,涵蓋:
- QKV projection
- attention output projection
- prefill attention
- cached decode attention
- SwiGLU
- down projection
- head projection
GitHub Actions
倉庫內含 self-hosted CUDA workflow:
.github/workflows/cuda-ci.yml
目前流程:
- 安裝 Python 相依
- 設定建置
- 建置專案
- 執行 CTest
CI 目前尚未涵蓋
目前 CI 尚未提供:
- 自動化效能回歸追蹤
- 多 GPU 家族覆蓋
- release artifact 產出
- 端到端 serving 測試
這些仍是 roadmap,非現有保證。