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

Function _split_handler

backends/mlx/ops.py:1628–1666  ·  view source on GitHub ↗

Handle split operation with uniform chunk size. Splits a tensor into chunks of a given size along a dimension. The last chunk may be smaller if the dimension does not divide evenly. PyTorch: split(x, split_size, dim=0) We pass [split_size] to the interpreter, which computes the ac

(P: MLXProgramBuilder, n: Node)

Source from the content-addressed store, hash-verified

1626 target=[torch.ops.aten.split.Tensor, torch.ops.aten.split_copy.Tensor]
1627)
1628def _split_handler(P: MLXProgramBuilder, n: Node) -> Slot:
1629 """Handle split operation with uniform chunk size.
1630
1631 Splits a tensor into chunks of a given size along a dimension.
1632 The last chunk may be smaller if the dimension does not divide evenly.
1633
1634 PyTorch: split(x, split_size, dim=0)
1635
1636 We pass [split_size] to the interpreter, which computes the actual
1637 chunk sizes based on the tensor dimension.
1638 """
1639 args = P.args(n)
1640 require_args(args, 2, 3, "aten.split")
1641 require_kwargs(P.kwargs(n), set(), "aten.split")
1642 x = args[0]
1643 split_size = args[1]
1644 dim = args[2] if len(args) > 2 else 0
1645
1646 axis = dim if dim is not None else 0
1647 if axis < 0:
1648 x_meta = n.args[0].meta.get("val")
1649 if x_meta is None:
1650 raise RuntimeError("split: missing tensor metadata for negative axis")
1651 axis += len(x_meta.shape)
1652
1653 # Create output slots for multi-output operation
1654 output_slots = P.make_or_get_slots(n)
1655
1656 # Emit SplitNode - interpreter computes actual chunk sizes from split_size
1657 P.emit(
1658 SplitNode(
1659 x=P.slot_to_tid(x),
1660 outs=[P.slot_to_tid(s) for s in output_slots],
1661 sizes=[P.to_int_or_vid(split_size)],
1662 axis=axis,
1663 )
1664 )
1665
1666 return output_slots
1667
1668
1669@REGISTRY.register(target=[torch.ops.aten.repeat.default])

Callers

nothing calls this directly

Calls 9

require_argsFunction · 0.85
require_kwargsFunction · 0.85
argsMethod · 0.80
kwargsMethod · 0.80
emitMethod · 0.80
slot_to_tidMethod · 0.80
to_int_or_vidMethod · 0.80
getMethod · 0.45
make_or_get_slotsMethod · 0.45

Tested by

no test coverage detected