Repository navigation
[Model] Enable CLIP vision backbone (issue #252) - #293
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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). Addstests/models/test_clip.pyas 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). Atbatch > 1this routes toconv_multi_tile_mapping, which collects every tile that fits SPAD intotile_candidates(returned sorted) but guarded the "Cannot find a valid mapping" error onmax_used_spad_sizeinstead of ontile_candidates.max_used_spad_sizeis only bumped when a candidate also satisfiesmax_k_h_w <= k_h, andmax_k_h_wis initialized toK_W, so it only ever fires for the full-kernel (k_h == K_H) tile. That full-kernel tile overflows SPAD atbatch > 1(its per-lane footprint exceeds the budget), so the guard raised even though smaller-k_htiles fit and were already intile_candidates. Themappingvariable it tracks is never returned.Fix. Guard on
not tile_candidatesinstead, 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.
CLIPVisionModel, patch 32, batch 2) matches CPU end to end (max diff ~1e-5).test_conv2d.pybatched patch-conv case: fails with "Cannot find a valid mapping" before the fix, passes after.test_cnnand the existingtest_conv2dcases are unchanged.