Skip to content

Fix SuperPoint torch.export by replacing data-dependent shapes - #48950

Open
shreyescodes wants to merge 3 commits into
huggingface:mainfrom
shreyescodes:fix-superpoint-export
Open

shreyescodes wants to merge 3 commits into
huggingface:mainfrom
shreyescodes:fix-superpoint-export

Conversation

@shreyescodes

@shreyescodes shreyescodes commented Sep 19, 2026

Copy link
Copy Markdown

CPU CI GPU run-slow

This PR makes the SuperPoint model compatible with torch.export by removing data-dependent shape operations, addressing the SuperPoint portion of #48243.

Previously, SuperPointInterestPointDecoder._extract_keypoints relied on boolean masking and torch.nonzero() to filter keypoints, which resulted in dynamic tensor shapes that blocked tracing. I replaced this with a static-shaped approach using torch.topk and score penalties (-inf) for threshold and border constraints. The output is now a fixed-size tensor padded to max_keypoints, with a validity mask.

Since the output shape is now static across the batch, I also refactored the main forward method to process the entire batch directly without needing the Python list comprehension loop.

All tests pass locally, including the test_torch_export_static tests which I've unskipped for this model.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

馃煛 Changes recommended

The default configuration does not preserve the existing eager and integration output contract.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

This PR updates SuperPoint keypoint extraction for static-shape torch.export compatibility.

Changes:

  • Replaces dynamic masking with penalized topk selection and validity masks.
  • Batches decoding and enables static export tests with max_keypoints=64.
File Summary
tests/鈥媘odels/鈥媠uperpoint/鈥媡est_modeling_superpoint.py Enables static export coverage with a fixed keypoint limit.
src/鈥媡ransformers/鈥媘odels/鈥媠uperpoint/鈥媘odeling_superpoint.py Implements static keypoint selection and batched decoding. A critical issue remains: the default max_keypoints=-1 changes eager keypoint behavior, ordering, and output shape.

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/transformers/models/superpoint/modeling_superpoint.py
@Rocketknight1

Copy link
Copy Markdown
Member

cc @IlyasMoutawwakil since you commented on the original issue!

@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: superpoint

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 35629355081:2
Result: success | Jobs: 2 | Tests: 26 | Failures: 0 | Duration: 3m 8s

This branch has not been deployed

No deployments
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.

3 participants