MCPcopy Create free account
hub / github.com/apple/ml-sharp / hard_sigmoid_with_pushback

Function hard_sigmoid_with_pushback

src/sharp/utils/math.py:170–178  ·  view source on GitHub ↗

Apply hard sigmoid with pushback. For compatibility reasons, we follow the default PyTorch implementation with a default slope of 1/6: https://pytorch.org/docs/stable/generated/torch.nn.Hardsigmoid.html

(x: torch.Tensor, slope: float = 1.0 / 6.0)

Source from the content-addressed store, hash-verified

168
169
170def hard_sigmoid_with_pushback(x: torch.Tensor, slope: float = 1.0 / 6.0) -> torch.Tensor:
171 """Apply hard sigmoid with pushback.
172
173 For compatibility reasons, we follow the default PyTorch implementation with a
174 default slope of 1/6:
175
176 https://pytorch.org/docs/stable/generated/torch.nn.Hardsigmoid.html
177 """
178 return clamp_with_pushback(slope * x + 0.5, min=0.0, max=1.0)
179
180
181def relu_with_pushback(x: torch.Tensor) -> torch.Tensor:

Callers

nothing calls this directly

Calls 1

clamp_with_pushbackFunction · 0.85

Tested by

no test coverage detected