Skip to content

Reject overflowing PyTorch uniform ranges#4391

Merged
FlorianPfaff merged 3 commits into
mainfrom
agent/reject-overflowing-pytorch-uniform-range-20260714
Jul 14, 2026
Merged

Reject overflowing PyTorch uniform ranges#4391
FlorianPfaff merged 3 commits into
mainfrom
agent/reject-overflowing-pytorch-uniform-range-20260714

Conversation

@FlorianPfaff

@FlorianPfaff FlorianPfaff commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • reject finite PyTorch random.uniform bounds when their promoted floating-point span is not representable
  • compute the span after promoting integer/low-precision bounds to a safe arithmetic dtype
  • preserve the existing random-stream dtype and scalar/array broadcasting behavior
  • add a NumPy/PyTorch regression for the maximum-finite symmetric range

Bug

The PyTorch backend validated low and high independently as finite, then sampled with:

(high - low) * rand + low

For finite endpoints such as -np.finfo(np.float64).max and np.finfo(np.float64).max, high - low overflows to infinity. The sampler therefore returned non-finite values even though both inputs passed validation. NumPy rejects the same request with OverflowError.

Fix

Promote both validated bounds to the effective floating arithmetic dtype before subtraction, validate that the resulting span is finite, and raise OverflowError("high - low range exceeds valid bounds") when it is not. The random draw still uses the prior dtype path, so ordinary seeded sampling is unchanged.

Validation

  • reproduced the pre-fix PyTorch result as all-inf samples for the maximum-finite symmetric range
  • focused smoke test verifies the patched path raises OverflowError
  • focused smoke test verifies ordinary array-valued bounds still return finite in-range samples
  • seeded smoke test verifies the existing float64-bound RNG stream is preserved exactly
  • python -m py_compile passes for both modified files
  • branch is 3 commits ahead of and 0 behind main

The full repository test matrix is delegated to GitHub Actions.

@github-actions

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 20.19s
✅ JSON prettier 7 0 0 0 0.99s
✅ JSON v8r 7 0 0 4.0s
✅ MARKDOWN markdownlint 68 0 0 0 1.83s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 1.07s
✅ PYTHON black 1489 182 0 0 85.95s
✅ PYTHON isort 1489 327 0 0 2.55s
✅ REPOSITORY betterleaks yes no no 2.06s
✅ REPOSITORY checkov yes no no 53.88s
✅ REPOSITORY gitleaks yes no no 14.48s
✅ REPOSITORY git_diff yes no no 0.24s
✅ REPOSITORY secretlint yes no no 52.82s
✅ REPOSITORY syft yes no no 5.67s
✅ REPOSITORY trivy-sbom yes no no 6.22s
✅ REPOSITORY trufflehog yes no no 30.33s
✅ YAML prettier 11 0 0 0 0.7s
✅ YAML v8r 11 0 0 11.78s
✅ YAML yamllint 11 0 0 0.6s

Notices

📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining SECURITY_SUGGESTIONS: false)

See detailed reports in MegaLinter artifacts

Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining FLAVOR_SUGGESTIONS: false)

  • Documentation: Custom Flavors
  • Command: npx mega-linter-runner@9.6.0 --custom-flavor-setup --custom-flavor-linters PYTHON_BLACK,PYTHON_ISORT,COPYPASTE_JSCPD,JSON_V8R,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_GITLEAKS,REPOSITORY_BETTERLEAKS,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY_SBOM,REPOSITORY_TRUFFLEHOG,YAML_PRETTIER,YAML_YAMLLINT,YAML_V8R

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@FlorianPfaff FlorianPfaff marked this pull request as ready for review July 14, 2026 20:18
@FlorianPfaff FlorianPfaff merged commit 74ba226 into main Jul 14, 2026
16 of 26 checks passed
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