Handle aten._to_copy - lower-level dtype/device conversion.
(P: MLXProgramBuilder, n: Node)
| 1035 | |
| 1036 | @REGISTRY.register(target=[torch.ops.aten._to_copy.default]) |
| 1037 | def _to_copy_handler(P: MLXProgramBuilder, n: Node) -> Slot: |
| 1038 | """Handle aten._to_copy - lower-level dtype/device conversion.""" |
| 1039 | # aten._to_copy(Tensor self, *, ScalarType? dtype=None, ...) |
| 1040 | args = P.args(n) |
| 1041 | kwargs = P.kwargs(n) |
| 1042 | require_args(args, 1, 1, "aten._to_copy") |
| 1043 | require_kwargs( |
| 1044 | kwargs, {"dtype", "device", "layout", "memory_format"}, "aten._to_copy" |
| 1045 | ) |
| 1046 | require_contiguous_format( |
| 1047 | layout=kwargs.get("layout"), |
| 1048 | memory_format=kwargs.get("memory_format"), |
| 1049 | op_name="aten._to_copy", |
| 1050 | ) |
| 1051 | x = args[0] |
| 1052 | out = P.make_or_get_slot(n) |
| 1053 | |
| 1054 | dtype = kwargs.get("dtype") |
| 1055 | if dtype is not None: |
| 1056 | # Dtype conversion |
| 1057 | P.emit( |
| 1058 | AsTypeNode( |
| 1059 | x=P.slot_to_tid(x), |
| 1060 | out=P.slot_to_tid(out), |
| 1061 | scalar_type=torch_dtype_to_scalar_type(dtype), |
| 1062 | ) |
| 1063 | ) |
| 1064 | else: |
| 1065 | # No dtype change, just copy (use contiguous) |
| 1066 | P.emit( |
| 1067 | ContiguousNode( |
| 1068 | x=P.slot_to_tid(x), |
| 1069 | out=P.slot_to_tid(out), |
| 1070 | ) |
| 1071 | ) |
| 1072 | return out |
| 1073 | |
| 1074 | |
| 1075 | @REGISTRY.register(target=[torch.ops.aten.embedding.default]) |
nothing calls this directly
no test coverage detected