feat(transformers/models): add models of Superglue and Superpoint#1348
feat(transformers/models): add models of Superglue and Superpoint#1348JIJIARONGjijiarong wants to merge 5 commits intomindspore-lab:masterfrom
Conversation
# Conflicts: # mindone/transformers/models/auto/configuration_auto.py
Summary of ChangesHello @JIJIARONGjijiarong, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces the SuperGlue and SuperPoint models, ported from the HuggingFace Transformers library. The implementation contains several critical bugs related to tensor shape manipulation and operations that could lead to runtime errors or incorrect model behavior. I have identified these issues and provided suggestions for fixes. Additionally, there are some minor bugs in the newly added test files that I've also pointed out.
| if keypoints.shape[2] == 0: # no keypoints | ||
| shape = keypoints.shape[:-1] | ||
| return ( | ||
| mint.full([shape, -1], dtype=mindspore.int32), |
There was a problem hiding this comment.
The shape argument for mint.full is incorrect. It is currently [shape, -1], which creates a list containing a tuple and an integer. This is not a valid shape for creating a tensor. The brackets [] should be removed to pass the shape tuple directly.
| mint.full([shape, -1], dtype=mindspore.int32), | |
| mint.full(shape, -1, dtype=mindspore.int32), |
| else: | ||
| extended_attention_mask = mint.ones( | ||
| (batch_size, num_keypoints), | ||
| ) |
There was a problem hiding this comment.
The extended_attention_mask is not created correctly when the input mask is None.
- The batch dimension of the created tensor is incorrect. It should be
descriptors.shape[0](which isbatch_size * 2) instead ofbatch_size. - The created 2D mask is not passed through
self.get_extended_attention_maskto convert it into the 4D format expected by the attention layers, which will cause a shape mismatch error during the forward pass.
| else: | |
| extended_attention_mask = mint.ones( | |
| (batch_size, num_keypoints), | |
| ) | |
| else: | |
| mask = mint.ones((descriptors.shape[0], num_keypoints)) | |
| input_shape = descriptors.shape | |
| extended_attention_mask = self.get_extended_attention_mask(mask, input_shape) |
| x_nchw = mint.unsqueeze(x, 0) | ||
| pooled_nchw = mint.functional.max_pool2d(x_nchw, kernel_size=kernel_size, stride=stride, padding=padding) | ||
| output = mint.squeeze(pooled_nchw, 0) |
There was a problem hiding this comment.
The max_pool implementation for 3D tensors is incorrect. Reshaping a (B, H, W) tensor to (1, B, H, W) with mint.unsqueeze(x, 0) causes max_pool2d to treat the batch dimension as the channel dimension, performing pooling across the batch. Pooling should be independent for each sample. The input to max_pool2d should be (B, 1, H, W), which can be achieved by using mint.unsqueeze(x, 1) and then squeezing dimension 1.
| x_nchw = mint.unsqueeze(x, 0) | |
| pooled_nchw = mint.functional.max_pool2d(x_nchw, kernel_size=kernel_size, stride=stride, padding=padding) | |
| output = mint.squeeze(pooled_nchw, 0) | |
| x_nchw = mint.unsqueeze(x, 1) | |
| pooled_nchw = mint.functional.max_pool2d(x_nchw, kernel_size=kernel_size, stride=stride, padding=padding) | |
| output = mint.squeeze(pooled_nchw, 1) |
| keypoints = keypoints / mindspore.tensor( | ||
| [width, height], | ||
| ) |
There was a problem hiding this comment.
There is a potential dtype mismatch in this division operation. keypoints is a float tensor, while mindspore.tensor([width, height]) creates an integer tensor. This can lead to type errors or unexpected behavior. To ensure correctness and robustness, the divisor should be explicitly cast to the same dtype as keypoints.
| keypoints = keypoints / mindspore.tensor( | |
| [width, height], | |
| ) | |
| keypoints = keypoints / mindspore.tensor( | |
| [width, height], dtype=keypoints.dtype | |
| ) |
| (pixel_values,), | ||
| {}, | ||
| { | ||
| "keypoints": 2, |
There was a problem hiding this comment.
| (pixel_values,), | ||
| {}, | ||
| { | ||
| "keypoints": 0, |
SamitHuang
left a comment
There was a problem hiding this comment.
why is fps of fp16 the same as that of fp32? is it typo?
Add
mindone.transformers.SuperGluePreTrainedModelmindone.transformers.SuperGlueForKeypointMatchingUsage
Performance Experiments are tested on Ascend Atlas 800T A2 machines with mindspore 2.6.0 pynative mode,
pipeline speed
Add
mindone.transformers.SuperPointForKeypointDetectionmindone.transformers.SuperPointPreTrainedModelUsage
Performance Experiments are tested on Ascend Atlas 800T A2 machines with mindspore 2.6.0 pynative mode,
pipeline speed