Skip to content

[BUG] LoweringException: RuntimeError: Cannot find a valid mapping for Clip model with batch size > 1 #252

Closed

Description

@oluwatimilehin

Describe the bug
Hello,

I have written a simple program to run some vision models from HuggingFace in this gist: https://gist.github.com/oluwatimilehin/db204bcab6eb7531173453a2e4ed7e8e

When I run the script for clip with any batch size greater than 1, like:

python vision_models.py -m clip -b 8

I get the error: LoweringException: RuntimeError: Cannot find a valid mapping with the full message as follows:

Received error running CLIPForImageClassification(
  (vision_model): CLIPVisionTransformer(
    (embeddings): CLIPVisionEmbeddings(
      (patch_embedding): Conv2d(3, 768, kernel_size=(32, 32), stride=(32, 32), bias=False)
      (position_embedding): Embedding(50, 768)
    )
    (pre_layrnorm): LayerNorm((768,), eps=1e-05, elementwise_affine=True)
    (encoder): CLIPEncoder(
      (layers): ModuleList(
        (0-11): 12 x CLIPEncoderLayer(
          (self_attn): CLIPSdpaAttention(
            (k_proj): Linear(in_features=768, out_features=768, bias=True)
            (v_proj): Linear(in_features=768, out_features=768, bias=True)
            (q_proj): Linear(in_features=768, out_features=768, bias=True)
            (out_proj): Linear(in_features=768, out_features=768, bias=True)
          )
          (layer_norm1): LayerNorm((768,), eps=1e-05, elementwise_affine=True)
          (mlp): CLIPMLP(
            (activation_fn): QuickGELUActivation()
            (fc1): Linear(in_features=768, out_features=3072, bias=True)
            (fc2): Linear(in_features=3072, out_features=768, bias=True)
          )
          (layer_norm2): LayerNorm((768,), eps=1e-05, elementwise_affine=True)
        )
      )
    )
    (post_layernorm): LayerNorm((768,), eps=1e-05, elementwise_affine=True)
  )
  (classifier): Linear(in_features=768, out_features=2, bias=True)
): LoweringException: RuntimeError: Cannot find a valid mapping
  target: aten.convolution.default
  args[0]: TensorBox(StorageBox(
    InputBuffer(name='arg0_1', layout=FixedLayout('npu:0', torch.float32, size=[32, 3, 224, 224], stride=[150528, 50176, 224, 1]))
  ))
  args[1]: TensorBox(StorageBox(
    InputBuffer(name='arg1_1', layout=FixedLayout('npu:0', torch.float32, size=[768, 3, 32, 32], stride=[3072, 1, 96, 3]))
  ))
  args[2]: None
  args[3]: [32, 32]
  args[4]: [0, 0]
  args[5]: [1, 1]
  args[6]: False
  args[7]: [0, 0]
  args[8]: 1

The error is from this function, but I haven't dug much deeper. Could you please look into this?

Thanks!

Activity

  1. added
    bug
    on May 28, 2026
  2. YWHyuk commented on Jul 9, 2026

    @YWHyuk
    Collaborator

    Fixed in #293. The CLIP vision backbone now runs with batch > 1 and matches the CPU reference end to end (max abs diff ~1e-5).

    The Cannot find a valid mapping came from the conv tile-mapping search, not the conv itself. A CLIP ViT-B/32 patch embedding is a Conv2d(3, 768, kernel_size=32, stride=32); at batch > 1 it routes to conv_multi_tile_mapping, which collects all SPAD-fitting tiles into tile_candidates (and returns them) but guarded the error on a separate max_used_spad_size counter. That counter only advances for the full-kernel (k_h == K_H) tile, which overflows SPAD once the batch is large enough — so it raised even though smaller-k_h tiles fit and were already collected. The guard now checks tile_candidates directly, so a conv is rejected only when no tile fits at all.

    A CLIPVisionModel test (tests/models/test_clip.py) and a batched patch-conv case in test_conv2d.py were added, and CLIP is now listed in the README model coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Work in Progressbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions