Skip to content

[CI-only] SOFIE LogSoftmax fix (format fixes applied) - #3

Open
aniruddhaadak80 wants to merge 2 commits into
masterfrom
fix-sofie-logsoftmax-underflow
Open

aniruddhaadak80 wants to merge 2 commits into
masterfrom
fix-sofie-logsoftmax-underflow

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Owner

Internal PR to run ROOT CI while the upstream run on root-project#23551 awaits maintainer approval.

…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
…gSoftmax fix

The formatting checks flagged the lines added by the previous commit:

- clang-format 20 wants the one-line loop bodies split and `size - 1` spaced,
  so the new generic-path block is now written the way .clang-format formats
  those lines. Only the host code is reformatted; the inference code that
  ROperator_Softmax emits is unchanged.
- ruff format, which the CI runs with --preview over the changed ranges, wants
  double quotes, so the new make_LogSoftmax* builders use them. The surrounding
  functions in generate_input_models.py still use single quotes, but they lie
  outside the changed ranges the check covers and are left untouched.

Verified with the same commands the CI runs: clang-format-20 restricted to the
diff hunks via --lines, and ruff format --diff --preview --range over the
Python hunks. Both are clean now.
@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

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

Test Results

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit c99473b.

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