Skip to content

bfloat16 unsupported by torch.tensor that takes np arrays inputs #81

@Ishticode

Description

@Ishticode

I am not sure whether to raise this here or at pytorch but here it is.
Usually this works works

x = np.array([2.], dtype=np.float16)
x = torch.tensor(x)

but not

from ml_dtypes import bfloat16
x = np.array([2.], dtype=bfloat16)
x = torch.tensor(x)

resulting in error

TypeError: can't convert np.ndarray of type bfloat16. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.

although pytorch does support bfloat16.
What do you say? or should I take this to PyTorch. Thank you.

Note: tensorflow does accept np arrays of ml_dtypes extended bfloat16 without any issue.
Note: I think u will be able to reproduce with almost all versions. But I can give the specifics if versions have anything to do with it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions