Type Checking: Types Tensor and TensorFloat incompatible

I am new to static type checking in python, therefore I am not sure if this is a PyTorch Problem at all.
I am using PyRight (default for VSCode Pylance installation) for type checking. Unfortunately it keeps giving me the warning, that FloatTensor and Tensor are incompatible types. Minimal example:

import torch
from torch import FloatTensor

def createFloatTensor() -> FloatTensor:
    return torch.rand(1, 2, requires_grad=False)

Tested version:

Python 3.8.8
PyTorch 1.8.1 (Cuda)
VSCode: PyLance 2021.4.1

Is this expected behaviour and is there a quick fix for this?


The short answer is that FloatTensor are not a thing anymore. They are still here only for backward compatibility reasons.
All the Tensors are of type torch.Tensor (whatever their dtype, device, layout, etc).

1 Like