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]: Elementwise function cannot be applied or does not return the correct value to Python float when ivy.set_array_mode(False) #28839

Closed
2 of 4 tasks
34j opened this issue Oct 27, 2024 · 3 comments · Fixed by #28840 or #28841
Assignees
Labels
Bug Report Report bugs detected in Ivy.

Comments

@34j
Copy link

34j commented Oct 27, 2024

Bug Explanation

Calculating log(1):

python -c "import ivy; ivy.set_backend('torch'); ivy.set_array_mode(False); print(ivy.log(1))"
venv/lib/python3.11/site-packages/ivy/func_wrapper.py:440: UserWarning: In the case of Compositional function, operators might cause inconsistent behavior when array_mode is set to False
  warnings.warn(
tensor([])
python -c "import ivy; ivy.set_backend('numpy'); ivy.set_array_mode(False); print(ivy.log(1))"
(long output)
ivy.utils.exceptions.IvyBackendException: numpy: is_array: numpy: is_ivy_array: numpy: is_native_array: numpy: nested_argwhere: numpy: nested_argwhere: maximum recursion depth exceeded

These works:

python -c "import ivy; import numpy as np; ivy.set_backend('numpy'); ivy.set_array_mode(False); print(ivy.log(np.array(1)))"
0.0
python -c "import ivy; import torch; ivy.set_backend('torch'); ivy.set_array_mode(False); print(ivy.log(torch.tensor(1)))"
tensor(0.)

Perhaps this kind of usage is not expected, but I would just like to report it anyway.

Steps to Reproduce Bug

python -c "import ivy; ivy.set_backend('numpy'); ivy.set_array_mode(False); print(ivy.log(1))"
python -c "import ivy; ivy.set_backend('torch'); ivy.set_array_mode(False); print(ivy.log(1))"

Environment

Ubuntu 22.04

Ivy Version

1.0.0.0

Backend

  • NumPy
  • TensorFlow
  • PyTorch
  • JAX

Device

CPU

@YushaArif99
Copy link
Contributor

Hi @34j. Thanks alot for opening the issue. Upon some close inspection, it turns out the actual bug is originating from printing the result of ivy.log(1) which invokes the __repr__ method of the ivy.Array class. I have opened a PR with the relevant fix, which should hopefully also resolve this issue you were experiencing. Let me know if this works or if the issue is still persisting on your end 😄

@34j
Copy link
Author

34j commented Oct 29, 2024

@YushaArif99 Thank you very much for your swift response and fix.

I ran pip install -U --force-reinstall git+https://github.com/ivy-llc/ivy.git and ran the commands again, and the Numpy issue seems to be resolved.

$ python -c "import ivy; ivy.set_backend('numpy'); ivy.set_array_mode(False); print(ivy.log(1))"
venv/lib/python3.11/site-packages/ivy/func_wrapper.py:440: UserWarning: In the case of Compositional function, operators might cause inconsistent behavior when array_mode is set to False
  warnings.warn(
ivy.array(0.)

However, the PyTorch one still persists.
I may be doing something wrong, so could you please run the latter command on your end to check this?

As you said, the Numpy one seems to be related to print, but I think the PyTorch one is a different issue as the shape is already wrong.

$ python -c "import ivy; ivy.set_backend('torch'); ivy.set_array_mode(True); print(ivy.log(1).shape)"
ivy.Shape()
$ python -c "import ivy; ivy.set_backend('torch'); ivy.set_array_mode(False); print(ivy.log(1).shape)"
venv/lib/python3.11/site-packages/ivy/func_wrapper.py:440: UserWarning: In the case of Compositional function, operators might cause inconsistent behavior when array_mode is set to False
  warnings.warn(
torch.Size([0])

@YushaArif99
Copy link
Contributor

YushaArif99 commented Oct 30, 2024

Hi @34j. Apologies for overlooking the 2nd example, totally slipped under my radar 😅

I have opened another PR with the torch fix as well which should hopefully resolve this 2nd issue.

These are the outputs I am getting:

- import ivy; ivy.set_backend('numpy'); ivy.set_array_mode(False); print(ivy.log(1))
>>> 0.0

- import ivy; ivy.set_backend('numpy'); ivy.set_array_mode(True); print(ivy.log(1))
>>> ivy.array(0.)

- import ivy; ivy.set_backend('torch'); ivy.set_array_mode(False); print(ivy.log(1))
>>> tensor(0.)

- import ivy; ivy.set_backend('torch'); ivy.set_array_mode(True); print(ivy.log(1))
>>> ivy.array(0.)

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
2 participants