Skip to content

Support multidimensional PyTorch quantiles#4491

Merged
FlorianPfaff merged 3 commits into
mainfrom
agent/fix-pytorch-multidimensional-quantiles
Jul 17, 2026
Merged

Support multidimensional PyTorch quantiles#4491
FlorianPfaff merged 3 commits into
mainfrom
agent/fix-pytorch-multidimensional-quantiles

Conversation

@FlorianPfaff

Copy link
Copy Markdown
Owner

Bug

The PyTorch backend passed q directly to torch.quantile. NumPy permits quantile arrays with arbitrary shape, but PyTorch accepts only a scalar or one-dimensional q tensor. Consequently, valid calls such as a 2 x 2 quantile grid raised:

RuntimeError: quantile() q must be a scalar or 1D tensor

The failure affected both the public PyTorch backend and the raw backend, including tuple-axis reductions. The existing empty-batch compatibility path also failed while validating multidimensional quantiles.

Fix

  • flatten multidimensional q only for the native torch.quantile call
  • reshape the result back to NumPy's q.shape + reduced_shape contract
  • preserve integer-input promotion before converting quantiles
  • retain tuple-axis, keepdims, out, and empty-batch behavior
  • apply the repair consistently to public and raw PyTorch backend entry points

Regression coverage

  • compares 2 x 2 quantile grids against numpy.quantile
  • covers integer inputs and tuple-axis reductions with keepdims=True
  • verifies multidimensional quantiles preserve empty non-reduced batch dimensions

Validation

  • reproduced the current failure with PyTorch 2.10.0
  • syntax-compiled the modified source and regression test
  • ran an exact wrapper smoke harness covering public/raw behavior, integer inputs, tuple axes, keepdims, and empty batch dimensions
  • branch is limited to two files and is based directly on current main

The full repository and backend matrices should run in GitHub Actions.

@FlorianPfaff
FlorianPfaff enabled auto-merge (squash) July 17, 2026 01:51
@github-actions

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 24.85s
✅ JSON prettier 7 0 0 0 1.02s
✅ JSON v8r 7 0 0 5.5s
✅ MARKDOWN markdownlint 68 0 0 0 1.94s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 1.05s
✅ PYTHON black 1550 199 0 0 98.16s
✅ PYTHON isort 1550 370 0 0 2.77s
✅ REPOSITORY betterleaks yes no no 2.42s
✅ REPOSITORY checkov yes no no 54.52s
✅ REPOSITORY gitleaks yes no no 15.7s
✅ REPOSITORY git_diff yes no no 0.33s
✅ REPOSITORY secretlint yes no no 60.42s
✅ REPOSITORY syft yes no no 6.27s
✅ REPOSITORY trivy-sbom yes no no 7.53s
✅ REPOSITORY trufflehog yes no no 32.46s
✅ YAML prettier 11 0 0 0 0.67s
✅ YAML v8r 11 0 0 12.48s
✅ YAML yamllint 11 0 0 0.58s

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 merged commit 4bc5041 into main Jul 17, 2026
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