Skip to content

Fix test_gather_object assertion for Python 3.14 PicklingError - #192811

Closed
albmalamd wants to merge 1 commit into
pytorch:mainfrom
albmalamd:fix_pickle_error_handling_test_gather_object
Closed

albmalamd wants to merge 1 commit into
pytorch:mainfrom
albmalamd:fix_pickle_error_handling_test_gather_object

Conversation

@albmalamd

Copy link
Copy Markdown
Contributor

Summary

test_gather_object / test_gather_object_subgroup fail on Python 3.14. The test calls all_gather_object on a local class (unpicklable) and asserts an error. The exception type changed: <=3.13 raised AttributeError, but 3.14 (CPython gh-139806) raises PicklingError eagerly from pickle.whichmodule() for '<locals>' names. PicklingError is a PickleError, not an AttributeError, so the stale assertRaises(AttributeError) no longer matches.

Fix

Assert on the types raised across all supported versions (python_min_version = 3.10):

with self.assertRaises((AttributeError, pickle.PickleError)):
    dist.all_gather_object(...)

Test plan

On Python 3.14.4, assertRaises(AttributeError) around pickle.Pickler().dump() of a local class ERRORS with PicklingError, while assertRaises((AttributeError, pickle.PickleError)) PASSES; on 3.10-3.13 the real AttributeError is also matched (issubclass). Full test needs a 4-GPU nccl world:
python -m pytest torch/testing/_internal/distributed/distributed_test.py -k test_gather_object -v

@pytorch-bot

pytorch-bot Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/192811

Note: Links to docs will display an error until the docs builds have been completed.

❌ You can merge normally! (1 Unrelated Failure), 1 Unclassified Failure

As of commit a9ef75b with merge base eb99a65 (image):

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@jithunnair-amd jithunnair-amd added ciflow/periodic-rocm-mi350 Trigger "distributed_4gpu" config (only runs distributed tests that need >2GPUs) CI on ROCm MI350 ciflow/periodic-rocm-mi300 Trigger "distributed" config CI on ROCm MI300/MI325 ciflow/periodic-rocm-mi200 Trigger "distributed" config CI on ROCm MI200 labels Aug 10, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

Warning: Unknown label ciflow/periodic-rocm-mi350.
Currently recognized labels are

  • ciflow/b200
  • ciflow/b200-distributed
  • ciflow/b200-symm-mem
  • ciflow/binaries
  • ciflow/binaries_libtorch
  • ciflow/binaries_wheel
  • ciflow/docker
  • ciflow/dtensor
  • ciflow/h100
  • ciflow/h100-cutlass-backend
  • ciflow/h100-distributed
  • ciflow/h100-symm-mem
  • ciflow/inductor
  • ciflow/inductor-cu126
  • ciflow/inductor-micro-benchmark
  • ciflow/inductor-micro-benchmark-cpu-x86
  • ciflow/inductor-pallas
  • ciflow/inductor-perf-compare
  • ciflow/inductor-perf-test-nightly-rocm-mi300
  • ciflow/inductor-perf-test-nightly-rocm-mi350
  • ciflow/inductor-perf-test-nightly-x86-zen
  • ciflow/inductor-perf-test-nightly-xpu
  • ciflow/inductor-periodic
  • ciflow/inductor-rocm-mi200
  • ciflow/inductor-rocm-mi300
  • ciflow/mps
  • ciflow/nightly
  • ciflow/op-benchmark
  • ciflow/periodic
  • ciflow/periodic-rocm-mi200
  • ciflow/periodic-rocm-mi300
  • ciflow/pull
  • ciflow/riscv64
  • ciflow/rocm-mi200
  • ciflow/rocm-mi300
  • ciflow/rocm-navi31
  • ciflow/rocm-nightly
  • ciflow/rocm-preview
  • ciflow/s390
  • ciflow/slow
  • ciflow/slow-rocm-mi200
  • ciflow/torchtitan
  • ciflow/triton_binaries
  • ciflow/trunk
  • ciflow/tsan
  • ciflow/unstable
  • ciflow/win-arm64
  • ciflow/xpu

Please add the new label to .github/pytorch-probot.yml

@janeyx99 janeyx99 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Aug 11, 2026
The test all_gather_objects a local class (unpicklable) and asserts an
error. The exception type changed: <=3.13 raised AttributeError, but 3.14
(CPython pytorchgh-139806) raises PicklingError from pickle.whichmodule() for
'<locals>' names. PicklingError is a PickleError, not an AttributeError, so
the stale assertRaises(AttributeError) no longer matches.

Fix the assertion to (AttributeError, pickle.PickleError), correct across
all supported versions (python_min_version = 3.10) while staying tight. The
fix belongs in the test, not production: normalizing pickle's exception type
in _object_to_tensor would mask a legitimate CPython change.

Test Plan: on Python 3.14.4, assertRaises(AttributeError) around
pickle.Pickler().dump() of a local class ERRORS with PicklingError, while
assertRaises((AttributeError, pickle.PickleError)) PASSES; on 3.10-3.13 the
real AttributeError is also matched (issubclass). Full test needs a 4-GPU
nccl world:
`pytest torch/testing/_internal/distributed/distributed_test.py -k test_gather_object`

Authored with the assistance of an AI coding assistant.
@albmalamd
albmalamd force-pushed the fix_pickle_error_handling_test_gather_object branch from b1c8bf8 to a9ef75b Compare August 12, 2026 15:02
@pytorch-bot

pytorch-bot Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Aug 17, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Details for Dev Infra team Raised by workflow job

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 2 checks: periodic-rocm-mi300 / linux-noble-rocm-py3.12-mi300 / test (distributed, 2, 3, linux.rocm.gpu.mi300.4, module:rocm, oncall:distributed), periodic-rocm-mi200 / linux-jammy-rocm-py3.10-mi200 / test (distributed, 3, 3, linux.rocm.gpu.mi210.2, module:rocm, oncall:distributed)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

albmalamd added a commit to ROCm/pytorch that referenced this pull request Aug 19, 2026
…ch#192811)

## Summary

`test_gather_object` / `test_gather_object_subgroup` fail on Python 3.14. The test calls `all_gather_object` on a **local class** (unpicklable) and asserts an error. The exception type changed: **<=3.13** raised `AttributeError`, but **3.14** ([CPython pytorchgh-139806](python/cpython#139806)) raises `PicklingError` eagerly from `pickle.whichmodule()` for `'<locals>'` names. `PicklingError` is a `PickleError`, not an `AttributeError`, so the stale `assertRaises(AttributeError)` no longer matches.

## Fix

Assert on the types raised across all supported versions (`python_min_version = 3.10`):

```python
with self.assertRaises((AttributeError, pickle.PickleError)):
    dist.all_gather_object(...)
```

## Test plan

On Python 3.14.4, assertRaises(AttributeError) around pickle.Pickler().dump() of a local class ERRORS with PicklingError, while assertRaises((AttributeError, pickle.PickleError)) PASSES; on 3.10-3.13 the real AttributeError is also matched (issubclass). Full test needs a 4-GPU nccl world:
`python -m pytest torch/testing/_internal/distributed/distributed_test.py -k test_gather_object -v`
Pull Request resolved: pytorch#192811
Approved by: https://github.com/jeffdaily

(cherry picked from commit 6b296c0)
pragupta pushed a commit to ROCm/pytorch that referenced this pull request Aug 19, 2026
Fix test_gather_object assertion for Python 3.14 PicklingError (pytorch#192811)
    
## Summary:
The test all_gather_objects a local class (unpicklable) and asserts an
error. The exception type changed: <=3.13 raised AttributeError, but
3.14
(CPython pytorchgh-139806) raises PicklingError from pickle.whichmodule() for
'<locals>' names. PicklingError is a PickleError, not an AttributeError,
so
the stale assertRaises(AttributeError) no longer matches.

Fix the assertion to (AttributeError, pickle.PickleError), correct
across
all supported versions (python_min_version = 3.10) while staying tight.
The
fix belongs in the test, not production: normalizing pickle's exception
type
in _object_to_tensor would mask a legitimate CPython change.

## Test plan:
Test Plan: on Python 3.14.4, assertRaises(AttributeError) around
pickle.Pickler().dump() of a local class ERRORS with PicklingError,
while
assertRaises((AttributeError, pickle.PickleError)) PASSES; on 3.10-3.13
the
real AttributeError is also matched (issubclass). Full test needs a
4-GPU
nccl world:
`pytest torch/testing/_internal/distributed/distributed_test.py -k
test_gather_object`

Authored with the assistance of an AI coding assistant.

Cherry-pick upstream pytorch#192811
orrangetabby17 pushed a commit to orrangetabby17/pytorch that referenced this pull request Sep 2, 2026
…ch#192811)

## Summary

`test_gather_object` / `test_gather_object_subgroup` fail on Python 3.14. The test calls `all_gather_object` on a **local class** (unpicklable) and asserts an error. The exception type changed: **<=3.13** raised `AttributeError`, but **3.14** ([CPython pytorchgh-139806](python/cpython#139806)) raises `PicklingError` eagerly from `pickle.whichmodule()` for `'<locals>'` names. `PicklingError` is a `PickleError`, not an `AttributeError`, so the stale `assertRaises(AttributeError)` no longer matches.

## Fix

Assert on the types raised across all supported versions (`python_min_version = 3.10`):

```python
with self.assertRaises((AttributeError, pickle.PickleError)):
    dist.all_gather_object(...)
```

## Test plan

On Python 3.14.4, assertRaises(AttributeError) around pickle.Pickler().dump() of a local class ERRORS with PicklingError, while assertRaises((AttributeError, pickle.PickleError)) PASSES; on 3.10-3.13 the real AttributeError is also matched (issubclass). Full test needs a 4-GPU nccl world:
`python -m pytest torch/testing/_internal/distributed/distributed_test.py -k test_gather_object -v`
Pull Request resolved: pytorch#192811
Approved by: https://github.com/jeffdaily
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/periodic-rocm-mi200 Trigger "distributed" config CI on ROCm MI200 ciflow/periodic-rocm-mi300 Trigger "distributed" config CI on ROCm MI300/MI325 ciflow/periodic-rocm-mi350 Trigger "distributed_4gpu" config (only runs distributed tests that need >2GPUs) CI on ROCm MI350 ciflow/trunk Trigger trunk jobs on your pull request Merged open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants