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

Function broad_cast_batch

sat/train_video.py:116–157  ·  view source on GitHub ↗
(batch)

Source from the content-addressed store, hash-verified

114
115
116def broad_cast_batch(batch):
117 mp_size = mpu.get_model_parallel_world_size()
118 global_rank = torch.distributed.get_rank() // mp_size
119 src = global_rank * mp_size
120
121 if batch["mp4"] is not None:
122 shape_keys = ['mp4', 'fps', 'num_frames', 'fut_traj']
123 broadcast_shape = {
124 key: batch[key].shape for key in shape_keys if key in batch.keys()
125 }
126 else:
127 broadcast_shape = None
128
129 obj_keys = ['txt', 'with_traj', 'with_human_drive_token']
130
131 broadcast_obj = [{key: batch[key] for key in obj_keys}]
132 broadcast_obj.append(broadcast_shape)
133
134 torch.distributed.broadcast_object_list(broadcast_obj, src=src, group=mpu.get_model_parallel_group())
135 objs = broadcast_obj[0]
136 for key, value in objs.items():
137 batch[key] = value
138
139 shapes = broadcast_obj[1]
140
141 mp4_shape = shapes['mp4']
142 fps_shape = shapes['fps']
143 num_frames_shape = shapes['num_frames']
144 fut_traj_shape = shapes['fut_traj']
145
146 if mpu.get_model_parallel_rank() != 0:
147 batch["mp4"] = torch.zeros(mp4_shape, device="cuda")
148 batch["fps"] = torch.zeros(fps_shape, device="cuda", dtype=torch.long)
149 batch["num_frames"] = torch.zeros(num_frames_shape, device="cuda", dtype=torch.long)
150
151 batch["fut_traj"] = torch.zeros(fut_traj_shape, device="cuda")
152
153 torch.distributed.broadcast(batch["mp4"], src=src, group=mpu.get_model_parallel_group())
154 torch.distributed.broadcast(batch["fps"], src=src, group=mpu.get_model_parallel_group())
155 torch.distributed.broadcast(batch["num_frames"], src=src, group=mpu.get_model_parallel_group())
156 torch.distributed.broadcast(batch["fut_traj"], src=src, group=mpu.get_model_parallel_group())
157 return batch
158
159
160def forward_step_eval(data_iterator, model, args, timers, only_log_video_latents=False, data_class=None):

Callers 2

forward_step_evalFunction · 0.85
forward_stepFunction · 0.85

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected