Fix ShardedTensorMetadata.tensor_properties for Python 3.11#91795
Fix ShardedTensorMetadata.tensor_properties for Python 3.11#91795ConnorBaker wants to merge 1 commit intopytorch:masterfrom ConnorBaker:master
ShardedTensorMetadata.tensor_properties for Python 3.11#91795Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/91795
Note: Links to docs will display an error until the docs builds have been completed. ❌ 5 FailuresAs of commit fa43c9f: NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot rebase |
|
@pytorchbot successfully started a rebase job. Check the current status here |
|
Successfully rebased |
|
@pytorchbot merge |
Merge startedYour 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 |
Merge failedReason: The following mandatory check(s) failed (Rule Dig deeper by viewing the failures on hud Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot rebase |
|
@pytorchbot successfully started a rebase job. Check the current status here |
The `tensor_properties` field of the `ShardedTensorMetadata` dataclass is a reference to a `TensorProperties` object. However, the field is set to `field(default=TensorProperties())` instead of `field(default_factory=TensorProperties)`. This causes an error when using Python 3.11 or later: ```python ValueError: mutable default <class 'torch.distributed._shard.sharded_tensor.metadata.TensorProperties'> for field tensor_properties is not allowed: use default_factory ``` This change in dataclass behavior was introduced in [bpo-44674: Use unhashability as a proxy for mutability for default dataclass __init__ arguments](python/cpython#29867). The current use of `default` instead of `default_factory` also means that all `ShardedTensorMetadata` objects created without specifying `tensor_properties` will share the same `TensorProperties` object.
|
Successfully rebased |
|
@pytorchbot merge -f "CI failure not related to this PR also this PR fixes blockers for PT3.11 so we want to merge it ASAP". |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
The
tensor_propertiesfield of theShardedTensorMetadatadataclass is a reference to aTensorPropertiesobject. However, the field is set tofield(default=TensorProperties())instead offield(default_factory=TensorProperties). This causes an error when using Python 3.11 or later:This change in dataclass behavior was introduced in bpo-44674: Use unhashability as a proxy for mutability for default dataclass init arguments.
The current use of
defaultinstead ofdefault_factoryalso means that allShardedTensorMetadataobjects created without specifyingtensor_propertieswill share the sameTensorPropertiesobject.