← Back to Pull requests

Raise math.exp2/log2 to stablehlo.exp2/log2 and support those ops #3708

Closed
unknown closed this pull request without merging on Oct 27, 2026 18:31 UTC
View on GitHub
unknown unknown commented on Oct 27, 2026 00:43 UTC
Author

StableHLO 1.23 (in the XLA main now pins) added stablehlo.exp2 and stablehlo.log2, and XLA has kExp2/kLog2 with elemental emitters for them. Until now math.exp2 and math.log2 (which the libdevice raising produces for __nv_exp2, __nv_log2, __nv_fast_log2f, and which exp10 is lowered through) were rescaled onto the natural forms: exp2(x) -> exp(x ln 2) and log2(x) -> log(x) (1/ln 2), an extra multiply and a rounding error per element.

This raises them to the dedicated ops and gives those ops the same treatment the other unary transcendentals have:

  • arith-raise: math.log2 -> stablehlo.log2 and math.exp2 -> stablehlo.exp2 (and mhlo.log2/mhlo.exp2 on the mhlo path) through RaiseUnary; the RaiseLog2/RaiseExp2 rescaling patterns are gone. log10 still rescales since stablehlo has no base-10 log.

  • Constant propagation: exp2_const_prop, log2_const_prop (via the reference interpreter's exp2Op/log2Op), added to enzyme-hlo-opt and to the C-API pipeline next to the other unary const props.

  • CSE: cse_exp2, cse_log2.

  • unary_pad_push_exp2, matching unary_pad_push_exp.

  • log2_simplify: log2(exp2 x) -> x, log2(exp x) -> x log2 e, log2(sqrt x) -> log2(x) / 2, log2(rsqrt x) -> -log2(x) / 2; log_simplify gains log(exp2 x) -> x ln 2.

  • Derivatives: d/dx 2^x = 2^x ln 2, d/dx log2 x = 1 / (x ln 2).

  • The no-NaN / finite / non-negative result analyses in Utils.cpp treat exp2 like exp.
  • LICM and the other structural patterns (reshape/transpose/broadcast pushing, while hoisting) key off the Elementwise/pure traits and need no per-op registration.

    Tests: raising/arith_raise_log_exp_base.mlir updated; new diffrules/stablehlo/exp2.mlir, diffrules/stablehlo/log2.mlir (forward, reverse and interpreter checks), exp2_log2_const_prop.mlir, log2simplify.mlir, cse_exp2_log2.mlir.

    Reactant.jl does not yet expose Ops.exp2/Ops.log2 (its log2 goes through log(x)/log(2)); that is a follow-up once a JLL carries this.

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01K1GPCnUaQKiMLASni1N1eu

    Diff: 268 lines (+201 / -67) across 3 files Reviewer: ftynse Review duration: 1067m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.39) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 268 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.335
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3708"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.4% (MEDIUM) · Higher = larger blast radius
    39.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17% · Safe to merge
    17%