Skip to content

docs: fix out_dtype signatures for bmm, mm, addmm, baddbmm#179182

Closed
satishkc7 wants to merge 1 commit into
pytorch:mainfrom
satishkc7:docs/fix-out-dtype-optional-signatures
Closed

docs: fix out_dtype signatures for bmm, mm, addmm, baddbmm#179182
satishkc7 wants to merge 1 commit into
pytorch:mainfrom
satishkc7:docs/fix-out-dtype-optional-signatures

Conversation

@satishkc7

Copy link
Copy Markdown
Contributor

Fixes #172751

Summary

torch.bmm, torch.mm, torch.addmm, and torch.baddbmm document out_dtype=None as the default value for that parameter. However, passing out_dtype=None explicitly raises a TypeError at runtime because the C++ dispatcher resolves overloads structurally and does not accept None for a dtype argument.

As suggested by @albanD, this PR updates the docstrings to show two explicit signatures for each function:

  • One without out_dtype (the common case)
  • One with out_dtype as a required positional argument (when dtype casting is needed)

This follows the existing pattern used for torch.max, torch.min, and other functions with multiple overloads.

Changes

  • torch/_torch_docs.py: updated addmm, baddbmm, bmm, and mm docstrings

Test plan

  • Verify rendered docs show two overload signatures per function
  • Confirm no other references to out_dtype=None remain in affected docstrings

These functions document out_dtype=None as an optional default, but
passing None explicitly raises a TypeError at runtime. Show two
explicit overloads instead: one without out_dtype and one with it
as a required argument, consistent with the actual C++ dispatch behavior.
@pytorch-bot pytorch-bot Bot added the release notes: python_frontend python frontend release notes category label Apr 2, 2026
@pytorch-bot

pytorch-bot Bot commented Apr 2, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/179182

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ You can merge normally! (5 Unrelated Failures)

As of commit 7aff08c with merge base c44b2f2 (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Apr 2, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: satishkc7 / name: Satish K C (7aff08c)

@mikaylagawarecki

Copy link
Copy Markdown
Contributor

@claude review this PR

@claude

claude Bot commented Apr 3, 2026

Copy link
Copy Markdown

Claude finished @mikaylagawarecki's task in 1m 25s —— View job


Review of PR #179182

  • Read the changed file and understand the diff
  • Check existing patterns for multi-signature docstrings (e.g., torch.max, torch.min)
  • Verify consistency across all four updated functions
  • Verify against native_functions.yaml that out_dtype is indeed a separate overload
  • Post review feedback

Summary

This PR correctly fixes the documented signatures for torch.addmm, torch.baddbmm, torch.bmm, and torch.mm. The previous docs showed out_dtype=None as an optional keyword-style parameter, but at the C++ dispatcher level these are separate overloads (e.g., bmm.dtype(Tensor self, Tensor mat2, ScalarType out_dtype)) where out_dtype is a required positional ScalarType, not an optional. Passing None at runtime raises a TypeError.

The fix follows the established pattern used by torch.max/torch.min — showing two .. function:: blocks with :noindex:, which is the right approach.

Detailed Feedback

Looks good overall. The changes are consistent across all four functions, the .. function:: / :noindex: pattern matches existing conventions, and out_dtype=None references are fully removed.

One minor observation:

Nit — the second overload blocks for addmm and baddbmm duplicate the beta, alpha, and out keyword args. This is technically correct for completeness (and torch.max similarly repeats its args in each signature block), so I'd consider this acceptable. Just noting that there's a small maintenance cost — if the description of beta/alpha changes in the future, it would need updating in two places per function. This is not a blocking concern.

LGTM — this is a clean, well-scoped docs fix.

@drisspg drisspg added the topic: docs topic category label Apr 20, 2026
@drisspg drisspg requested a review from albanD April 20, 2026 16:42
@albanD

albanD commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

@claude use the pr-review skill to review this

@claude

claude Bot commented Apr 22, 2026

Copy link
Copy Markdown

Claude finished @albanD's task in 2m 10s —— View job


PR Review: #179182

  • Read the changed file and understand the diff
  • Check existing patterns for multi-signature docstrings
  • Verify against native_functions.yaml that out_dtype is separate overloads
  • Check formatting consistency across all four functions
  • Post review feedback

Summary

Clean docs fix that correctly addresses #172751. The previous signatures documented out_dtype=None as an optional kwarg, but in native_functions.yaml these are structurally separate overloads (e.g., bmm.dtype(Tensor self, Tensor mat2, ScalarType out_dtype)) where out_dtype is a required positional ScalarType. Passing None at runtime raises TypeError. The fix uses the established .. function:: / :noindex: pattern already used by torch.max, torch.min, torch.normal, etc.

Code Quality

The formatting is correct and consistent across all four functions:

  • .. function:: at column 0 with :noindex: indented 3 spaces — matches existing convention
  • out_dtype is correctly documented as a required positional arg (dtype) rather than optional
  • The out_dtype description properly ends with a period (the old version was inconsistent — comma in some places, no punctuation in others)
  • bmm and mm correctly use Keyword Args: (with capital A) matching their primary signature blocks, while addmm and baddbmm use Keyword args: (lowercase a) — also matching their respective primary blocks

One observation worth noting:

  • addmm and baddbmm duplicate beta, alpha, and out kwargs in the second overload block. This is technically correct and matches how torch.max duplicates its args across overloads. However, bmm and mm avoid duplication by only listing the differing args plus {out}. Both approaches are acceptable per existing conventions, but the inconsistency between the four functions in this PR is slightly unfortunate. Since the addmm/baddbmm overloads have beta and alpha as keyword-only args that aren't in bmm/mm, duplicating them is reasonable for completeness — a reader of the out_dtype overload needs to know those kwargs exist.

Backward Compatibility

No BC concerns — this is a docs-only change with no functional code modifications.

Recommendation

Approve

This is a well-scoped, correct docs fix that follows established patterns. The changes accurately reflect the actual C++ dispatcher overload structure in native_functions.yaml.


@albanD albanD added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Apr 22, 2026

@albanD albanD left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@albanD

albanD commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Apr 22, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged open source release notes: python_frontend python frontend release notes category topic: docs topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

torch.bmm doesn't accept out_dtype=None, contradicting the docs

6 participants