Skip to content

Commit

Permalink
Fix distributed_concat with scalar tensor (huggingface#16963)
Browse files Browse the repository at this point in the history
* Fix `distributed_concat` with scalar tensor

* Update trainer_pt_utils.py
  • Loading branch information
Yard1 authored Apr 27, 2022
1 parent 084c38c commit 5896b3e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/transformers/trainer_pt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ def distributed_concat(tensor: Any, num_total_examples: Optional[int] = None) ->
try:
if isinstance(tensor, (tuple, list)):
return type(tensor)(distributed_concat(t, num_total_examples) for t in tensor)
if len(tensor.shape) <= 0:
tensor = tensor[None]
output_tensors = [tensor.clone() for _ in range(dist.get_world_size())]
output_tensors = [t if len(t.shape) > 0 else t[None] for t in output_tensors]
dist.all_gather(output_tensors, tensor)
concat = torch.cat(output_tensors, dim=0)

Expand Down

0 comments on commit 5896b3e

Please sign in to comment.