Skip to content

[codex] Fix PyTorch choice without replacement#1841

Merged
FlorianPfaff merged 3 commits intomainfrom
codex/fix-pytorch-choice-replace
Apr 25, 2026
Merged

[codex] Fix PyTorch choice without replacement#1841
FlorianPfaff merged 3 commits intomainfrom
codex/fix-pytorch-choice-replace

Conversation

@FlorianPfaff
Copy link
Copy Markdown
Owner

Summary

  • Fix the PyTorch backend random.choice(..., replace=False) path to sample unique indices with torch.randperm instead of torch.randint.
  • Normalize PyTorch choice size handling so sampled indices are reshaped to the requested output size.
  • Add a PyTorch-only regression test that samples the full population without replacement and verifies the results are unique.

Root cause

The unweighted PyTorch choice branch ignored replace=False and always used torch.randint, which samples each index independently and can return duplicates.

Validation

  • Not run locally; this session has a read-only filesystem, so the change was made through the GitHub connector. CI should run on the PR.

@FlorianPfaff FlorianPfaff marked this pull request as ready for review April 25, 2026 07:46
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 25, 2026

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 15.61s
✅ JSON prettier 2 0 0 0 0.59s
✅ JSON v8r 2 0 0 2.77s
✅ MARKDOWN markdownlint 2 0 0 0 0.72s
✅ MARKDOWN markdown-table-formatter 2 0 0 0 0.22s
✅ PYTHON bandit 382 0 0 6.28s
✅ PYTHON black 382 33 0 0 11.52s
✅ PYTHON flake8 382 0 0 3.4s
✅ PYTHON isort 382 36 0 0 0.79s
✅ PYTHON mypy 382 0 0 5.54s
✅ PYTHON pylint 382 0 0 121.29s
✅ PYTHON ruff 382 36 0 0 0.09s
✅ REPOSITORY checkov yes no no 24.45s
✅ REPOSITORY gitleaks yes no no 7.99s
✅ REPOSITORY git_diff yes no no 0.05s
✅ REPOSITORY secretlint yes no no 7.67s
✅ REPOSITORY syft yes no no 6.04s
✅ REPOSITORY trivy-sbom yes no no 2.12s
✅ REPOSITORY trufflehog yes no no 20.5s
✅ YAML prettier 4 0 0 0 0.52s
✅ YAML v8r 4 0 0 6.05s
✅ YAML yamllint 4 0 0 0.47s

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.4.0 --custom-flavor-setup --custom-flavor-linters PYTHON_PYLINT,PYTHON_BLACK,PYTHON_FLAKE8,PYTHON_ISORT,PYTHON_BANDIT,PYTHON_MYPY,PYTHON_RUFF,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

@github-actions
Copy link
Copy Markdown
Contributor

Test Results

    12 files  +    4      12 suites  +4   4h 49m 35s ⏱️ + 3h 3m 55s
 1 091 tests +    1   1 091 ✅ +    1      0 💤 ±  0  0 ❌ ±0 
13 376 runs  +4 444  10 276 ✅ +3 672  3 100 💤 +772  0 ❌ ±0 

Results for commit 593b3da. ± Comparison against base commit 24543a9.

@FlorianPfaff FlorianPfaff enabled auto-merge (squash) April 25, 2026 10:22
@FlorianPfaff FlorianPfaff merged commit dc8dc2b into main Apr 25, 2026
17 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