Skip to content

Support non-tensor attrs in __tensor_flatten__#176457

Closed
aorenste wants to merge 13 commits intogh/aorenste/206/basefrom
gh/aorenste/206/head
Closed

Support non-tensor attrs in __tensor_flatten__#176457
aorenste wants to merge 13 commits intogh/aorenste/206/basefrom
gh/aorenste/206/head

Conversation

@aorenste
Copy link
Copy Markdown
Contributor

@aorenste aorenste commented Mar 4, 2026

Stack from ghstack (oldest at bottom):

The first return value of __tensor_flatten__ can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated __tensor_flatten__ results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):

  • test_tensor_subclass_with_opaque_attr_backward
  • test_tensor_subclass_opaque_backward_compiled_autograd
  • test_tensor_subclass_shared_opaque_remapping
  • test_shared_opaque_identity_guard
  • test_shared_direct_opaque_identity_guard
  • test_tensor_subclass_shared_opaque_backward
  • test_deeply_nested_tensor_subclass_with_opaque
  • test_subclass_parametrization_with_opaque_attrs
  • test_export_non_strict_with_opaque_attrs
  • test_get_untyped_storages_with_opaque_attrs
  • test_subclass_opaque_attrs_cache_hit
  • test_value_type_opaque_in_tensor_attrs_errors

Authored with Claude.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @Lucaskabela @jataylo

The first return value of __tensor_flatten__ can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated __tensor_flatten__ results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit

Authored with Claude.

[ghstack-poisoned]
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Mar 4, 2026

🔗 Helpful Links

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

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

✅ You can merge normally! (2 Unrelated Failures)

As of commit f583a4b with merge base 9a8ed4e (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

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

aorenste added a commit that referenced this pull request Mar 4, 2026
The first return value of __tensor_flatten__ can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated __tensor_flatten__ results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit

Authored with Claude.

ghstack-source-id: f485fef
Pull Request resolved: #176457
The first return value of `__tensor_flatten__` can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated `__tensor_flatten__` results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit

Authored with Claude.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo

[ghstack-poisoned]
aorenste added a commit that referenced this pull request Mar 5, 2026
The first return value of __tensor_flatten__ can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated __tensor_flatten__ results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit

Authored with Claude.

ghstack-source-id: a18076d
Pull Request resolved: #176457
The first return value of `__tensor_flatten__` can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated `__tensor_flatten__` results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit
- test_value_type_opaque_in_tensor_attrs_errors

Authored with Claude.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo

[ghstack-poisoned]
aorenste added a commit that referenced this pull request Mar 5, 2026
The first return value of __tensor_flatten__ can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated __tensor_flatten__ results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit

Authored with Claude.

ghstack-source-id: 47dad0f
Pull Request resolved: #176457
The first return value of `__tensor_flatten__` can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated `__tensor_flatten__` results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit
- test_value_type_opaque_in_tensor_attrs_errors

Authored with Claude.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo

[ghstack-poisoned]
aorenste added a commit that referenced this pull request Mar 5, 2026
The first return value of __tensor_flatten__ can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated __tensor_flatten__ results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit

Authored with Claude.

ghstack-source-id: 2dd7af8
Pull Request resolved: #176457
@aorenste aorenste marked this pull request as ready for review March 5, 2026 19:39
@aorenste aorenste requested review from angelayi and ezyang and removed request for angelayi March 5, 2026 19:39
The first return value of `__tensor_flatten__` can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated `__tensor_flatten__` results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit
- test_value_type_opaque_in_tensor_attrs_errors

Authored with Claude.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo

[ghstack-poisoned]
aorenste added a commit that referenced this pull request Mar 6, 2026
The first return value of __tensor_flatten__ can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated __tensor_flatten__ results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit

Authored with Claude.

ghstack-source-id: 2dd7af8
Pull Request resolved: #176457
aorenste added a commit that referenced this pull request Mar 6, 2026
The first return value of __tensor_flatten__ can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated __tensor_flatten__ results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit

Authored with Claude.

ghstack-source-id: bc4d79e
Pull Request resolved: #176457
The first return value of `__tensor_flatten__` can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated `__tensor_flatten__` results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit
- test_value_type_opaque_in_tensor_attrs_errors

Authored with Claude.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo

[ghstack-poisoned]
aorenste added a commit that referenced this pull request Mar 7, 2026
The first return value of __tensor_flatten__ can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated __tensor_flatten__ results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit

Authored with Claude.

ghstack-source-id: 65fb56c
Pull Request resolved: #176457
The first return value of `__tensor_flatten__` can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated `__tensor_flatten__` results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit
- test_value_type_opaque_in_tensor_attrs_errors

Authored with Claude.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo

[ghstack-poisoned]
aorenste added a commit that referenced this pull request Mar 7, 2026
The first return value of __tensor_flatten__ can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated __tensor_flatten__ results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit

Authored with Claude.

ghstack-source-id: 45b0259
Pull Request resolved: #176457
The first return value of `__tensor_flatten__` can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated `__tensor_flatten__` results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit
- test_value_type_opaque_in_tensor_attrs_errors

Authored with Claude.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo

[ghstack-poisoned]
aorenste added a commit that referenced this pull request Mar 7, 2026
The first return value of __tensor_flatten__ can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated __tensor_flatten__ results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit

Authored with Claude.

ghstack-source-id: c505ee7
Pull Request resolved: #176457
The first return value of `__tensor_flatten__` can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated `__tensor_flatten__` results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit
- test_value_type_opaque_in_tensor_attrs_errors

Authored with Claude.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo

[ghstack-poisoned]
aorenste added a commit that referenced this pull request Mar 7, 2026
The first return value of __tensor_flatten__ can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated __tensor_flatten__ results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit

Authored with Claude.

ghstack-source-id: fa270e1
Pull Request resolved: #176457
@aorenste
Copy link
Copy Markdown
Contributor Author

aorenste commented Mar 8, 2026

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Mar 8, 2026
@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

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

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: trunk / macos-py3-arm64 / test (default, 3, 3, macos-m1-stable)

Details for Dev Infra team Raised by workflow job

The first return value of `__tensor_flatten__` can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated `__tensor_flatten__` results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit
- test_value_type_opaque_in_tensor_attrs_errors

Authored with Claude.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo

[ghstack-poisoned]
aorenste added a commit that referenced this pull request Mar 8, 2026
The first return value of __tensor_flatten__ can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated __tensor_flatten__ results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit

Authored with Claude.

ghstack-source-id: 0dd82ff
Pull Request resolved: #176457
The first return value of `__tensor_flatten__` can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated `__tensor_flatten__` results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit
- test_value_type_opaque_in_tensor_attrs_errors

Authored with Claude.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo

[ghstack-poisoned]
aorenste added a commit that referenced this pull request Mar 8, 2026
The first return value of __tensor_flatten__ can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated __tensor_flatten__ results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit

Authored with Claude.

ghstack-source-id: 065031f
Pull Request resolved: #176457
The first return value of `__tensor_flatten__` can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated `__tensor_flatten__` results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit
- test_value_type_opaque_in_tensor_attrs_errors

Authored with Claude.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo

[ghstack-poisoned]
aorenste added a commit that referenced this pull request Mar 8, 2026
The first return value of __tensor_flatten__ can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated __tensor_flatten__ results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit

Authored with Claude.

ghstack-source-id: 35ec966
Pull Request resolved: #176457
@aorenste
Copy link
Copy Markdown
Contributor Author

aorenste commented Mar 9, 2026

@pytorchbot merge

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

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

EmanueleCoradin pushed a commit to EmanueleCoradin/pytorch that referenced this pull request Mar 30, 2026
The first return value of `__tensor_flatten__` can now contain opaque
(non-tensor) values such as DeviceMesh. Opaques flow through the flat
arg list alongside tensors: they get indices, become graph inputs/outputs,
and are pulled from all_args by position during subclass reconstruction
— the same as PlainTensorMeta. An empty OpaqueMeta marker in
SubclassCreationMeta.attrs distinguishes opaque slots from tensor slots
(needed by process_runtime_tangent, which skips non-differentiable
opaques).

All code that previously iterated `__tensor_flatten__` results and assumed
every element was a tensor now handles opaques: subclass_parametrization,
non_strict_utils, FSDP _init_utils, common_utils (get_untyped_storages),
frontend_utils, and parametrize.py (which stores opaques as plain
attributes rather than parameters).

Tests added (all in test/test_opaque_obj_v2.py):
- test_tensor_subclass_with_opaque_attr_backward
- test_tensor_subclass_opaque_backward_compiled_autograd
- test_tensor_subclass_shared_opaque_remapping
- test_shared_opaque_identity_guard
- test_shared_direct_opaque_identity_guard
- test_tensor_subclass_shared_opaque_backward
- test_deeply_nested_tensor_subclass_with_opaque
- test_subclass_parametrization_with_opaque_attrs
- test_export_non_strict_with_opaque_attrs
- test_get_untyped_storages_with_opaque_attrs
- test_subclass_opaque_attrs_cache_hit
- test_value_type_opaque_in_tensor_attrs_errors

Authored with Claude.

Pull Request resolved: pytorch#176457
Approved by: https://github.com/ezyang
@github-actions github-actions bot deleted the gh/aorenste/206/head branch April 8, 2026 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants