Skip to content

Commit

Permalink
Fix gather for TPU (huggingface#13813)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgugger committed Sep 30, 2021
1 parent 54f9d62 commit 6b87918
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/transformers/trainer_pt_utils.py
Expand Up @@ -152,6 +152,8 @@ def nested_xla_mesh_reduce(tensors, name):

if isinstance(tensors, (list, tuple)):
return type(tensors)(nested_xla_mesh_reduce(t, f"{name}_{i}") for i, t in enumerate(tensors))
if tensors.ndim == 0:
tensors = tensors[None]
return xm.mesh_reduce(name, tensors, torch.cat)
else:
raise ImportError("Torch xla must be installed to use `nested_xla_mesh_reduce`")
Expand Down

0 comments on commit 6b87918

Please sign in to comment.