跳至主要内容

測試與 CI

TinyLoop 目前驗證分為三層:

  1. CUDA 側 unit 測試
  2. 生成與 parity regression
  3. self-hosted CUDA CI 串接

CTest 覆蓋

目前測試包含:

測試用途
tinyloop.test_int2_kernelINT2 kernel 正確性
tinyloop.test_opsLayerNorm、residual、embedding、fused op 覆蓋
tinyloop.test_attentionAttention 正確性,含 production-shape prefill 檢查
tinyloop.test_kv_cacheKV-cache helper 正確性
tinyloop.test_fp16_gemmFP16 GEMM 正確性
tinyloop.test_decode_paritycached vs uncached decode 的 hidden/logit parity
tinyloop.test_generate_regressionraw-byte CLI 生成 parity
tinyloop.test_generate_tokenizer_regressiontokenizer-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_regressionprefix-cache parity
tinyloop.test_int4_kernelINT4 kernel 正確性
tinyloop.test_ropeRoPE kernel parity(prefill、decode、V-slice 不變性)
tinyloop.test_gqaGQA attention(MHA parity、較少 KV heads、cached decode、cache append)
tinyloop.test_fused_ln_qkv融合 LN+QKV kernel parity 與 norm 輸出
tinyloop.test_variable_l_parityVariable-L logit-lens parity(L=16
tinyloop.test_memory_leak5 次 load/unload GPU 記憶體成長偵測
tinyloop.test_fuzz隨機 seq_len/L/tokens fuzzing(50 次迭代)
tinyloop.test_kv_cache_regression27 點 cached vs uncached 多 token parity 掃描
tinyloop.test_constrained_decodingregex/choice/JSON-shape 約束式生成
tinyloop.test_paged_attentionPaged KV pool、page table、paged vs contiguous parity

工具:

工具用途
tools/perf_regression.py效能基線比較與回歸偵測
tools/trace_to_chrome.pyCUDA profile → chrome://tracing JSON
tools/trace_tokens.pyToken 軌跡 — 每迭代 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 模組建置支援
  • numpy
  • transformers
  • 有時需 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,非現有保證。