pytorch - 💡(How to fix) Fix Softplus degenerates incorrectly [1 comments, 2 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#180193Fetched 2026-04-13 05:35:23
View on GitHub
Comments
1
Participants
2
Timeline
16
Reactions
0
Participants
Timeline (top)
mentioned ×5subscribed ×5labeled ×4closed ×1

Code Example

import torch
import torch.nn.functional as F

x = torch.tensor([0.5, 1.0, 2.0])
cpu = F.softplus(x, beta=1e30, threshold=float('inf'))
gpu = F.softplus(x.cuda(), beta=1e30, threshold=float('inf')).cpu()

print("CPU:", cpu.tolist())       # BUG: [inf, inf, inf]
print("GPU:", gpu.tolist())       # BUG: [inf, inf, inf]
print("Expected: [0.5, 1.0, 2.0]")
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

import torch
import torch.nn.functional as F

x = torch.tensor([0.5, 1.0, 2.0])
cpu = F.softplus(x, beta=1e30, threshold=float('inf'))
gpu = F.softplus(x.cuda(), beta=1e30, threshold=float('inf')).cpu()

print("CPU:", cpu.tolist())       # BUG: [inf, inf, inf]
print("GPU:", gpu.tolist())       # BUG: [inf, inf, inf]
print("Expected: [0.5, 1.0, 2.0]")

Versions

[inf, inf, inf] [inf, inf, inf] Expected: [0.5, 1.0, 2.0]

cc @albanD @mruberry @jbschlosser @walterddr @mikaylagawarecki

extent analysis

TL;DR

The issue can be resolved by adjusting the beta parameter in the F.softplus function to a smaller value, as the current value of 1e30 is causing the function to produce infinite values.

Guidance

  • The beta parameter in F.softplus controls the steepness of the softplus function, and a very large value like 1e30 can lead to infinite outputs for small inputs.
  • Try reducing the beta value to a smaller number, such as 1 or 10, to see if it produces the expected results.
  • The threshold parameter is set to float('inf'), which means it will not have any effect on the output, so adjusting the beta value is the most likely solution.
  • Verify the results by printing the output of F.softplus with the adjusted beta value and comparing it to the expected output.

Example

import torch
import torch.nn.functional as F

x = torch.tensor([0.5, 1.0, 2.0])
cpu = F.softplus(x, beta=1, threshold=20)
gpu = F.softplus(x.cuda(), beta=1, threshold=20).cpu()

print("CPU:", cpu.tolist())
print("GPU:", gpu.tolist())

Notes

The issue may be specific to the version of PyTorch being used, and adjusting the beta value may not work for all versions.

Recommendation

Apply workaround: Adjust the beta value in the F.softplus function to a smaller number, such as 1 or 10, to avoid producing infinite outputs.

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