MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / broadcast_data

Function broadcast_data

SwissArmyTransformer/sat/mpu/data.py:76–116  ·  view source on GitHub ↗

Broadcast data from rank zero of each model parallel group to the members of the same model parallel group. Arguments: keys: list of keys in the data disctionary to be broadcasted data: data dictionary of string keys and cpu tensor values. datatype: torch data type o

(keys, data, datatype)

Source from the content-addressed store, hash-verified

74
75
76def broadcast_data(keys, data, datatype):
77 """Broadcast data from rank zero of each model parallel group to the
78 members of the same model parallel group.
79
80 Arguments:
81 keys: list of keys in the data disctionary to be broadcasted
82 data: data dictionary of string keys and cpu tensor values.
83 datatype: torch data type of all tensors in data associated
84 with keys.
85 """
86 # Build (key, size) and (key, number of elements) dictionaries along
87 # with the total number of elements on all ranks.
88 key_size, key_numel, total_numel = _build_key_size_numel_dictionaries(keys,
89 data)
90
91 # Pack on rank zero.
92 if get_model_parallel_rank() == 0:
93 # Check that all keys have the same data type.
94 _check_data_types(keys, data, datatype)
95 # Flatten the data associated with the keys
96 flatten_data = torch.cat(
97 [data[key].contiguous().view(-1) for key in keys], dim=0).cuda()
98 else:
99 flatten_data = torch.empty(total_numel,
100 device=torch.cuda.current_device(),
101 dtype=datatype)
102
103 # Boradcast
104 torch.distributed.broadcast(flatten_data, get_model_parallel_src_rank(),
105 group=get_model_parallel_group())
106
107 # Unpack
108 output = {}
109 offset = 0
110 for key in keys:
111 size = key_size[key]
112 numel = key_numel[key]
113 output[key] = flatten_data.narrow(0, offset, numel).view(size)
114 offset += numel
115
116 return output

Callers

nothing calls this directly

Calls 5

get_model_parallel_rankFunction · 0.85
_check_data_typesFunction · 0.85
get_model_parallel_groupFunction · 0.85

Tested by

no test coverage detected