Skip to content

Commit

Permalink
Fix UserWarning: The torch.cuda.*DtypeTensor constructors are no long… (
Browse files Browse the repository at this point in the history
#5018)

> …er recommended. It's best to use methods such as torch.tensor(data,
dtype=*, device='cuda') to create tensors.

By currying the returned tensor properties in CUDA_Accelerator, the
above warning in PyTorch is avoided.

Co-authored-by: Olatunji Ruwase <olruwase@microsoft.com>
Co-authored-by: Logan Adams <114770087+loadams@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 16, 2024
1 parent a3be0d4 commit 177dc14
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions accelerator/cuda_accelerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# DeepSpeed Team

import functools
import os
import pkgutil
import importlib
Expand Down Expand Up @@ -260,31 +261,31 @@ def replay_graph(self, graph):

@property
def BFloat16Tensor(self):
return torch.cuda.BFloat16Tensor
return functools.partial(torch.tensor, dtype=torch.bfloat16, device='cuda')

@property
def ByteTensor(self):
return torch.cuda.ByteTensor
return functools.partial(torch.tensor, dtype=torch.uint8, device='cuda')

@property
def DoubleTensor(self):
return torch.cuda.DoubleTensor
return functools.partial(torch.tensor, dtype=torch.double, device='cuda')

@property
def FloatTensor(self):
return torch.cuda.FloatTensor
return functools.partial(torch.tensor, dtype=torch.float, device='cuda')

@property
def HalfTensor(self):
return torch.cuda.HalfTensor
return functools.partial(torch.tensor, dtype=torch.half, device='cuda')

@property
def IntTensor(self):
return torch.cuda.IntTensor
return functools.partial(torch.tensor, dtype=torch.int, device='cuda')

@property
def LongTensor(self):
return torch.cuda.LongTensor
return functools.partial(torch.tensor, dtype=torch.long, device='cuda')

def pin_memory(self, tensor, align_bytes=1):
return tensor.pin_memory()
Expand Down

0 comments on commit 177dc14

Please # to comment.