Skip to content

[Model] Enable CLIP vision backbone (issue #252) - #293

Merged
YWHyuk merged 2 commits into
feature/togsim-cpp-tracefrom
feature/clip-conv-mapping
Jul 9, 2026
Merged

YWHyuk merged 2 commits into
feature/togsim-cpp-tracefrom
feature/clip-conv-mapping

Conversation

@YWHyuk

@YWHyuk YWHyuk commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Enables the CLIP vision backbone with batch > 1, resolving #252. The vision transformer now compiles and matches CPU end to end (max diff ~1e-5). Adds tests/models/test_clip.py as a self-hosted CI job and lists CLIP in the README model coverage.

Root cause. A CLIP ViT-B/32 patch embedding is a Conv2d(3, 768, kernel_size=32, stride=32). At batch > 1 this routes to conv_multi_tile_mapping, which collects every tile that fits SPAD into tile_candidates (returned sorted) but guarded the "Cannot find a valid mapping" error on max_used_spad_size instead of on tile_candidates. max_used_spad_size is only bumped when a candidate also satisfies max_k_h_w <= k_h, and max_k_h_w is initialized to K_W, so it only ever fires for the full-kernel (k_h == K_H) tile. That full-kernel tile overflows SPAD at batch > 1 (its per-lane footprint exceeds the budget), so the guard raised even though smaller-k_h tiles fit and were already in tile_candidates. The mapping variable it tracks is never returned.

Fix. Guard on not tile_candidates instead, so a conv is rejected only when no tile fits at all. The returned candidate list is unchanged, so convs that already compiled are unaffected; only the wrongly-rejected batched convs now proceed.

Verification.

  • CLIP vision (CLIPVisionModel, patch 32, batch 2) matches CPU end to end (max diff ~1e-5).
  • Added test_conv2d.py batched patch-conv case: fails with "Cannot find a valid mapping" before the fix, passes after.
  • test_cnn and the existing test_conv2d cases are unchanged.

YWHyuk added 2 commits July 9, 2026 16:04
conv_multi_tile_mapping (used for batch > 1 convs) collects every tile
that fits SPAD into tile_candidates and returns them sorted, but it
guarded the "no mapping" error on max_used_spad_size instead of on
tile_candidates. max_used_spad_size is only bumped when a candidate also
satisfies max_k_h_w <= k_h, and max_k_h_w is initialized to K_W, so it
only ever fires for the full-kernel (k_h == K_H) tile. When that tile
overflows SPAD -- e.g. a CLIP ViT-B/32 patch conv (3->768, 32x32 stride
32) at batch > 1 -- the guard raised "Cannot find a valid mapping" even
though smaller-k_h tiles fit and were already in tile_candidates. The
mapping variable it tracks is never returned.

Guard on `not tile_candidates` instead, so the conv is rejected only
when no tile fits at all. The returned candidate list is unchanged, so
convs that already worked are unaffected. Adds a batched patch-conv case
to test_conv2d.py. Fixes issue #252.
With the conv-mapping fix, CLIP's vision transformer runs with batch > 1
and matches CPU end to end (max diff ~1e-5). Add tests/models/test_clip.py
(CLIPVisionModel, batch 2, patch 32), wire it as a self-hosted CI job,
and list CLIP in the README model coverage.
@YWHyuk
YWHyuk merged commit ae26ede into feature/togsim-cpp-trace Jul 9, 2026
@YWHyuk
YWHyuk deleted the feature/clip-conv-mapping branch July 14, 2026 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant