You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
some ops are not yet supported for Dtensor
This seems to work, though there may be better solutions.
defcopy_stochastic_(target: Tensor, source: Tensor):
""" copies source into target using stochastic rounding Args: target: the target tensor with dtype=bfloat16 source: the target tensor with dtype=float32 """ifisinstance(target, DTensor):
target_for_op=target.to_local()
else:
target_for_op=targetifisinstance(source, DTensor):
source_for_op=source.to_local()
else:
source_for_op=source# create a random 16 bit integerresult=torch.randint_like(
source_for_op,
dtype=torch.int32,
low=0,
high=(1<<16),
)
# add the random number to the lower 16 bit of the mantissaresult.add_(source_for_op.view(dtype=torch.int32))
# mask off the lower 16 bit of the mantissaresult.bitwise_and_(-65536) # -65536 = FFFF0000 as a signed int32# copy the higher 16 bit into the target tensortarget_for_op.copy_(result.view(dtype=torch.float32))
torch.distributed.breakpoint(0)
ifisinstance(target, DTensor):
target_for_op=DTensor.from_local(target_for_op, device_mesh=target.device_mesh, placements=target.placements, shape=target.shape, stride=target.stride())
target.copy_(target_for_op)
# del target_for_op# if isinstance(source, DTensor):# del source_for_opdelresult```
The text was updated successfully, but these errors were encountered:
some ops are not yet supported for Dtensor
This seems to work, though there may be better solutions.
The text was updated successfully, but these errors were encountered: