Skip to content

Fix PyTorch bool dtype promotion#3435

Merged
FlorianPfaff merged 3 commits into
mainfrom
fix-pytorch-bool-dtype-promotion
Jun 29, 2026
Merged

Fix PyTorch bool dtype promotion#3435
FlorianPfaff merged 3 commits into
mainfrom
fix-pytorch-bool-dtype-promotion

Conversation

@FlorianPfaff

Copy link
Copy Markdown
Owner

Summary

  • Add a PyTorch backend compatibility shim that replaces convert_to_wider_dtype with a torch.promote_types-based implementation.
  • Wire the shim into backend support initialization so raw PyTorch helpers use the corrected promotion behavior.
  • Add regression tests for mixed boolean/numeric allclose and isclose inputs.

Bug fixed

The PyTorch backend's promotion table did not include bool/uint8 and other non-default numeric dtypes. Mixed boolean/numeric comparisons such as allclose(bool_tensor, uint8_tensor) and isclose(bool_tensor, float_tensor) could therefore leave incompatible dtypes unchanged and raise a Torch dtype mismatch, while NumPy promotes the operands and succeeds.

Testing

  • Added tests/backend_support/test_pytorch_dtype_promotion_contract.py.
  • Not run locally in this connector environment; CI should execute the regression tests.

@github-actions

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 67.03s
✅ JSON prettier 7 0 0 0 0.69s
✅ JSON v8r 7 0 0 4.47s
✅ MARKDOWN markdownlint 68 0 0 0 1.57s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 0.43s
✅ PYTHON black 1127 11 0 0 56.15s
✅ PYTHON isort 1127 16 0 0 3.4s
✅ REPOSITORY checkov yes no no 43.54s
✅ REPOSITORY gitleaks yes no no 11.01s
✅ REPOSITORY git_diff yes no no 0.19s
✅ REPOSITORY secretlint yes no no 40.05s
✅ REPOSITORY syft yes no no 5.81s
✅ REPOSITORY trivy-sbom yes no no 5.67s
✅ REPOSITORY trufflehog yes no no 18.35s
✅ YAML prettier 11 0 0 0 0.69s
✅ YAML v8r 11 0 0 10.2s
✅ YAML yamllint 11 0 0 0.45s

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.5.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_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 force-pushed the fix-pytorch-bool-dtype-promotion branch from 809c622 to bbc5c54 Compare June 29, 2026 15:36
@FlorianPfaff FlorianPfaff merged commit 3c728d8 into main Jun 29, 2026
8 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