Views
No views yet
.pte files: run the encoder once per image, the
decoder once per click.mobilesam_encoder_xnnpack_fp32.pte (28.3 MB) — image (1,3,1024,1024) →
image_embed (1,256,64,64)mobilesam_encoder_xnnpack_int8.pte (14.0 MB) — same, dynamically quantized,
corr 0.999880mobilesam_decoder_xnnpack_fp32.pte (20.5 MB) — (image_embed,
points (1,N,2) fp32 pixel coords in 1024-space, labels (1,N) fp32 1=fg/0=bg)
→ mask logits (1,3,256,256), iou scores (1,3)mobilesam_decoder_xnnpack_fp16.pte (10.5 MB) — same decoder, corr 0.999825model.half() in eager already
returns corr -0.37 against the fp32 model. Dynamic int8 is the size lever here
instead, and it holds at corr 0.9999. The decoder has no int8 build for the opposite
reason: it came out at 21.8 MB, larger than its own fp32 file, because a dynamically
quantized transformer leaves the decoder's large constant positional embedding in
fp32 and adds quantization metadata on top.| graph | output | shape | max_abs_diff | corr |
|---|---|---|---|---|
| encoder | image_embed | [1, 256, 64, 64] | 3.815e-06 | 1.000000 |
| decoder | mask logits | [1, 3, 256, 256] | 1.717e-05 | 1.000000 |
| decoder | iou | [1, 3] | 1.192e-07 | 1.000000 |
TwoWayTransformer.forward
opens with image_pe.flatten(2).permute(0, 2, 1). That input is constant for a
fixed image size, and leaving the reshape in the graph corrupts the block that
consumes it — layer 0's keys came out at corr 0.78 against eager. Handing the
transformer the already-flat tensor restores corr 1.000000. This reproduces with no
delegate at all, and every operator involved verifies clean in isolation, so it is
worth knowing about rather than rediscovering.point_embedding[labels == -1] = 0.0 and three more masked +=. torch.export turns
each into an index_put behind a nonzero, which is a data-dependent shape. The
equivalent emb * (1 - m) + m * w form has fixed shapes and no runtime guards.repeat_interleave is dropped. The mask decoder calls
torch.repeat_interleave(x, tokens.shape[0], dim=0) with one point batch — a no-op
whose lowered form the delegate mis-sizes. Note this model uses the functional form,
not the tensor method.