xnn.common.models.ops.exact_softplus#

xnn.common.models.ops.exact_softplus(x)[source]#

Evaluate log(1 + exp(x)) exactly to round-off, with exact derivatives.

One fused torch.nn.functional.softplus() kernel per pass in eager mode (two selections around log1p(exp(-|x|)) under TorchScript). The fused kernel returns x above its threshold and so drops the tail log(1 + exp(-x)), which is below the rounding of the value and of the derivative sigmoid(x) once exp(-threshold) is: a threshold of 40 in float64 (exp(-40) = 4e-18) and 20 otherwise (exp(-20) = 2e-9), against the default 20 that drops 2e-9 in float64.

Parameters:

x (Tensor) – Input values of any shape.

Returns:

Softplus values with the same shape as x.

Return type:

Tensor