Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] NumPy and bfloat16 #9492

Open
jaketae opened this issue Jan 8, 2023 · 1 comment
Open

[Bug] NumPy and bfloat16 #9492

jaketae opened this issue Jan 8, 2023 · 1 comment
Assignees
Labels
Bug Report Report bugs detected in Ivy.

Comments

@jaketae
Copy link
Contributor

jaketae commented Jan 8, 2023

While examining why test cases were failing for

pytest ivy_tests/test_ivy/test_frontends/test_torch/test_creation_ops.py -k 'test_torch_full'

I realized that the to_numpy() function has a special branch for handling bfloat16:

https://github.com/unifyai/ivy/blob/e4f6cb774f18b8789c99a1ac4df22f342e858764/ivy/functional/backends/torch/general.py#L86-L92

The line I'm struggling to parse is

return x.detach().cpu().numpy().astype("bfloat16")

Currently, NumPy has no support for bfloat16. This can easily be checked in the interpreter.

>>> import numpy as np
>>> x = np.random.randn(1)
>>> x.astype("float16")
array([-0.343], dtype=float16)
>>> x.astype("bfloat16")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: data type 'bfloat16' not understood

There is an ongoing discussion in the NumPy repo regarding bfloat16 support. Currently, they are conservative with adopting bfloat16 and are waiting for an external proof-of-concept implementation from the community.

In short, why are we calling np.ndarray.astype("bfloat16") in the to_numpy() conversion? Thank you!


Edit: Another implicit failure comes from array_helpers.py, specifically the array_values() function. The function attempts to return a NumPy array, but when dtype is bfloat16, the return fails:

https://github.com/unifyai/ivy/blob/e4f6cb774f18b8789c99a1ac4df22f342e858764/ivy_tests/test_ivy/helpers/hypothesis_helpers/array_helpers.py#L775

This behavior is observed, for instance, when running

pytest ivy_tests/test_ivy/test_frontends/test_torch/test_tensor.py -k 'test_torch_tensor_property_ivy_array'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report Report bugs detected in Ivy.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants