MCPcopy Create free account
hub / github.com/OpenGVLab/UniFormerV2 / _serialize_to_tensor

Function _serialize_to_tensor

slowfast/utils/distributed.py:167–192  ·  view source on GitHub ↗

Seriialize the tensor to ByteTensor. Note that only `gloo` and `nccl` backend is supported. Args: data (data): data to be serialized. group (group): pytorch dist group. Returns: tensor (ByteTensor): tensor that serialized.

(data, group)

Source from the content-addressed store, hash-verified

165
166
167def _serialize_to_tensor(data, group):
168 """
169 Seriialize the tensor to ByteTensor. Note that only `gloo` and `nccl`
170 backend is supported.
171 Args:
172 data (data): data to be serialized.
173 group (group): pytorch dist group.
174 Returns:
175 tensor (ByteTensor): tensor that serialized.
176 """
177
178 backend = dist.get_backend(group)
179 assert backend in ["gloo", "nccl"]
180 device = torch.device("cpu" if backend == "gloo" else "cuda")
181
182 buffer = pickle.dumps(data)
183 if len(buffer) > 1024 ** 3:
184 logger = logging.getLogger(__name__)
185 logger.warning(
186 "Rank {} trying to all-gather {:.2f} GB of data on device {}".format(
187 get_rank(), len(buffer) / (1024 ** 3), device
188 )
189 )
190 storage = torch.ByteStorage.from_buffer(buffer)
191 tensor = torch.ByteTensor(storage).to(device=device)
192 return tensor
193
194
195def _pad_to_largest_tensor(tensor, group):

Callers 1

all_gather_unalignedFunction · 0.85

Calls 1

get_rankFunction · 0.85

Tested by

no test coverage detected