Add memory format support to empty_like operator#27244
Add memory format support to empty_like operator#27244VitalyFedyunin wants to merge 17 commits intogh/VitalyFedyunin/5/basefrom
empty_like operator#27244Conversation
[ghstack-poisoned]
[ghstack-poisoned]
Adds memory_format keyword argument (positional for cpp). 'Preserve' behavior now follows next rules: 1) If tensor is non-overlapping and dense - output tensor will have the same strides as input tensor. 2) If not (1) and tensor is stored in the channels last format, output tensor going to have channels last format. 3) Output tensor is going to be contiguous in all other cases. --- Dense tensor is the tensor that store values in a contiguous block of memory. Non-overlapping tensor is the tensor in which elements occupy individual non-repetitive memory. [ghstack-poisoned]
Adds memory_format keyword argument (positional for cpp). 'Preserve' behavior now follows next rules: 1) If tensor is non-overlapping and dense - output tensor will have the same strides as input tensor. 2) If not (1) and tensor is stored in the channels last format, output tensor going to have channels last format. 3) Output tensor is going to be contiguous in all other cases. --- Dense tensor is the tensor that store values in a contiguous block of memory. Non-overlapping tensor is the tensor in which elements occupy individual non-repetitive memory. [ghstack-poisoned]
Adds memory_format keyword argument (positional for cpp). 'Preserve' behavior now follows next rules: 1) If tensor is non-overlapping and dense - output tensor will have the same strides as input tensor. 2) If not (1) and tensor is stored in the channels last format, output tensor going to have channels last format. 3) Output tensor is going to be contiguous in all other cases. --- Dense tensor is the tensor that store values in a contiguous block of memory. Non-overlapping tensor is the tensor in which elements occupy individual non-repetitive memory. [ghstack-poisoned]
Adds memory_format keyword argument (positional for cpp). 'Preserve' behavior now follows next rules: 1) If tensor is non-overlapping and dense - output tensor will have the same strides as input tensor. 2) If not (1) and tensor is stored in the channels last format, output tensor going to have channels last format. 3) Output tensor is going to be contiguous in all other cases. --- Dense tensor is the tensor that store values in a contiguous block of memory. Non-overlapping tensor is the tensor in which elements occupy individual non-repetitive memory. [ghstack-poisoned]
…ator" Adds memory_format keyword argument (positional for cpp). 'Preserve' behavior now follows next rules: 1) If tensor is non-overlapping and dense - output tensor will have the same strides as input tensor. 2) If not (1) and tensor is stored in the channels last format, output tensor going to have channels last format. 3) Output tensor is going to be contiguous in all other cases. --- Dense tensor is the tensor that store values in a contiguous block of memory. Non-overlapping tensor is the tensor in which elements occupy individual non-repetitive memory. [ghstack-poisoned]
…operator" Adds memory_format keyword argument (positional for cpp). 'Preserve' behavior now follows next rules: 1) If tensor is non-overlapping and dense - output tensor will have the same strides as input tensor. 2) If not (1) and tensor is stored in the channels last format, output tensor going to have channels last format. 3) Output tensor is going to be contiguous in all other cases. --- Dense tensor is the tensor that store values in a contiguous block of memory. Non-overlapping tensor is the tensor in which elements occupy individual non-repetitive memory. [ghstack-poisoned]
… operator" Adds memory_format keyword argument (positional for cpp). 'Preserve' behavior now follows next rules: 1) If tensor is non-overlapping and dense - output tensor will have the same strides as input tensor. 2) If not (1) and tensor is stored in the channels last format, output tensor going to have channels last format. 3) Output tensor is going to be contiguous in all other cases. --- Dense tensor is the tensor that store values in a contiguous block of memory. Non-overlapping tensor is the tensor in which elements occupy individual non-repetitive memory. [ghstack-poisoned]
| supports_named_tensor: True | ||
|
|
||
| - func: empty_like.dtype(Tensor self, *, ScalarType dtype, Layout layout, Device device, bool pin_memory=False, MemoryFormat? memory_format=contiguous_format) -> Tensor | ||
| - func: empty_like.dtype(Tensor self, *, ScalarType dtype, Layout layout, Device device, bool pin_memory=False, MemoryFormat? memory_format=None) -> Tensor |
There was a problem hiding this comment.
None and contigous_format (i.e., 0) have the same behavior?
There was a problem hiding this comment.
Yes, but it is exceptional case. No need to handle it in the test.
|
@ailzhang hi |
| if (self.is_quantized()) { | ||
|
|
||
| auto memory_format = | ||
| optional_memory_format.value_or(MemoryFormat::Contiguous); |
There was a problem hiding this comment.
To be changed later right :>
There was a problem hiding this comment.
Yes, right now we need to introduce this option, after we check all current code for expected behaviour and change default.
There was a problem hiding this comment.
If it's to be changed later, can we add a comment linking some issue or with some information ?
| if decl['name'].endswith('_like') and not has_tensor_options: | ||
| # it's a tensor | ||
| actuals.append('{}.options().is_variable(false)'.format(actuals[0])) | ||
| if decl['name'] == 'empty_like': |
There was a problem hiding this comment.
Umm... this looks very non-general. (I assume it gets fixed later in the stack but it is very shocking here)
There was a problem hiding this comment.
Yes, need to list by function until I convert all of them
| check_sum_all(torch.tensor([True, False, True], dtype=torch.bool, device=device)) | ||
|
|
||
| def _test_memory_format_transformations(self, device, input_generator_fn, transformation_fn): | ||
| def _test_memory_format_transformations(self, device, input_generator_fn, transformation_fn, compare_data=True): |
…ator" Adds memory_format keyword argument (positional for cpp). 'Preserve' behavior now follows next rules: 1) If tensor is non-overlapping and dense - output tensor will have the same strides as input tensor. 2) If not (1) and tensor is stored in the channels last format, output tensor going to have channels last format. 3) Output tensor is going to be contiguous in all other cases. --- Dense tensor is the tensor that store values in a contiguous block of memory. Non-overlapping tensor is the tensor in which elements occupy individual non-repetitive memory. Differential Revision: [D17980310](https://our.internmc.facebook.com/intern/diff/D17980310) [ghstack-poisoned]
…perator" Adds memory_format keyword argument (positional for cpp). 'Preserve' behavior now follows next rules: 1) If tensor is non-overlapping and dense - output tensor will have the same strides as input tensor. 2) If not (1) and tensor is stored in the channels last format, output tensor going to have channels last format. 3) Output tensor is going to be contiguous in all other cases. --- Dense tensor is the tensor that store values in a contiguous block of memory. Non-overlapping tensor is the tensor in which elements occupy individual non-repetitive memory. Differential Revision: [D17980310](https://our.internmc.facebook.com/intern/diff/D17980310) [ghstack-poisoned]
Adds memory_format keyword argument (positional for cpp). 'Preserve' behavior now follows next rules: 1) If tensor is non-overlapping and dense - output tensor will have the same strides as input tensor. 2) If not (1) and tensor is stored in the channels last format, output tensor going to have channels last format. 3) Output tensor is going to be contiguous in all other cases. --- Dense tensor is the tensor that store values in a contiguous block of memory. Non-overlapping tensor is the tensor in which elements occupy individual non-repetitive memory. Differential Revision: [D17980310](https://our.internmc.facebook.com/intern/diff/D17980310) [ghstack-poisoned]
…to `empty_like` operator" Adds memory_format keyword argument (positional for cpp). 'Preserve' behavior now follows next rules: 1) If tensor is non-overlapping and dense - output tensor will have the same strides as input tensor. 2) If not (1) and tensor is stored in the channels last format, output tensor going to have channels last format. 3) Output tensor is going to be contiguous in all other cases. --- Dense tensor is the tensor that store values in a contiguous block of memory. Non-overlapping tensor is the tensor in which elements occupy individual non-repetitive memory. Differential Revision: [D17980310](https://our.internmc.facebook.com/intern/diff/D17980310) [ghstack-poisoned]
…ke` operator" Adds memory_format keyword argument (positional for cpp). 'Preserve' behavior now follows next rules: 1) If tensor is non-overlapping and dense - output tensor will have the same strides as input tensor. 2) If not (1) and tensor is stored in the channels last format, output tensor going to have channels last format. 3) Output tensor is going to be contiguous in all other cases. --- Dense tensor is the tensor that store values in a contiguous block of memory. Non-overlapping tensor is the tensor in which elements occupy individual non-repetitive memory. Differential Revision: [D17980310](https://our.internmc.facebook.com/intern/diff/D17980310) [ghstack-poisoned]
Summary: Pull Request resolved: pytorch/pytorch#27244 Adds memory_format keyword argument (positional for cpp). 'Preserve' behavior now follows next rules: 1) If tensor is non-overlapping and dense - output tensor will have the same strides as input tensor. 2) If not (1) and tensor is stored in the channels last format, output tensor going to have channels last format. 3) Output tensor is going to be contiguous in all other cases. --- Dense tensor is the tensor that store values in a contiguous block of memory. Non-overlapping tensor is the tensor in which elements occupy individual non-repetitive memory. Test Plan: Imported from OSS Reviewed By: ezyang Differential Revision: D17980310 Pulled By: VitalyFedyunin fbshipit-source-id: 00a39b40daa4b8ee63c32e60d920222f8be2d6a1
|
@VitalyFedyunin merged this pull request in baf8488. |
ghstack-source-id: 3b495ce Pull Request resolved: pytorch/pytorch#27244
Summary: Pull Request resolved: pytorch#27244 Adds memory_format keyword argument (positional for cpp). 'Preserve' behavior now follows next rules: 1) If tensor is non-overlapping and dense - output tensor will have the same strides as input tensor. 2) If not (1) and tensor is stored in the channels last format, output tensor going to have channels last format. 3) Output tensor is going to be contiguous in all other cases. --- Dense tensor is the tensor that store values in a contiguous block of memory. Non-overlapping tensor is the tensor in which elements occupy individual non-repetitive memory. Test Plan: Imported from OSS Reviewed By: ezyang Differential Revision: D17980310 Pulled By: VitalyFedyunin fbshipit-source-id: 00a39b40daa4b8ee63c32e60d920222f8be2d6a1
|
|
||
| - func: empty_like(Tensor self) -> Tensor | ||
| use_c10_dispatcher: full | ||
| - func: empty_like(Tensor self, *, MemoryFormat? memory_format=None) -> Tensor |
There was a problem hiding this comment.
With the benefit of hindsight, I should have asked: why do we have two overloads of empty_like in the first place?!
There was a problem hiding this comment.
Do you mean this line and line 1123?
There was a problem hiding this comment.
yes. But see my most recent PR.
There was a problem hiding this comment.
As far as I remember combining them together was never considered by me.
ghstack-source-id: b9323d5 Pull Request resolved: pytorch/pytorch#27244
Stack from ghstack:
resize_op. #28292 Add memory format support to theresize_op.operator==of TensorOptions as confusing one #28076 Killoperator==of TensorOptions as confusing oneresize_as_operator #27979 Add memory format support toresize_as_operatorrandn_likeoperator #27890 Add memory format support torandn_likeoperatorrandint_likeoperator #27889 Add memory format support torandint_likeoperatorzeros_likeoperator #27562 Add memory format support tozeros_likeoperatorrand_likeoperator #27561 Add memory format support torand_likeoperatorones_likeoperator #27270 Add memory format support toones_likeoperatorfull_likeoperator #27262 Add memory format support tofull_likeoperatorempty_likeoperator #27244 Add memory format support toempty_likeoperatorAdds memory_format keyword argument (positional for cpp).
'Preserve' behavior now follows next rules:
Dense tensor is the tensor that store values in a contiguous block of memory.
Non-overlapping tensor is the tensor in which elements occupy individual non-repetitive memory.
Differential Revision: D17980310