Skip to content

[release/2.11] fix PicklingError handling for Python 3.14 - #3584

Merged
pragupta merged 1 commit into
release/2.11from
cherry-pick-192811-onto-release-2.11
Aug 19, 2026
Merged

pragupta merged 1 commit into
release/2.11from
cherry-pick-192811-onto-release-2.11

Conversation

@albmalamd

@albmalamd albmalamd commented Aug 19, 2026 •

Copy link
Copy Markdown

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
'' 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

Cherry-picked to release/2.12 branch via #3585

Cherry-picked to release/2.13 branch via #3586

@pragupta pragupta changed the title [Release/2.11] Cherry-pick upstream 192811- fix PicklingError handling for Python 3.14 [release/2.11] fix PicklingError handling for Python 3.14 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)
@albmalamd
albmalamd force-pushed the cherry-pick-192811-onto-release-2.11 branch from 1e62ed7 to 7daec36 Compare August 19, 2026 16:44
@pragupta
pragupta merged commit 976fe89 into release/2.11 Aug 19, 2026
@pragupta
pragupta deleted the cherry-pick-192811-onto-release-2.11 branch August 19, 2026 16:47
@albmalamd

Copy link
Copy Markdown
Author

!cherry-pick --onto release/2.12

@albmalamd

Copy link
Copy Markdown
Author

!cherry-pick --onto release/2.13

@rocm-repo-management-api-6

Copy link
Copy Markdown

Created branch autogenerated/release/2.12_cherry-pick_pr-3584 and #3585

Comment processed by Build

@rocm-repo-management-api-6

Copy link
Copy Markdown

Created branch autogenerated/release/2.13_cherry-pick_pr-3584 and #3586

Comment processed by Build

pablo-garay pushed a commit that referenced this pull request Aug 24, 2026
Cherry-pick of #3584

Co-authored-by: albmalamd <[email protected]>
(cherry picked from commit 6596a0d)
jithunnair-amd pushed a commit that referenced this pull request Aug 25, 2026
Cherry-pick of #3584

Co-authored-by: albmalamd <[email protected]>
(cherry picked from commit 6596a0d)
jithunnair-amd pushed a commit that referenced this pull request Aug 27, 2026
Cherry-pick of #3584

Co-authored-by: albmalamd <[email protected]>
(cherry picked from commit 6596a0d)
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.

2 participants