forked from pytorch/ao
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistributed_utils.py
More file actions
27 lines (22 loc) · 980 Bytes
/
distributed_utils.py
File metadata and controls
27 lines (22 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD 3-Clause license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.distributed._functional_collectives as funcol
from torch.distributed._tensor import DTensor
from torchao.float8.float8_training_tensor import Float8TrainingTensor
def tensor_already_casted_to_fp8(tensor: torch.Tensor) -> bool:
"""
Check if the tensor is already casted to fp8, works if the local
tensor is wrapped in DTensor.
"""
if isinstance(tensor, Float8TrainingTensor):
return True
elif isinstance(tensor, DTensor):
# TODO: shall we stick to public API and directly use tensor.to_local() here?
return tensor_already_casted_to_fp8(tensor._local_tensor)
elif isinstance(tensor, funcol.AsyncCollectiveTensor):
return tensor_already_casted_to_fp8(tensor.elem)
return False