SIGN IN SIGN UP

[S615805][S694227][PyTorch] Safely preserve tensor strides (#194251) (#194251)

Summary:

Add optional strides to PyTorch DCP and sharded TensorProperties while preserving legacy pickle compatibility. S694227 occurred because PartiallyMaterializedTensor is passed through APIs typed as torch.Tensor but has no stride attribute. Both shared metadata constructors now call stride only when a callable attribute exists and record None otherwise, allowing downstream contiguous fallback. Regression coverage includes generic tensor-like objects and a real FBGEMM PartiallyMaterializedTensor through both ModelStore metadata paths.

Test Plan:
buck test fbcode//mode/opt fbcode//caffe2/test/distributed/checkpoint:test_planner fbcode//caffe2/test/distributed/checkpoint:test_compatibility fbcode//aiplatform/modelstore/experimental/DCP/planners/tests:modelstore_save_planner_test
https://www.internalfb.com/intern/testinfra/testrun/5910974891858832 (42 passed)

buck test fbcode//mode/opt fbcode//aiplatform/modelstore/experimental/DCP/planners/tests:modelstore_save_planner_test-library-type-checking fbcode//aiplatform/modelstore/experimental/DCP/planners/tests:modelstore_save_planner_test
https://www.internalfb.com/intern/testinfra/testrun/5348024939975086 (5 passed)

S694227 regression on the full stack:
buck test fbcode//mode/opt fbcode//minimal_viable_ai/models/blue_reels_vdd/v5/gpu_tests:hstu_standalone_cint_toy_train_and_publish_test -- --exact 'fbcode//minimal_viable_ai/models/blue_reels_vdd/v5/gpu_tests:hstu_standalone_cint_toy_train_and_publish_test - test_train (minimal_viable_ai.models.blue_reels_vdd.v5.gpu_tests.hstu_standalone_cint_toy_train_and_publish_test.ModelHstuStandaloneCintTest)'
https://www.internalfb.com/intern/testinfra/testrun/6192449817165760 (1 passed)

buck test fbcode//mode/opt fbcode//aiplatform/modelstore/experimental/integration_tests/tests/nosan:multi_rank_kvtensor_save_load_test
https://www.internalfb.com/intern/testinfra/testrun/10696049303744220 (3 passed)

arc f
arc lint

Reviewed By: meetv18, sibuachu

Differential Revision: D115449673

Pull Request resolved: https://github.com/pytorch/pytorch/pull/194251
Approved by: https://github.com/sibuachu, https://github.com/meetv18
A
Angeline Mingwei Zhang committed
e6f4d79afe009fb474d4ff1b5d3ba9d98c91d4e6
Parent: 7d84b26
Committed by PyTorch MergeBot <pytorchmergebot@users.noreply.github.com> on 8/24/2026, 8:46:47 PM