Handle aten.add.Tensor: a + alpha * b.
(P: MLXProgramBuilder, n: Node)
| 1097 | |
| 1098 | @REGISTRY.register(target=[torch.ops.aten.add.Tensor, torch.ops.aten.add.Scalar]) |
| 1099 | def _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]) |
nothing calls this directly
no test coverage detected