Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fusion script for segment anything v2 #22167

Merged
merged 2 commits into from
Sep 21, 2024
Merged

Add fusion script for segment anything v2 #22167

merged 2 commits into from
Sep 21, 2024

Conversation

tianleiwu
Copy link
Contributor

@tianleiwu tianleiwu commented Sep 20, 2024

Description

  • Add MultiHeadAttention fusion for SAM2.
  • Add LayerNormalization fusion for NCHW format by inserting Transpose from NCHW to NHWC before layer normalization, and add another Transpose after layer norm to convert NHWC back to NCHW. Hopefully, those extra Transpose nodes will be removed when prefer_nhwc is enabled later.
  • Add a condition that the input shall be 3D when fuse SkipLayerNorm.
  • Update convert_to_onnx.py to add --optimize and --use_gpu options to output optimized onnx model for CPU/CUDA eps.
  • Add an option --dtype fp16|fp32 in convert_to_onnx.py to support converting optimized model to float16.
  • Update the demo to use the optimized onnx models.

Motivation and Context

To support optimization of SAM2 for CPU/CUDA eps that is exported in #22119

@tianleiwu tianleiwu requested review from kunal-vaishnavi, wangyems and apsonawane and removed request for kunal-vaishnavi and wangyems September 20, 2024 18:50
@tianleiwu tianleiwu merged commit 1431215 into main Sep 21, 2024
87 checks passed
@tianleiwu tianleiwu deleted the tlwu/sam2_fusion branch September 21, 2024 04:32
tianleiwu added a commit that referenced this pull request Sep 21, 2024
### Description
Add benchmark script segment anything v2. 
It depends on #22119 for
onnx export, and #22167 for
sam2 graph fusion.

### Motivation and Context

Benchmark SAM2 model performance.
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.

2 participants