MCPcopy Create free account
hub / github.com/pytorch/executorch / _to_copy_handler

Function _to_copy_handler

backends/mlx/ops.py:1037–1072  ·  view source on GitHub ↗

Handle aten._to_copy - lower-level dtype/device conversion.

(P: MLXProgramBuilder, n: Node)

Source from the content-addressed store, hash-verified

1035
1036@REGISTRY.register(target=[torch.ops.aten._to_copy.default])
1037def _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])

Callers

nothing calls this directly

Calls 10

require_argsFunction · 0.85
require_kwargsFunction · 0.85
argsMethod · 0.80
kwargsMethod · 0.80
emitMethod · 0.80
slot_to_tidMethod · 0.80
getMethod · 0.45
make_or_get_slotMethod · 0.45

Tested by

no test coverage detected