Skip to content

[CI-only] SOFIE LogSoftmax numerical stability fix - #1

Closed
aniruddhaadak80 wants to merge 1 commit into
masterfrom
fix-sofie-logsoftmax-underflow
Closed

aniruddhaadak80 wants to merge 1 commit into
masterfrom
fix-sofie-logsoftmax-underflow

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Owner

Internal PR to run the ROOT CI (ROOT CI / code analysis / Test Coverage) against this branch before a maintainer approves the upstream run on root-project#23551. Not intended for merging.

…ximum

ROperator_Softmax computed LogSoftmax as log(softmax(x)): it normalized
exp(x - max) by the sum and then took the log of the result. When an input is
more than ~88 below the maximum, exp(x - max) underflows to 0 in float, so the
log returns -inf instead of a large negative number, and values close to the
underflow lose precision as well (e.g. -99.98 instead of -100).

Evaluate the numerically stable form (x - max) - log(sum(exp(x - max)))
instead, which does not depend on exp(x - max) staying above the underflow
threshold. Both code paths of the operator are fixed: the contiguous last-axis
case and the generic strided case. The plain Softmax path is unchanged.

There were no LogSoftmax tests, so this adds five ONNX test models
(LogSoftmax1d/2d/3d for the ordinary cases, plus LogSoftmaxLargeRange and
LogSoftmaxLargeRangeAxis0, which cover both code paths with inputs 100 apart
and returned -inf before). The reference outputs of the two large-range models
are computed with the stable formula in double precision, because onnx.reference
computes log(softmax(x)) and is wrong for the same reason.

Fixes root-project#23547
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing

@aniruddhaadak80

Copy link
Copy Markdown
Owner Author

Reopening to re-trigger CI now that Actions are enabled on the fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant