pytorch - 💡(How to fix) Fix torch.softmax is not a true alias for torch.nn.functional.softmax [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#181663Fetched 2026-04-28 06:23:54
View on GitHub
Comments
0
Participants
1
Timeline
45
Reactions
0
Author
Participants
Timeline (top)
mentioned ×20subscribed ×20labeled ×5

Error Message

Traceback (most recent call last): File "<input>", line 1, in <module> TypeError: softmax() received an invalid combination of arguments - got (Tensor), but expected one of:

  • (Tensor input, int dim, torch.dtype dtype = None, *, Tensor out = None)
  • (Tensor input, name dim, *, torch.dtype dtype = None)

Code Example

import torch

t = torch.zeros(5)
torch.nn.functional.softmax(t)  # Ok
torch.softmax(t)  # Raising TypeError

---

Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: softmax() received an invalid combination of arguments - got (Tensor), but expected one of:
 * (Tensor input, int dim, torch.dtype dtype = None, *, Tensor out = None)
 * (Tensor input, name dim, *, torch.dtype dtype = None)
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

The dim argument is required for torch.softmax and optional for torch.nn.functional.softmax.

It should be optional in both cases, as the former is an alias for the latter.

import torch

t = torch.zeros(5)
torch.nn.functional.softmax(t)  # Ok
torch.softmax(t)  # Raising TypeError
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: softmax() received an invalid combination of arguments - got (Tensor), but expected one of:
 * (Tensor input, int dim, torch.dtype dtype = None, *, Tensor out = None)
 * (Tensor input, name dim, *, torch.dtype dtype = None)

Versions

torch 2.11.0

cc @albanD @mruberry @jbschlosser @walterddr @mikaylagawarecki

extent analysis

TL;DR

The dim argument should be made optional for torch.softmax to match the behavior of torch.nn.functional.softmax.

Guidance

  • Verify the behavior of torch.nn.functional.softmax without the dim argument to confirm it is optional.
  • Check the documentation for torch.softmax to see if there are any known issues or limitations related to the dim argument.
  • Consider passing the dim argument to torch.softmax to resolve the immediate error, even if it should be optional.
  • Review the implementation of torch.softmax to see if it is indeed an alias for torch.nn.functional.softmax and if the discrepancy is a bug.

Example

import torch

t = torch.zeros(5)
torch.softmax(t, dim=0)  # Pass dim argument to resolve error

Notes

The fix may require updating the torch.softmax function to make the dim argument optional, which could involve modifying the PyTorch library.

Recommendation

Apply workaround by passing the dim argument to torch.softmax until the discrepancy between torch.softmax and torch.nn.functional.softmax is resolved.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING