Skip to content

fix: SAM ModelSamVisionLayer missing batch size#262

Open
ziyuanguo1998 wants to merge 2 commits intomainfrom
ziyuan/fix-sam
Open

fix: SAM ModelSamVisionLayer missing batch size#262
ziyuanguo1998 wants to merge 2 commits intomainfrom
ziyuan/fix-sam

Conversation

@ziyuanguo1998
Copy link
Contributor

No description provided.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 17, 2026 10:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the ModSamVisionLayer class in the SAM ViT Base QNN model patches to correctly handle batch sizes greater than 1 in the window_partition and window_unpartition methods, and aligns the forward return type with its declared signature.

Changes:

  • Added the batch_size dimension to reshape calls in window_partition and window_unpartition, and updated the corresponding permute orderings from 5D to 6D to correctly handle arbitrary batch sizes.
  • Wrapped the forward method's return value in a tuple to match the declared return type annotation tuple[torch.FloatTensor].

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@ziyuanguo1998 ziyuanguo1998 changed the title fix: SAM ModelSamVisionLayer batch size fix: SAM ModelSamVisionLayer missing batch size Mar 17, 2026
Copy link
Contributor

@xieofxie xieofxie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is intentional as when we created this recipe, 6D or higher transfomations were not supported and removing batch_size reduced the dimensions to 5D

olive-ai==0.9.3, transformers==4.56.2 and torch==2.8.0 works

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.

5 participants