已合并
[fix] remove to_copy meta_register #35922
culechan创建于 5月18日
[fix] remove to_copy meta_register #35922
已合并
共 2 个文件变更+3-55
| @@ -39,18 +39,18 @@ class TestToCopyStride(TestCase): | |||
| 39 | fake_source = fake_mode.from_tensor(source) | 39 | fake_source = fake_mode.from_tensor(source) |
| 40 | fake_copied = _to_copy_strided_float32(fake_source) | 40 | fake_copied = _to_copy_strided_float32(fake_source) |
| 41 | self.assertEqual(fake_copied.shape, SOURCE_SIZE) | 41 | self.assertEqual(fake_copied.shape, SOURCE_SIZE) |
| 42 | - self.assertEqual(fake_copied.stride(), CONTIGUOUS_STRIDE) | 42 | + self.assertEqual(fake_copied.stride(), SOURCE_STRIDE) |
| 43 | 43 | ||
| 44 | def test_to_copy_compile_stride(self): | 44 | def test_to_copy_compile_stride(self): |
| 45 | source = _make_source_tensor() | 45 | source = _make_source_tensor() |
| 46 | real_copied = _to_copy_strided_float32(source) | 46 | real_copied = _to_copy_strided_float32(source) |
| 47 | self.assertEqual(real_copied.shape, SOURCE_SIZE) | 47 | self.assertEqual(real_copied.shape, SOURCE_SIZE) |
| 48 | - self.assertEqual(real_copied.stride(), CONTIGUOUS_STRIDE) | 48 | + self.assertEqual(real_copied.stride(), SOURCE_STRIDE) |
| 49 | 49 | ||
| 50 | compiled_to_copy = torch.compile(_to_copy_strided_float32, backend="inductor") | 50 | compiled_to_copy = torch.compile(_to_copy_strided_float32, backend="inductor") |
| 51 | compiled_copied = compiled_to_copy(source) | 51 | compiled_copied = compiled_to_copy(source) |
| 52 | self.assertEqual(compiled_copied.shape, SOURCE_SIZE) | 52 | self.assertEqual(compiled_copied.shape, SOURCE_SIZE) |
| 53 | - self.assertEqual(compiled_copied.stride(), CONTIGUOUS_STRIDE) | 53 | + self.assertEqual(compiled_copied.stride(), SOURCE_STRIDE) |
| 54 | 54 | ||
| 55 | 55 | ||
| 56 | if __name__ == "__main__": | 56 | if __name__ == "__main__": |
| @@ -19,7 +19,6 @@ npu = torch.ops.npu | |||
| 19 | META_BLACKLIST = { | 19 | META_BLACKLIST = { |
| 20 | "aten::empty_strided", # causing infinite recursion, test_meta.py | 20 | "aten::empty_strided", # causing infinite recursion, test_meta.py |
| 21 | "aten::clone", # causing infinite recursion | 21 | "aten::clone", # causing infinite recursion |
| 22 | - "aten::_to_copy", # causing infinite recursion, test_serialization.py -k test_tensor_subclass_getstate_overwrite # noqa: B950 | ||
| 23 | "aten::copy_", # Exception not raised, test_torch.py -k test_storage_meta_errors_cpu_int64 # noqa: B950 | 22 | "aten::copy_", # Exception not raised, test_torch.py -k test_storage_meta_errors_cpu_int64 # noqa: B950 |
| 24 | "aten::constant_pad_nd", # requires_grad mismatch, test_ops.py -k test_fake_crossref_backward_amp_istft_cuda_float32 # noqa: B950 | 23 | "aten::constant_pad_nd", # requires_grad mismatch, test_ops.py -k test_fake_crossref_backward_amp_istft_cuda_float32 # noqa: B950 |
| 25 | "aten::rot90", # requires_grad mismatch! test_ops.py -k test_fake_crossref_backward_amp_rot90_cuda_float32 # noqa: B950 | 24 | "aten::rot90", # requires_grad mismatch! test_ops.py -k test_fake_crossref_backward_amp_rot90_cuda_float32 # noqa: B950 |
| @@ -187,54 +186,3 @@ def meta_native_dropout_backward_patch(grad_output: Tensor, mask: Tensor, scale: | |||
| 187 | from torch._decomp.decompositions import native_dropout_backward | 186 | from torch._decomp.decompositions import native_dropout_backward |
| 188 | 187 | ||
| 189 | return native_dropout_backward(grad_output, mask, scale) | 188 | return native_dropout_backward(grad_output, mask, scale) |
| 190 | - | ||
| 191 | - | ||
| 192 | - | ||
| 193 | -def meta_to_copy_default( | ||
| 194 | - x, | ||
| 195 | - *, | ||
| 196 | - dtype: torch.dtype | None = None, | ||
| 197 | - layout=None, | ||
| 198 | - device: torch.device | None = None, | ||
| 199 | - pin_memory: bool = False, | ||
| 200 | - non_blocking: bool = False, | ||
| 201 | - memory_format: torch.memory_format | None = None, | ||
| 202 | -): | ||
| 203 | - if layout and layout != torch.strided: | ||
| 204 | - raise AssertionError(f"Only strided layout is supported, got {layout}") | ||
| 205 | - if pin_memory: | ||
| 206 | - raise AssertionError("pin_memory is not supported") | ||
| 207 | - if not isinstance(x, (torch.Tensor, int, float, bool, complex)): | ||
| 208 | - raise AssertionError(f"x must be Tensor or scalar type, got {type(x)}") | ||
| 209 | - | ||
| 210 | - out_memory_format = ( | ||
| 211 | - memory_format if memory_format is not None else torch.contiguous_format | ||
| 212 | - ) | ||
| 213 | - | ||
| 214 | - if device is None and dtype is None and memory_format is None: | ||
| 215 | - if isinstance(x, torch.Tensor): | ||
| 216 | - return x.clone(memory_format=out_memory_format) | ||
| 217 | - else: | ||
| 218 | - return x | ||
| 219 | - dtype_converted = False | ||
| 220 | - | ||
| 221 | - if isinstance(x, torch.Tensor): | ||
| 222 | - x_tensor = x | ||
| 223 | - else: | ||
| 224 | - x_tensor = torch.scalar_tensor(x) | ||
| 225 | - | ||
| 226 | - if device is not None and device != x_tensor.device: | ||
| 227 | - # avoid conversions on cpu | ||
| 228 | - if dtype is not None and device.type == "cpu": | ||
| 229 | - x_tensor = torch._prims.convert_element_type(x_tensor, dtype) | ||
| 230 | - dtype_converted = True | ||
| 231 | - x_tensor = torch._prims.device_put(x_tensor, device, non_blocking) | ||
| 232 | - | ||
| 233 | - if dtype is not None and not dtype_converted: | ||
| 234 | - x_tensor = torch._prims.convert_element_type(x_tensor, dtype) | ||
| 235 | - dtype_converted = True | ||
| 236 | - | ||
| 237 | - if memory_format is not None: # no ref/prim for memory format | ||
| 238 | - return torch.clone(x_tensor, memory_format=memory_format) | ||
| 239 | - else: | ||
| 240 | - return torch.clone(x_tensor, memory_format=out_memory_format) | ||