Skip to content

SAM 3 skeleton test: compare against a float32 load and find the RoPE tables by any spelling - #14318

Merged
danielhanchen merged 1 commit into
mainfrom
ci/sam3-rope-buffer-names
Oct 20, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci/sam3-rope-buffer-names

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

(Python 3.13, a-k) fails on every PR since #14310 merged (for example #14316 and #14317, both on base fb372c1):

studio/backend/tests/test_diffusion_segment_quant.py: in test_skeleton_buffers_match_from_pretrained
    assert dense.keys() == built.keys() and any("rope" in name for name in dense)

#14310 showed the same failure on its own run before merging. Reproduced locally with transformers 5.18 (CI resolves 5.17.0); the 4.57 floor has no Sam3Model, so the test skips there.

There are two layers:

  1. With transformers 5.x the RoPE buffers are named rotary_emb.inv_freq, rotary_emb.original_inv_freq and position_ids; none contains rope.
  2. Behind that check, the dtype comparison fails as well: from_pretrained(dtype = bfloat16) casts the ViT's position_ids to bf16 on 5.18, while _build_skeleton builds them in float32 on purpose. They are not just a different dtype: layer 1 (global attention) has different values in bf16, and swapping the skeleton's buffers into the dense model changes the vision encoder output. That is exactly the 0.04 shift the test's docstring describes, so the skeleton is right and a bf16 load is not a valid reference.

Fix

Test only:

  • The reference is from_pretrained(dtype = float32), the exact tables the skeleton is meant to reproduce on every transformers version.
  • The RoPE presence check matches rope, rotary or position_ids.

Testing

  • test_diffusion_segment_quant.py with transformers 5.18: 37 passed, 3 skipped. On main the skeleton test fails as in CI.
  • Building the skeleton without _default_dtype(torch.float32) (the regression the test exists for) makes it fail on position_ids.
  • test_diffusion_segment.py with test_diffusion_segment_quant.py: 109 passed, 3 skipped.

Not covered here

The dense bf16 path (Sam3Model.from_pretrained(..., dtype = dtype) in diffusion_segment.py) gets the rounded position_ids on 5.18, so on that release its masks differ from the pre-quantized path's. That is a product question for the segmenter, separate from this CI fix.

… tables by any spelling

On transformers 5.x the RoPE buffers are rotary_emb.inv_freq and position_ids, so the 'rope' name check failed every PR's (Python 3.13, a-k) shard. Behind it, from_pretrained(dtype = bfloat16) casts the global-attention position_ids to bf16 on some 5.x releases, so the reference is now a float32 load, which is what the skeleton deliberately builds.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T07:43:36.930587Z c16baf0 Manual request
🔒 Security Review ⚠️ Failed 2026-10-20T07:41:46.868180Z c16baf0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: c16baf0bf6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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