Skip to content

[Fix] Torch random.shuffle(axis=-1) mishandles negative axes#23119

Open
ChiragSW wants to merge 1 commit into
keras-team:masterfrom
ChiragSW:issue#23118
Open

[Fix] Torch random.shuffle(axis=-1) mishandles negative axes#23119
ChiragSW wants to merge 1 commit into
keras-team:masterfrom
ChiragSW:issue#23118

Conversation

@ChiragSW

Copy link
Copy Markdown
Contributor

Description

Fixes: #23118
axis now goes through canonicalize_axis(). Added a small test for axis=-1.

Contributor Agreement

Please review our AI-Assisted Contribution Policy and check all boxes below before submitting your PR for review:

  • I am a human, and not a bot.
  • I will be responsible for responding to review comments in a timely manner.
  • I will work with the maintainers to push this PR forward until submission.

Note: Failing to adhere to this agreement may result in your future PRs no longer being reviewed.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the PyTorch backend's random.shuffle implementation to support negative axes by using canonicalize_axis. It also adds a test case in keras/src/random/random_test.py to verify that shuffling works correctly with axis=-1. There are no review comments, and I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@codecov-commenter

codecov-commenter commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.24%. Comparing base (e0bfa2d) to head (67f8e00).

❗ There is a different number of reports uploaded between BASE (e0bfa2d) and HEAD (67f8e00). Click for more details.

HEAD has 18 uploads less than BASE
Flag BASE (e0bfa2d) HEAD (67f8e00)
keras 9 3
keras-tpu 2 0
keras-jax 3 0
keras-cpu 5 3
keras-numpy 1 0
keras-torch 2 1
keras-tensorflow 2 1
keras-gpu 2 0
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #23119      +/-   ##
==========================================
- Coverage   84.69%   75.24%   -9.46%     
==========================================
  Files         464      464              
  Lines       68957    68959       +2     
  Branches    11331    11331              
==========================================
- Hits        58404    51888    -6516     
- Misses       7624    14364    +6740     
+ Partials     2929     2707     -222     
Flag Coverage Δ
keras 75.11% <100.00%> (-9.39%) ⬇️
keras-cpu 75.11% <100.00%> (-8.76%) ⬇️
keras-gpu ?
keras-jax ?
keras-numpy ?
keras-openvino 59.51% <50.00%> (+<0.01%) ⬆️
keras-tensorflow 59.52% <50.00%> (-0.29%) ⬇️
keras-torch 58.65% <100.00%> (-0.40%) ⬇️
keras-tpu ?

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ChiragSW

ChiragSW commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

I don't know why the one numpy test is failing. It's passing on my machine with numpy backend.
Logs:

PS C:\Users\watta\hive\keras> $env:KERAS_BACKEND='numpy'   
PS C:\Users\watta\hive\keras> pytest keras/src/ops/image_test.py::ImageOpsDtypeTest::test_perspective_transform_bfloat16
===================================================== test session starts =====================================================
platform win32 -- Python 3.10.9, pytest-9.0.2, pluggy-1.6.0 -- C:\Users\watta\AppData\Local\Programs\Python\Python310\python.exe
cachedir: .pytest_cache
rootdir: C:\Users\watta\hive\keras
configfile: pyproject.toml
plugins: anyio-4.11.0, langsmith-0.4.38
collected 1 item                                                                                                               

keras/src/ops/image_test.py::ImageOpsDtypeTest::test_perspective_transform_bfloat16 PASSED                               [100%]

====================================================== 1 passed in 2.28s ======================================================

@hertschuh please help me out here

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Torch random.shuffle(axis=-1) mishandles negative axes

3 participants