fn
logsumexp
→Tensorlogsumexp(input: Tensor, dim: int | Sequence[int] | None = ..., keepdim: bool = ...)Compute the numerically stable log-sum-exp along dim.
Combines exp, sum and log in a single fused
operation, subtracting the per-slice maximum before exponentiation to
avoid overflow. This is the canonical normaliser of categorical
log-probabilities and the smooth approximation of max.
Parameters
inputTensorInput tensor (real-valued).
dimint or sequence of int= ...Dimension(s) over which to reduce.
keepdimbool= FalseKeep reduced dims with size 1 if
True.Returns
TensorReduced tensor.
Notes
The stable formulation is
which avoids inf even when x has large positive components.
LSE is convex, satisfies , and its gradient is the softmax.
Examples
>>> import lucid
>>> x = lucid.tensor([1000.0, 1000.0, 1000.0])
>>> lucid.logsumexp(x, dim=0)
Tensor(1001.0986)