- Add conftest.py: shared paths, tolerances, skip markers, fixtures - Consolidate imports/shapes/smoke/forward → test_model_contract.py - Consolidate all parity (decoder/refiner/backbone/e2e) → test_parity.py - Fold 2048 slow test into test_engine.py - Rework test_conversion.py to use public convert_checkpoint() API - Simplify test_weights.py: drop CLI/env var tests, keep checksum+config - Rename tiling/compilation test files for consistency - Delete 10 redundant files 80 tests collected (75 pass, 4 skip, 1 deselected) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
72 lines
2.4 KiB
Python
72 lines
2.4 KiB
Python
"""Shared test fixtures, paths, tolerances, and skip markers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import mlx.core as mx
|
|
import numpy as np
|
|
import pytest
|
|
|
|
from corridorkey_mlx.model.corridorkey import GreenFormer
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Paths
|
|
# ---------------------------------------------------------------------------
|
|
GOLDEN_PATH = Path("reference/fixtures/golden.npz")
|
|
GOLDEN_WEIGHTS_PATH = Path("reference/fixtures/golden_weights.npz")
|
|
MLX_CHECKPOINT_PATH = Path("checkpoints/corridorkey_mlx.safetensors")
|
|
PT_CHECKPOINT_PATH = Path("checkpoints/CorridorKey_v1.0.pth")
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Tolerances
|
|
# ---------------------------------------------------------------------------
|
|
PARITY_TOL_TIGHT = 1e-4
|
|
PARITY_TOL_BACKBONE = 2e-2
|
|
PARITY_TOL_E2E = 1e-3
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Skip markers
|
|
# ---------------------------------------------------------------------------
|
|
has_golden = pytest.mark.skipif(not GOLDEN_PATH.exists(), reason="golden.npz not found")
|
|
has_checkpoint = pytest.mark.skipif(
|
|
not MLX_CHECKPOINT_PATH.exists(), reason="MLX checkpoint not found"
|
|
)
|
|
has_pt_checkpoint = pytest.mark.skipif(
|
|
not PT_CHECKPOINT_PATH.exists(), reason="PyTorch checkpoint not found"
|
|
)
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Shared fixtures
|
|
# ---------------------------------------------------------------------------
|
|
IMG_SIZE = 512
|
|
SMALL_IMG_SIZE = 256
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def golden_fixtures() -> dict[str, np.ndarray]:
|
|
"""Load golden.npz fixture file (PyTorch NCHW format)."""
|
|
if not GOLDEN_PATH.exists():
|
|
pytest.skip("golden.npz not found")
|
|
return dict(np.load(GOLDEN_PATH))
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def random_model() -> GreenFormer:
|
|
"""GreenFormer with random weights at 512."""
|
|
model = GreenFormer(img_size=IMG_SIZE)
|
|
model.eval()
|
|
# mx.eval is MLX array materialization, not Python eval()
|
|
mx.eval(model.parameters()) # noqa: S307
|
|
return model
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def loaded_model() -> GreenFormer:
|
|
"""GreenFormer with checkpoint weights at 512."""
|
|
if not MLX_CHECKPOINT_PATH.exists():
|
|
pytest.skip("MLX checkpoint not found")
|
|
model = GreenFormer(img_size=IMG_SIZE)
|
|
model.load_checkpoint(MLX_CHECKPOINT_PATH)
|
|
return model
|