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

Function _add_handler

backends/mlx/ops.py:1099–1129  ·  view source on GitHub ↗

Handle aten.add.Tensor: a + alpha * b.

(P: MLXProgramBuilder, n: Node)

Source from the content-addressed store, hash-verified

1097
1098@REGISTRY.register(target=[torch.ops.aten.add.Tensor, torch.ops.aten.add.Scalar])
1099def _add_handler(P: MLXProgramBuilder, n: Node) -> Slot:
1100 """Handle aten.add.Tensor: a + alpha * b."""
1101 args = P.args(n)
1102 require_args(args, 2, 2, "aten.add.Tensor")
1103 require_kwargs(P.kwargs(n), {"alpha"}, "aten.add.Tensor")
1104 a, b = args
1105 input_meta = n.args[0].meta.get("val")
1106 dtype = input_meta.dtype if input_meta is not None else torch.float32
1107 if not isinstance(b, Slot):
1108 b = emit_lifted_constant(P, b, dtype)
1109 alpha = P.kwargs(n).get("alpha", 1)
1110 if alpha != 1:
1111 alpha_slot = emit_lifted_constant(P, alpha, dtype)
1112 _, tmp = P.make_tmp_slot()
1113 P.emit(
1114 MultiplyNode(
1115 a=P.slot_to_tid(b),
1116 b=P.slot_to_tid(alpha_slot),
1117 out=P.slot_to_tid(tmp),
1118 )
1119 )
1120 b = tmp
1121 out = P.make_or_get_slot(n)
1122 P.emit(
1123 AddNode(
1124 a=P.slot_to_tid(a),
1125 b=P.slot_to_tid(b),
1126 out=P.slot_to_tid(out),
1127 )
1128 )
1129 return out
1130
1131
1132@REGISTRY.register(target=[torch.ops.aten.div.Tensor_mode])

Callers

nothing calls this directly

Calls 11

emit_lifted_constantFunction · 0.90
require_argsFunction · 0.85
require_kwargsFunction · 0.85
AddNodeClass · 0.85
argsMethod · 0.80
kwargsMethod · 0.80
emitMethod · 0.80
slot_to_tidMethod · 0.80
getMethod · 0.45
make_tmp_slotMethod · 0.45
make_or_get_slotMethod · 0.45

Tested by

no test coverage detected