MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / shard_tensor_node

Function shard_tensor_node

deepspeed/compile/util.py:596–612  ·  view source on GitHub ↗
(gm: GraphModule, tensor_node: Node)

Source from the content-addressed store, hash-verified

594
595
596def shard_tensor_node(gm: GraphModule, tensor_node: Node):
597 from .fx import find_node_by_name, get_node_shape_meta, replace_node_users
598 val = get_node_shape_meta(tensor_node)
599 assert val is not None, f"Node {tensor_node.name} has no shape metadata"
600
601 seq_dim = get_autosp_seq_dim(tensor_node)
602 seq_len = val.shape[seq_dim]
603
604 assert isinstance(
605 seq_len,
606 torch.SymInt), (f"Expected sequence dimension to be {torch.SymInt!r} but instead found {type(seq_len)!r}")
607
608 symb_seq_int_node = find_node_by_name(gm, str(seq_len))
609 assert symb_seq_int_node, f"Unable to find symbolic placeholder for {seq_len}"
610
611 sliced_node = insert_sequence_shard(gm, tensor_node, val.ndim, seq_dim, symb_seq_int_node)
612 replace_node_users(tensor_node, sliced_node, exclude=[sliced_node])
613
614
615def insert_sequence_shard(gm: GraphModule, tensor_node: Node, ndim: int, seq_dim: int,

Calls 5

get_node_shape_metaFunction · 0.85
get_autosp_seq_dimFunction · 0.85
find_node_by_nameFunction · 0.85
insert_sequence_shardFunction · 0.85
replace_node_usersFunction · 0.85