Skip to content

Fix arange and logit behavior for torch-nightly CI - #2974

Open
justinchuby with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-ci
Open

Fix arange and logit behavior for torch-nightly CI#2974
justinchuby with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-ci

Conversation

Copilot AI commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Cherry-pick of commit 6c844d3 from copilot/follow-up-bincount-index-put to fix torch-nightly CI failures in aten_arange and aten_logit.

aten_arange / aten_arange_start / aten_arange_start_step

torch-nightly changed the semantics of arange when an integral dtype is requested but one or more inputs are non-integral (e.g. torch.arange(3.1, dtype=torch.int64) now returns 4 elements, not 3). The fix:

  • Detects the behavior at import time via _INT64_ARANGE_NON_INTEGRAL_USES_FLOAT_LENGTH
  • Routes mixed integral/float inputs through a new helper _arange_integral_dtype_with_non_integral_args that computes the length in float then indexes via Range(0, length, 1) multiplied by step, rather than passing the raw float bounds to op.Range
# torch-nightly: torch.arange(3.1, dtype=torch.int64) → tensor([0, 1, 2, 3])  (len=4)
# previously matched old behavior (len=3); now correctly matches new behavior

aten_logit

The previous two-step clamp (min then max) gave wrong results when eps > 0.5 because 1 - eps < eps. Fixed by applying max (lower bound) first, then min (upper bound), matching torch.clamp order.

# eps=0.6 → one_minus_eps=0.4; old code could clamp self to [0.4,…] then force to 0.6
# new code: clamp to [0.6,…] first, then cap at 0.4 → correct torch behavior

Copilot AI requested review from Copilot and removed request for Copilot July 24, 2026 14:46
Copilot AI linked an issue Jul 24, 2026 that may be closed by this pull request
Copilot AI requested review from Copilot and removed request for Copilot July 24, 2026 14:51
Copilot AI changed the title [WIP] Fix CI by cherry picking commit 6c844d3 Fix arange and logit behavior for torch-nightly CI Jul 24, 2026
Copilot AI requested a review from justinchuby July 24, 2026 14:52
@justinchuby
justinchuby marked this pull request as ready for review July 24, 2026 15:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the TorchLib ONNX-function implementations in core.py to match recent torch-nightly behavioral changes that were causing CI failures, specifically around aten::arange* integer-dtype edge cases with non-integral inputs and aten::logit clamping when eps > 0.5.

Changes:

  • Add an import-time torch behavior probe and route mixed integral/float arange inputs through a new helper that computes sequence length in float.
  • Adjust aten::arange.start_step branching so the “special integral dtype” adjustment applies in the intended cases.
  • Fix aten::logit clamping order to match torch.clamp semantics for eps > 0.5.

Comment on lines +59 to +61
_INT64_ARANGE_NON_INTEGRAL_USES_FLOAT_LENGTH = (
torch.arange(3.1, dtype=torch.int64).numel() == 4
)
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.64%. Comparing base (00de62e) to head (8334fcb).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
onnxscript/function_libs/torch_lib/ops/core.py 80.00% 5 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2974   +/-   ##
=======================================
  Coverage   72.64%   72.64%           
=======================================
  Files         265      265           
  Lines       32192    32222   +30     
  Branches     3038     3044    +6     
=======================================
+ Hits        23385    23408   +23     
- Misses       7776     7781    +5     
- Partials     1031     1033    +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Fix CI

3 participants