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

Implemented torch.nn.functional.dropout2d #15643

Merged
merged 14 commits into from Jul 8, 2023

Conversation

Ali-12122
Copy link
Contributor

close #15394

@ivy-leaves ivy-leaves added the PyTorch Frontend Developing the PyTorch Frontend, checklist triggered by commenting add_frontend_checklist label May 18, 2023
@Ali-12122
Copy link
Contributor Author

Currently this function is not working due to #15475, and Im trying to fix it in the mean time.

@Ali-12122 Ali-12122 marked this pull request as ready for review May 18, 2023 16:14
Copy link
Contributor

@hmahmood24 hmahmood24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Ali-12122. Hope you're doing well. Can you kindly refactor your implementation to use ivy.dropout2d instead since it has been added to ivy in this commit here. That should also resolve the issue with ivy.bernoulli you were facing and we can then get the PR to merge after it passes all tests. Thanks!

@Ali-12122
Copy link
Contributor Author

absolutely, thank you.

@Ali-12122
Copy link
Contributor Author

Hi @hmahmood24, so I have refactored my code as we previously agreed, but for some reason I can't get my test to run, neither was I able to run the other test in the file, test_torch_dropout().

When running any test, i get this horrendous error log.

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy\utils\exceptions.py", line 210, in _handle_exceptions
INTERNALERROR>     return fn(*args, **kwargs)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy\functional\ivy\general.py", line 568, in set_exception_trace_mode
INTERNALERROR>     ivy.__setattr__("exception_trace_mode", mode, True)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy\__init__.py", line 1306, in __setattr__
INTERNALERROR>     raise ivy.utils.exceptions.IvyException(
INTERNALERROR> ivy.utils.exceptions.IvyException: Property: exception_trace_mode is read only! Please use the setter: set_exception_trace_mode() for setting its value!
INTERNALERROR> 
INTERNALERROR> During handling of the above exception, another exception occurred:
INTERNALERROR> 
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\main.py", line 265, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\config\__init__.py", line 1046, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_hooks.py", line 277, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\conftest.py", line 37, in pytest_configure
INTERNALERROR>     set_exception_trace_mode(config.getoption("--ivy-tb"))
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy\utils\exceptions.py", line 246, in _handle_exceptions
INTERNALERROR>     raise ivy.utils.exceptions.IvyBackendException(
INTERNALERROR> ivy.utils.exceptions.IvyBackendException: numpy: set_exception_trace_mode:   File "C:\Users\aliam\ivy\ivy\ivy\utils\exceptions.py", line 210, in _handle_exceptions
INTERNALERROR>     return fn(*args, **kwargs)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy\functional\ivy\general.py", line 568, in set_exception_trace_mode
INTERNALERROR>     ivy.__setattr__("exception_trace_mode", mode, True)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy\__init__.py", line 1306, in __setattr__
INTERNALERROR>     raise ivy.utils.exceptions.IvyException(
INTERNALERROR> During the handling of the above exception, another exception occurred:
INTERNALERROR>  Property: exception_trace_mode is read only! Please use the setter: set_exception_trace_mode() for setting its value!

Process finished with exit code 3

Empty suite

What am I doing wrong?

Thanks in advance.

@Ali-12122 Ali-12122 closed this Jun 15, 2023
@Ali-12122 Ali-12122 reopened this Jun 15, 2023
Copy link
Contributor

@hmahmood24 hmahmood24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Ali-12122. Thanks for making the changes. I have requested just a couple more changes for you to make. Regarding the bug you were facing, try re-syncing with master and running the tests again. That bug should be resolved now. If you face any other problems or isses, feel free to reach out or re-request a review once done. Thanks! :)

Comment on lines 23 to 24
if not training:
return tensor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can pass the training parameter as it is to the ivy.dropout2d function since it can handle these checks itself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to pass all the parameters to ivy.dropout2d but it throws errors if I pass anything other than prob, I'll try to see if this will be solved be re-syncing with master, if not, I'll create a bug report and link it here.

if not training:
return tensor

ret = tensor.dropout2d(prob)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant to use ivy.dropout here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used ivy.dropout2d because we agreed to do so, should I use ivy.dropout instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used ivy.dropout2d because we agreed to do so, should I use ivy.dropout instead?

Oh sorry I meant ivy.dropout2d haha. You have used tensor.dropout2d which doesn't exist. You have to use ivy.dropout2d

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgive me if I am missing something but isn't this use case similar to what I'm doing?

or maybe I should use ivy.dropout2d() incase tensor is not an ivy.Array?

@Ali-12122
Copy link
Contributor Author

@hmahmood24 so I have passed the arguments to ivy.dropout2d() and re-ran the test again but a new error emerged,

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\main.py", line 265, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\config\__init__.py", line 1046, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_hooks.py", line 277, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\conftest.py", line 86, in pytest_configure
INTERNALERROR>     test_globals.FWS_DICT[backend_str](),
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 21, in <lambda>
INTERNALERROR>     FWS_DICT["jax"] = lambda x=None: _get_ivy_jax(x)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 76, in _get_ivy_jax
INTERNALERROR>     import ivy.functional.backends.jax
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy\functional\backends\jax\__init__.py", line 21, in <module>
INTERNALERROR>     register_pytree_node(
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\jax\_src\tree_util.py", line 137, in register_pytree_node
INTERNALERROR>     pytree.register_node(nodetype, flatten_func, unflatten_func)
INTERNALERROR> ValueError: Duplicate custom PyTreeDef type registration for <class 'ivy.data_classes.container.container.Container'>.

Process finished with exit code 3

Empty suite

what am I doing wrong?

@hmahmood24
Copy link
Contributor

tensor.dropout2d doesn't exist. You have to use ivy.dropout2d

@Ali-12122
Copy link
Contributor Author

@hmahmood24 Thank you for your time, energy, and effort with me man, really.

I'll try again using ivy.dropout2d() and see if this solves the issue.

again, thank you for everything.

@Ali-12122
Copy link
Contributor Author

okay, ivy.dropout2d does in fact work, alone it works, but the issue lies with the decorator @to_ivy_arrays_and_back.

@to_ivy_arrays_and_back
def dropout2d(tensor, prob=0.5, training=True, data_format="NCHW", inplace=False):
    if tensor.ndim < 2:
        raise ValueError("Feature dropout requires at least 2 dimensions in the input")

    ret = ivy.dropout2d(tensor, prob, training=training, data_format=data_format)
    if inplace:
        ivy.inplace_update(tensor, ret)
        return tensor
    return ret


rando = ivy.asarray([
    [1, 2, 3, 4],
    [4, 5, 6, 7],
    [7, 8, 9, 10]
])
z = dropout2d(tensor=rando, prob=0.5, training=False, data_format="NCHW", inplace=False)
print(z)

throws this error:

C:\Users\aliam\.conda\envs\ivy_dev\python.exe C:\Users\aliam\ivy\ivy\ivy\functional\frontends\torch\nn\functional\dropout_functions.py 
  File "C:\Users\aliam\ivy\ivy\ivy\functional\frontends\torch\nn\functional\dropout_functions.py", line 5, in <module>
    from ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back
  File "C:\Users\aliam\ivy\ivy\ivy\functional\frontends\torch\__init__.py", line 252, in <module>
    from . import nn
  File "C:\Users\aliam\ivy\ivy\ivy\functional\frontends\torch\nn\__init__.py", line 1, in <module>
    from . import functional
  File "C:\Users\aliam\ivy\ivy\ivy\functional\frontends\torch\nn\functional\__init__.py", line 5, in <module>
    from . import dropout_functions
  File "C:\Users\aliam\ivy\ivy\ivy\functional\frontends\torch\nn\functional\dropout_functions.py", line 35, in <module>
    z = dropout2d(tensor=rando, prob=0.5, training=False, data_format="NCHW", inplace=False)
  File "C:\Users\aliam\ivy\ivy\ivy\functional\frontends\torch\func_wrapper.py", line 84, in outputs_to_frontend_arrays_torch
    ivy.set_default_float_dtype(torch_frontend.get_default_dtype())

AttributeError: partially initialized module 'ivy.functional.frontends.torch' has no attribute 'get_default_dtype' (most likely due to a circular import)

Process finished with exit code 1

Is this from me or should I go make a bug report?

Thanks in advance.

@hmahmood24
Copy link
Contributor

okay, ivy.dropout2d does in fact work, alone it works, but the issue lies with the decorator @to_ivy_arrays_and_back.

@to_ivy_arrays_and_back
def dropout2d(tensor, prob=0.5, training=True, data_format="NCHW", inplace=False):
    if tensor.ndim < 2:
        raise ValueError("Feature dropout requires at least 2 dimensions in the input")

    ret = ivy.dropout2d(tensor, prob, training=training, data_format=data_format)
    if inplace:
        ivy.inplace_update(tensor, ret)
        return tensor
    return ret


rando = ivy.asarray([
    [1, 2, 3, 4],
    [4, 5, 6, 7],
    [7, 8, 9, 10]
])
z = dropout2d(tensor=rando, prob=0.5, training=False, data_format="NCHW", inplace=False)
print(z)

throws this error:

C:\Users\aliam\.conda\envs\ivy_dev\python.exe C:\Users\aliam\ivy\ivy\ivy\functional\frontends\torch\nn\functional\dropout_functions.py 
  File "C:\Users\aliam\ivy\ivy\ivy\functional\frontends\torch\nn\functional\dropout_functions.py", line 5, in <module>
    from ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back
  File "C:\Users\aliam\ivy\ivy\ivy\functional\frontends\torch\__init__.py", line 252, in <module>
    from . import nn
  File "C:\Users\aliam\ivy\ivy\ivy\functional\frontends\torch\nn\__init__.py", line 1, in <module>
    from . import functional
  File "C:\Users\aliam\ivy\ivy\ivy\functional\frontends\torch\nn\functional\__init__.py", line 5, in <module>
    from . import dropout_functions
  File "C:\Users\aliam\ivy\ivy\ivy\functional\frontends\torch\nn\functional\dropout_functions.py", line 35, in <module>
    z = dropout2d(tensor=rando, prob=0.5, training=False, data_format="NCHW", inplace=False)
  File "C:\Users\aliam\ivy\ivy\ivy\functional\frontends\torch\func_wrapper.py", line 84, in outputs_to_frontend_arrays_torch
    ivy.set_default_float_dtype(torch_frontend.get_default_dtype())

AttributeError: partially initialized module 'ivy.functional.frontends.torch' has no attribute 'get_default_dtype' (most likely due to a circular import)

Process finished with exit code 1

Is this from me or should I go make a bug report?

Thanks in advance.

I think you need to make the changes in your code first and then I'll look at the logs from the CI tests to see what's going on. Can you kindly make the changes I requested first?



@to_ivy_arrays_and_back
def dropout2d(tensor, prob=0.5, training=True, data_format="NCHW", inplace=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original torch function doesn't have a data_format argument as seen here. Can you please remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry I've missed that, I will remove it, thank you for mentioning it.

if tensor.ndim < 2:
raise ValueError("Feature dropout requires at least 2 dimensions in the input")

ret = tensor.dropout2d(prob, training=training, data_format=data_format)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ivy.dropout2d here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolutely.

@Ali-12122
Copy link
Contributor Author

I used ivy.dropout2d() as we agreed, removed the argument data_format, and renamed arguments tensor to input and prob to p to match the signature of the orignal torch function.

I have also set data_format in ivy.dropout2d() to "NCHW" to match the data format used by torch.

I re-ran the test and got this error log:

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\main.py", line 265, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\config\__init__.py", line 1046, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_hooks.py", line 277, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\conftest.py", line 86, in pytest_configure
INTERNALERROR>     test_globals.FWS_DICT[backend_str](),
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 21, in <lambda>
INTERNALERROR>     FWS_DICT["jax"] = lambda x=None: _get_ivy_jax(x)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 76, in _get_ivy_jax
INTERNALERROR>     import ivy.functional.backends.jax
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy\functional\backends\jax\__init__.py", line 21, in <module>
INTERNALERROR>     register_pytree_node(
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\jax\_src\tree_util.py", line 137, in register_pytree_node
INTERNALERROR>     pytree.register_node(nodetype, flatten_func, unflatten_func)
INTERNALERROR> ValueError: Duplicate custom PyTreeDef type registration for <class 'ivy.data_classes.container.container.Container'>.

Process finished with exit code 3

Empty suite

Comment on lines 94 to 97
x=x[0],
prob=prob,
training=training,
data_format=data_format,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The input parameters need to be renamed here as well i.e. x will be input, prob to p and data_format will be removed since it doesn't exist in the original function's signature

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolutely

prob=prob,
training=training,
data_format=data_format,
return_flat_np_arrays=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think you need this here since this is handled in the helpers.flatten_and_to_np function right below. Can you elaborate on why you added this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, I'll remove it.

Can you elaborate on why you added this?

I didn't add, I took the test for ivy.dropout2d and tried to adapt it as much as I can to my case, I thought that would be a more correct way of doing things, but it looks like I've missed a couple of things.

please let me know if the approach I took was problematic.

),
prob=helpers.floats(min_value=0, max_value=0.9),
training=st.booleans(),
data_format=st.sampled_from(["NCHW", "NHWC"]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I'll remove it.

@hmahmood24
Copy link
Contributor

hmahmood24 commented Jun 18, 2023

I used ivy.dropout2d() as we agreed, removed the argument data_format, and renamed arguments tensor to input and prob to p to match the signature of the orignal torch function.

I have also set data_format in ivy.dropout2d() to "NCHW" to match the data format used by torch.

I re-ran the test and got this error log:

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\main.py", line 265, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\config\__init__.py", line 1046, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_hooks.py", line 277, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\conftest.py", line 86, in pytest_configure
INTERNALERROR>     test_globals.FWS_DICT[backend_str](),
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 21, in <lambda>
INTERNALERROR>     FWS_DICT["jax"] = lambda x=None: _get_ivy_jax(x)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 76, in _get_ivy_jax
INTERNALERROR>     import ivy.functional.backends.jax
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy\functional\backends\jax\__init__.py", line 21, in <module>
INTERNALERROR>     register_pytree_node(
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\jax\_src\tree_util.py", line 137, in register_pytree_node
INTERNALERROR>     pytree.register_node(nodetype, flatten_func, unflatten_func)
INTERNALERROR> ValueError: Duplicate custom PyTreeDef type registration for <class 'ivy.data_classes.container.container.Container'>.

Process finished with exit code 3

Empty suite

I'll look into this issue. Apologies for this and thanks for bringing this up. In the meantime, do address the changes I requested. Also can you run some test in another module within the torch frontend and verify if that runs fine for you? Maybe try running the test for torch.nn.functional.dropout in the same file? For completeness, run some test in another file as well and let me know. Thanks

@Ali-12122
Copy link
Contributor Author

@hmahmood24 Again, thank you for your time, energy, and efforts with me, it is much appreciated.

I have made the following changes:

The requested changes:

1- Removed data_format strategy in handle_frontend_test decorator.
2- Renamed parameters x to input and prob to p.
3- Removed return_flat_np_arrays=True.

Issues I think I fixed:

4- Removed test_gradients in the handle_frontend_test as it is not a parameter used by it.
5- Added test_inplace in the handle_frontend_test as it was missing.
6- Converted the x to np.array and flattened it to match ret and gt_ret.

Please let me know if I should reverse any of them.

Regarding the tests, not even one ran, all of them threw errors.

test_torch_dropout2d

2023-06-18 11:38:55.443317: W external/org_tensorflow/tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2023-06-18 11:38:55.456721: W external/org_tensorflow/tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\main.py", line 265, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\config\__init__.py", line 1046, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_hooks.py", line 277, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\conftest.py", line 86, in pytest_configure
INTERNALERROR>     test_globals.FWS_DICT[backend_str](),
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 21, in <lambda>
INTERNALERROR>     FWS_DICT["jax"] = lambda x=None: _get_ivy_jax(x)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 76, in _get_ivy_jax
INTERNALERROR>     import ivy.functional.backends.jax
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy\functional\backends\jax\__init__.py", line 21, in <module>
INTERNALERROR>     register_pytree_node(
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\jax\_src\tree_util.py", line 137, in register_pytree_node
INTERNALERROR>     pytree.register_node(nodetype, flatten_func, unflatten_func)
INTERNALERROR> ValueError: Duplicate custom PyTreeDef type registration for <class 'ivy.data_classes.container.container.Container'>.

Process finished with exit code 3

Empty suite

Its sister function also failed.

test_torch_dropout

2023-06-18 11:41:02.068177: W external/org_tensorflow/tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2023-06-18 11:41:02.076938: W external/org_tensorflow/tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\main.py", line 265, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\config\__init__.py", line 1046, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_hooks.py", line 277, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\conftest.py", line 86, in pytest_configure
INTERNALERROR>     test_globals.FWS_DICT[backend_str](),
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 21, in <lambda>
INTERNALERROR>     FWS_DICT["jax"] = lambda x=None: _get_ivy_jax(x)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 76, in _get_ivy_jax
INTERNALERROR>     import ivy.functional.backends.jax
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy\functional\backends\jax\__init__.py", line 21, in <module>
INTERNALERROR>     register_pytree_node(
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\jax\_src\tree_util.py", line 137, in register_pytree_node
INTERNALERROR>     pytree.register_node(nodetype, flatten_func, unflatten_func)
INTERNALERROR> ValueError: Duplicate custom PyTreeDef type registration for <class 'ivy.data_classes.container.container.Container'>.

Process finished with exit code 3

Empty suite

I ran test_torch_det from test_torch\test_linalg with no avail:

test_torch_det

2023-06-18 11:44:58.718544: W external/org_tensorflow/tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2023-06-18 11:44:58.727172: W external/org_tensorflow/tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\main.py", line 265, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\config\__init__.py", line 1046, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_hooks.py", line 277, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\conftest.py", line 86, in pytest_configure
INTERNALERROR>     test_globals.FWS_DICT[backend_str](),
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 21, in <lambda>
INTERNALERROR>     FWS_DICT["jax"] = lambda x=None: _get_ivy_jax(x)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 76, in _get_ivy_jax
INTERNALERROR>     import ivy.functional.backends.jax
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy\functional\backends\jax\__init__.py", line 21, in <module>
INTERNALERROR>     register_pytree_node(
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\jax\_src\tree_util.py", line 137, in register_pytree_node
INTERNALERROR>     pytree.register_node(nodetype, flatten_func, unflatten_func)
INTERNALERROR> ValueError: Duplicate custom PyTreeDef type registration for <class 'ivy.data_classes.container.container.Container'>.

Process finished with exit code 3

Empty suite

What is it that I am doing wrong? I can't imagine that all ivy tests are failing for everybody.

@hmahmood24
Copy link
Contributor

@hmahmood24 Again, thank you for your time, energy, and efforts with me, it is much appreciated.

I have made the following changes:

The requested changes:

1- Removed data_format strategy in handle_frontend_test decorator. 2- Renamed parameters x to input and prob to p. 3- Removed return_flat_np_arrays=True.

Issues I think I fixed:

4- Removed test_gradients in the handle_frontend_test as it is not a parameter used by it. 5- Added test_inplace in the handle_frontend_test as it was missing. 6- Converted the x to np.array and flattened it to match ret and gt_ret.

Please let me know if I should reverse any of them.

Regarding the tests, not even one ran, all of them threw errors.

test_torch_dropout2d

2023-06-18 11:38:55.443317: W external/org_tensorflow/tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2023-06-18 11:38:55.456721: W external/org_tensorflow/tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\main.py", line 265, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\config\__init__.py", line 1046, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_hooks.py", line 277, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\conftest.py", line 86, in pytest_configure
INTERNALERROR>     test_globals.FWS_DICT[backend_str](),
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 21, in <lambda>
INTERNALERROR>     FWS_DICT["jax"] = lambda x=None: _get_ivy_jax(x)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 76, in _get_ivy_jax
INTERNALERROR>     import ivy.functional.backends.jax
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy\functional\backends\jax\__init__.py", line 21, in <module>
INTERNALERROR>     register_pytree_node(
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\jax\_src\tree_util.py", line 137, in register_pytree_node
INTERNALERROR>     pytree.register_node(nodetype, flatten_func, unflatten_func)
INTERNALERROR> ValueError: Duplicate custom PyTreeDef type registration for <class 'ivy.data_classes.container.container.Container'>.

Process finished with exit code 3

Empty suite

Its sister function also failed.

test_torch_dropout

2023-06-18 11:41:02.068177: W external/org_tensorflow/tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2023-06-18 11:41:02.076938: W external/org_tensorflow/tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\main.py", line 265, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\config\__init__.py", line 1046, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_hooks.py", line 277, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\conftest.py", line 86, in pytest_configure
INTERNALERROR>     test_globals.FWS_DICT[backend_str](),
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 21, in <lambda>
INTERNALERROR>     FWS_DICT["jax"] = lambda x=None: _get_ivy_jax(x)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 76, in _get_ivy_jax
INTERNALERROR>     import ivy.functional.backends.jax
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy\functional\backends\jax\__init__.py", line 21, in <module>
INTERNALERROR>     register_pytree_node(
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\jax\_src\tree_util.py", line 137, in register_pytree_node
INTERNALERROR>     pytree.register_node(nodetype, flatten_func, unflatten_func)
INTERNALERROR> ValueError: Duplicate custom PyTreeDef type registration for <class 'ivy.data_classes.container.container.Container'>.

Process finished with exit code 3

Empty suite

I ran test_torch_det from test_torch\test_linalg with no avail:

test_torch_det

2023-06-18 11:44:58.718544: W external/org_tensorflow/tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2023-06-18 11:44:58.727172: W external/org_tensorflow/tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\main.py", line 265, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\_pytest\config\__init__.py", line 1046, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_hooks.py", line 277, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\conftest.py", line 86, in pytest_configure
INTERNALERROR>     test_globals.FWS_DICT[backend_str](),
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 21, in <lambda>
INTERNALERROR>     FWS_DICT["jax"] = lambda x=None: _get_ivy_jax(x)
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy_tests\test_ivy\helpers\globals.py", line 76, in _get_ivy_jax
INTERNALERROR>     import ivy.functional.backends.jax
INTERNALERROR>   File "C:\Users\aliam\ivy\ivy\ivy\functional\backends\jax\__init__.py", line 21, in <module>
INTERNALERROR>     register_pytree_node(
INTERNALERROR>   File "C:\Users\aliam\.conda\envs\ivy_dev\lib\site-packages\jax\_src\tree_util.py", line 137, in register_pytree_node
INTERNALERROR>     pytree.register_node(nodetype, flatten_func, unflatten_func)
INTERNALERROR> ValueError: Duplicate custom PyTreeDef type registration for <class 'ivy.data_classes.container.container.Container'>.

Process finished with exit code 3

Empty suite

What is it that I am doing wrong? I can't imagine that all ivy tests are failing for everybody.

Yeah no I think the problem is with your environment. You'll probably to work in a clean environment to get the tests running. Regarding the changes, they all seem fine to keep 👍🏼 No worries. Can you try testing in a fresh environment?

@Ali-12122
Copy link
Contributor Author

hey @hmahmood24, so I have changed my environment, and I'm currently using a docker interpreter instead of Conda, things have improved but I'm still facing issues, all tests keep failing.

test_torch_dropout2d

test_dropout_functions.py::test_torch_dropout2d[cpu-ivy.functional.backends.numpy-False-False] ERROR [100%]
test setup failed
file /ivy/ivy_tests/test_ivy/test_frontends/test_torch/test_dropout_functions.py, line 55
  @handle_frontend_test(
      fn_tree="torch.nn.functional.dropout2d",
      dtype_and_x=helpers.dtype_and_values(
          available_dtypes=helpers.get_dtypes("float"),
          min_value=0,
          max_value=50,
          allow_inf=False,
          min_num_dims=2,
          max_num_dims=4,
          min_dim_size=1,
          max_dim_size=5,
      ),
      prob=helpers.floats(min_value=0, max_value=0.9),
      training=st.booleans(),
      test_with_out=st.just(False),
      test_inplace=st.just(False),
  )
  def test_torch_dropout2d(
E       fixture 'fn_name' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, frontend, include_metadata_in_junit_xml, json_metadata, metadata, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, run_around_tests, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

/ivy/ivy_tests/test_ivy/test_frontends/test_torch/test_dropout_functions.py:55

test_torch_dropout

test_dropout_functions.py::test_torch_dropout[cpu-ivy.functional.backends.numpy-False-False] FAILED [100%]
ivy_tests/test_ivy/test_frontends/test_torch/test_dropout_functions.py:9 (test_torch_dropout[cpu-ivy.functional.backends.numpy-False-False])
@handle_frontend_test(
>       fn_tree="torch.nn.functional.dropout",
        dtype_and_x=helpers.dtype_and_values(
            available_dtypes=helpers.get_dtypes("float"),
            min_value=0,
            max_value=50,
            allow_inf=False,
            min_num_dims=1,
            max_num_dims=1,
            min_dim_size=2,
        ),
        prob=helpers.floats(min_value=0, max_value=0.9),
        training=st.booleans(),
        test_with_out=st.just(True),
        test_inplace=st.just(False),
    )

test_dropout_functions.py:11: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../helpers/hypothesis_helpers/array_helpers.py:490: in dtype_and_values
    available_dtypes = draw(available_dtypes)
/opt/miniconda/envs/multienv/lib/python3.10/site-packages/hypothesis/internal/conjecture/data.py:951: in draw
    return strategy.do_draw(self)
/opt/miniconda/envs/multienv/lib/python3.10/site-packages/hypothesis/strategies/_internal/core.py:1558: in do_draw
    return self.definition(data.draw, *self.args, **self.kwargs)
../../helpers/hypothesis_helpers/dtype_helpers.py:173: in get_dtypes
    valid_dtypes = set(retrieval_fn(test_globals.CURRENT_BACKEND(), kind))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

framework = <module 'ivy.functional.backends.numpy' from '/ivy/ivy/functional/backends/numpy/__init__.py'>
kind = 'float'

    def _get_fn_dtypes(framework, kind="valid"):
>       return test_globals.CURRENT_RUNNING_TEST.supported_device_dtypes[framework.backend][
            test_globals.CURRENT_DEVICE_STRIPPED
        ][kind]
E       KeyError: 'cpu'
E       
E       You can reproduce this example by temporarily adding @reproduce_failure('6.79.0', b'AA==') as a decorator on your test case

../../helpers/hypothesis_helpers/dtype_helpers.py:35: KeyError

test_torch_det

test_linalg.py::test_torch_det[cpu-ivy.functional.backends.numpy-False-False] FAILED [100%]
ivy_tests/test_ivy/test_frontends/test_torch/test_linalg.py:217 (test_torch_det[cpu-ivy.functional.backends.numpy-False-False])
@handle_frontend_test(
>       fn_tree="torch.linalg.det",
        aliases=["torch.det"],
        dtype_and_x=_get_dtype_and_square_matrix(),
    )

test_linalg.py:219: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
test_linalg.py:25: in _get_dtype_and_square_matrix
    dim_size = draw(helpers.ints(min_value=2, max_value=5))
/opt/miniconda/envs/multienv/lib/python3.10/site-packages/hypothesis/internal/conjecture/data.py:951: in draw
    return strategy.do_draw(self)
/opt/miniconda/envs/multienv/lib/python3.10/site-packages/hypothesis/strategies/_internal/lazy.py:156: in do_draw
    return data.draw(self.wrapped_strategy)
/opt/miniconda/envs/multienv/lib/python3.10/site-packages/hypothesis/internal/conjecture/data.py:951: in draw
    return strategy.do_draw(self)
/opt/miniconda/envs/multienv/lib/python3.10/site-packages/hypothesis/strategies/_internal/core.py:1558: in do_draw
    return self.definition(data.draw, *self.args, **self.kwargs)
../../helpers/hypothesis_helpers/number_helpers.py:176: in ints
    dtype = draw(dtype_helpers.get_dtypes("integer", full=False, prune_function=False))
/opt/miniconda/envs/multienv/lib/python3.10/site-packages/hypothesis/internal/conjecture/data.py:951: in draw
    return strategy.do_draw(self)
/opt/miniconda/envs/multienv/lib/python3.10/site-packages/hypothesis/strategies/_internal/lazy.py:156: in do_draw
    return data.draw(self.wrapped_strategy)
/opt/miniconda/envs/multienv/lib/python3.10/site-packages/hypothesis/internal/conjecture/data.py:951: in draw
    return strategy.do_draw(self)
/opt/miniconda/envs/multienv/lib/python3.10/site-packages/hypothesis/strategies/_internal/core.py:1558: in do_draw
    return self.definition(data.draw, *self.args, **self.kwargs)
../../helpers/hypothesis_helpers/dtype_helpers.py:243: in get_dtypes
    frontend_dtypes = retrieval_fn(test_globals.CURRENT_FRONTEND(), kind)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

framework = None, kind = 'integer'

    def _get_type_dict(framework, kind):
        if kind == "valid":
            return framework.valid_dtypes
        elif kind == "numeric":
            return framework.valid_numeric_dtypes
        elif kind == "integer":
>           return framework.valid_int_dtypes
E           AttributeError: 'NoneType' object has no attribute 'valid_int_dtypes'
E           
E           You can reproduce this example by temporarily adding @reproduce_failure('6.79.0', b'AA==') as a decorator on your test case

../../helpers/hypothesis_helpers/dtype_helpers.py:46: AttributeError

should I try in a new environment again?

@Ali-12122
Copy link
Contributor Author

Hey @hmahmood24, so I have moved to GitHub codespaces and fixed some issues in my git configuration, everything runs well and other tests are working well, my test works but it keeps failing, if you could please check it out today and see where's the issue I would be extremely grateful.

Thank you in advance.

Here is the error log:

@Ali-12122/workspaces/ivy (torch-dropout2d) $ python3 -m pytest -v -x ivy_tests/test_ivy/test_frontends/test_torch/test_dropout_functions.py::test_torch_dropout2d

Use Database in ReadOnly Mode with local caching !
======================================================================================= test session starts =======================================================================================
platform linux -- Python 3.10.8, pytest-7.4.0, pluggy-1.2.0 -- /home/codespace/.python/current/bin/python3
cachedir: .pytest_cache
hypothesis profile 'ivy_profile' -> max_examples=25, print_blob=True, deadline=timedelta(milliseconds=500000), suppress_health_check=[HealthCheck.too_slow, HealthCheck.filter_too_much, HealthCheck.data_too_large], database=MultiplexedDatabase(DirectoryBasedExampleDatabase('/workspaces/ivy/.hypothesis/examples/'), ReadOnlyDatabase(RedisExampleDatabase(Redis<ConnectionPool<Connection<host=redis-17011.c259.us-central1-2.gce.cloud.redislabs.com,port=17011,db=0>>>, expire_after=datetime.timedelta(days=8))))
backend(s): all
device: cpu
number of Hypothesis examples: 25
rootdir: /workspaces/ivy
plugins: anyio-3.7.0, hypothesis-6.79.2
collected 2 items                                                                                                                                                                                 

ivy_tests/test_ivy/test_frontends/test_torch/test_dropout_functions.py::test_torch_dropout2d[cpu-ivy.functional.backends.numpy-False-False] FAILED                                          [ 50%]

============================================================================================ FAILURES =============================================================================================
_______________________________________________________________ test_torch_dropout2d[cpu-ivy.functional.backends.numpy-False-False] _______________________________________________________________

args = (ivy.array([[0.]]), 0.5), kwargs = {'data_format': 'NCHW', 'training': True}

    @functools.wraps(fn)
    def _handle_exceptions(*args, **kwargs):
        """
        Catch all exceptions and raise them in IvyException.
    
        Parameters
        ----------
        args
            The arguments to be passed to the function.
    
        kwargs
            The keyword arguments to be passed to the function.
    
        Returns
        -------
            The return of the function, or raise IvyException if error is thrown.
        """
        try:
>           return fn(*args, **kwargs)

ivy/utils/exceptions.py:210: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ivy/func_wrapper.py:971: in _handle_nestable
    return fn(*args, **kwargs)
ivy/func_wrapper.py:399: in _handle_array_like_without_promotion
    return fn(*args, **kwargs)
ivy/func_wrapper.py:863: in _handle_out_argument
    return fn(*args, out=out, **kwargs)
ivy/func_wrapper.py:439: in _inputs_to_native_arrays
    return fn(*new_args, **new_kwargs)
ivy/func_wrapper.py:545: in _outputs_to_ivy_arrays
    ret = fn(*args, **kwargs)
ivy/functional/backends/numpy/experimental/layers.py:793: in dropout2d
    x = np.transpose(x, perm)
/home/codespace/.local/lib/python3.10/site-packages/numpy/core/fromnumeric.py:668: in transpose
    return _wrapfunc(a, 'transpose', axes)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

obj = array([[0.]], dtype=float32), method = 'transpose', args = ((1, 2, 0),), kwds = {}, bound = <built-in method transpose of numpy.ndarray object at 0x7fd805ba83f0>

    def _wrapfunc(obj, method, *args, **kwds):
        bound = getattr(obj, method, None)
        if bound is None:
            return _wrapit(obj, method, *args, **kwds)
    
        try:
>           return bound(*args, **kwds)
E           ValueError: axes don't match array

/home/codespace/.local/lib/python3.10/site-packages/numpy/core/fromnumeric.py:57: ValueError

During handling of the above exception, another exception occurred:

    @handle_frontend_test(
>       fn_tree="torch.nn.functional.dropout2d",
        dtype_and_x=helpers.dtype_and_values(
            available_dtypes=helpers.get_dtypes("float"),
            min_value=0,
            max_value=50,
            allow_inf=False,
            min_num_dims=2,
            max_num_dims=4,
            min_dim_size=1
        ),
        prob=helpers.floats(min_value=0, max_value=0.9),
        training=st.booleans(),
        test_with_out=st.just(False),
        test_inplace=st.just(False),
    )

ivy_tests/test_ivy/test_frontends/test_torch/test_dropout_functions.py:56: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ivy_tests/test_ivy/test_frontends/test_torch/test_dropout_functions.py:82: in test_torch_dropout2d
    ret = helpers.test_frontend_function(
ivy_tests/test_ivy/helpers/function_testing.py:608: in test_frontend_function
    ret = get_frontend_ret(
ivy_tests/test_ivy/helpers/function_testing.py:1774: in get_frontend_ret
    ret = frontend_fn(*args, **kwargs)
ivy/functional/frontends/torch/func_wrapper.py:87: in outputs_to_frontend_arrays_torch
    ret = fn(*args, **kwargs)
ivy/functional/frontends/torch/func_wrapper.py:58: in _inputs_to_ivy_arrays_torch
    return fn(*new_args, **new_kwargs)
ivy/functional/frontends/torch/nn/functional/dropout_functions.py:24: in dropout2d
    ret = ivy.dropout2d(input, p, training=training, data_format="NCHW")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

args = (ivy.array([[0.]]), 0.5), kwargs = {'data_format': 'NCHW', 'training': True}

    @functools.wraps(fn)
    def _handle_exceptions(*args, **kwargs):
        """
        Catch all exceptions and raise them in IvyException.
    
        Parameters
        ----------
        args
            The arguments to be passed to the function.
    
        kwargs
            The keyword arguments to be passed to the function.
    
        Returns
        -------
            The return of the function, or raise IvyException if error is thrown.
        """
        try:
            return fn(*args, **kwargs)
        # Not to rethrow as IvyBackendException
        except IvyNotImplementedException as e:
            raise e
        except IvyError as e:
            _write_traceback_history(buffer)
            raise ivy.utils.exceptions.IvyError(
                fn.__name__, buffer.getvalue() + " " + str(e), include_backend=True
            )
        except IvyBroadcastShapeError as e:
            _write_traceback_history(buffer)
            raise ivy.utils.exceptions.IvyBroadcastShapeError(
                fn.__name__, buffer.getvalue() + " " + str(e), include_backend=True
            )
        except IvyDtypePromotionError as e:
            _write_traceback_history(buffer)
            raise ivy.utils.exceptions.IvyDtypePromotionError(
                fn.__name__, buffer.getvalue() + " " + str(e), include_backend=True
            )
        except (IndexError, IvyIndexError) as e:
            _write_traceback_history(buffer)
            raise ivy.utils.exceptions.IvyIndexError(
                fn.__name__, buffer.getvalue() + " " + str(e), include_backend=True
            )
        except (AttributeError, IvyAttributeError) as e:
            _write_traceback_history(buffer)
            raise ivy.utils.exceptions.IvyAttributeError(
                fn.__name__, buffer.getvalue() + " " + str(e), include_backend=True
            )
        except (ValueError, IvyValueError) as e:
            _write_traceback_history(buffer)
>           raise ivy.utils.exceptions.IvyValueError(
                fn.__name__, buffer.getvalue() + " " + str(e), include_backend=True
            )
E           ivy.utils.exceptions.IvyValueError: numpy: dropout2d:   File "/workspaces/ivy/ivy/utils/exceptions.py", line 210, in _handle_exceptions
E               return fn(*args, **kwargs)
E             File "/workspaces/ivy/ivy/func_wrapper.py", line 971, in _handle_nestable
E               return fn(*args, **kwargs)
E             File "/workspaces/ivy/ivy/func_wrapper.py", line 399, in _handle_array_like_without_promotion
E               return fn(*args, **kwargs)
E             File "/workspaces/ivy/ivy/func_wrapper.py", line 863, in _handle_out_argument
E               return fn(*args, out=out, **kwargs)
E             File "/workspaces/ivy/ivy/func_wrapper.py", line 439, in _inputs_to_native_arrays
E               return fn(*new_args, **new_kwargs)
E             File "/workspaces/ivy/ivy/func_wrapper.py", line 545, in _outputs_to_ivy_arrays
E               ret = fn(*args, **kwargs)
E             File "/workspaces/ivy/ivy/functional/backends/numpy/experimental/layers.py", line 793, in dropout2d
E               x = np.transpose(x, perm)
E             File "<__array_function__ internals>", line 200, in transpose
E             File "/home/codespace/.local/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 668, in transpose
E               return _wrapfunc(a, 'transpose', axes)
E             File "/home/codespace/.local/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc
E               return bound(*args, **kwds)
E           During the handling of the above exception, another exception occurred:
E            axes don't match array
E           Falsifying example: test_torch_dropout2d(
E               on_device='cpu',
E               frontend='torch',
E               dtype_and_x=(['float32'], [array([[0.]], dtype=float32)]),
E               prob=0.5,
E               training=True,
E               fn_tree='ivy.functional.frontends.torch.nn.functional.dropout2d',
E               test_flags=FrontendFunctionTestFlags(
E                   num_positional_args=0,
E                   with_out=False,
E                   inplace=False,
E                   as_variable=[False],
E                   native_arrays=[False],
E                   generate_frontend_arrays=False,
E               ),
E           )
E           
E           You can reproduce this example by temporarily adding @reproduce_failure('6.79.2', b'AXicY2BkYAAidHAASoOlAAosAMQ=') as a decorator on your test case

ivy/utils/exceptions.py:241: IvyValueError
===================================================================================== short test summary info =====================================================================================
FAILED ivy_tests/test_ivy/test_frontends/test_torch/test_dropout_functions.py::test_torch_dropout2d[cpu-ivy.functional.backends.numpy-False-False] - ivy.utils.exceptions.IvyValueError: numpy: dropout2d:   File "/workspaces/ivy/ivy/utils/exceptions.py", line 210, in _handle_exceptions
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================================================================================== 1 failed in 4.89s ========================================================================================

Copy link
Contributor

@hmahmood24 hmahmood24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Ali-12122, apologies for being a little late on this. I have requested a change in my review. That should resolve the issue you are facing. Thanks! :)

min_value=0,
max_value=50,
allow_inf=False,
min_num_dims=2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The min_num_dims needs to be 3 since torch supports either NCL or NCHW in the input

@Ali-12122
Copy link
Contributor Author

@hmahmood24 Thank you for your guidance and support, I did make the change you requested, and it passed the test.

@Ali-12122/workspaces/ivy (torch-dropout2d) $ python3 -m pytest -v -x ivy_tests/test_ivy/test_frontends/test_torch/test_dropout_functions.py::test_torch_dropout2d
Use Database in ReadOnly Mode with local caching !
===================================================================== test session starts ======================================================================
platform linux -- Python 3.10.8, pytest-7.4.0, pluggy-1.2.0 -- /home/codespace/.python/current/bin/python3
cachedir: .pytest_cache
hypothesis profile 'ivy_profile' -> max_examples=25, print_blob=True, deadline=timedelta(milliseconds=500000), suppress_health_check=[HealthCheck.too_slow, HealthCheck.filter_too_much, HealthCheck.data_too_large], database=MultiplexedDatabase(DirectoryBasedExampleDatabase('/workspaces/ivy/.hypothesis/examples/'), ReadOnlyDatabase(RedisExampleDatabase(Redis<ConnectionPool<Connection<host=redis-17011.c259.us-central1-2.gce.cloud.redislabs.com,port=17011,db=0>>>, expire_after=datetime.timedelta(days=8))))
backend(s): all
device: cpu
number of Hypothesis examples: 25
rootdir: /workspaces/ivy
plugins: anyio-3.7.0, hypothesis-6.79.2
collected 2 items                                                                                                                                              

ivy_tests/test_ivy/test_frontends/test_torch/test_dropout_functions.py::test_torch_dropout2d[cpu-ivy.functional.backends.numpy-False-False] PASSED       [ 50%]
ivy_tests/test_ivy/test_frontends/test_torch/test_dropout_functions.py::test_torch_dropout2d[cpu-ivy.functional.backends.torch-False-False] PASSED       [100%]

======================================================================= warnings summary =======================================================================
ivy_tests/test_ivy/test_frontends/test_torch/test_dropout_functions.py: 42 warnings
  /home/codespace/.local/lib/python3.10/site-packages/torch/nn/functional.py:1338: UserWarning: dropout2d: Received a 3D input to dropout2d and assuming that channel-wise 1D dropout behavior is desired - input is interpreted as shape (N, C, L), where C is the channel dim. This behavior will change in a future release to interpret the input as one without a batch dimension, i.e. shape (C, H, W). To maintain the 1D channel-wise dropout behavior, please switch to using dropout1d instead.
    warnings.warn("dropout2d: Received a 3D input to dropout2d and assuming that channel-wise "

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================ 2 passed, 42 warnings in 4.99s ================================================================

Should I do anything regarding these warnings?

@hmahmood24
Copy link
Contributor

Hey @Ali-12122 I think everything looks good now to merge! Thanks a lot for the PR and apologies for any inconveniences :) Cheers!

@hmahmood24 hmahmood24 merged commit c58240c into Transpile-AI:master Jul 8, 2023
126 of 132 checks passed
@Ali-12122
Copy link
Contributor Author

@hmahmood24 Thanks for everything and thanks for being an amazing guide and support, Cheers to you as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PyTorch Frontend Developing the PyTorch Frontend, checklist triggered by commenting add_frontend_checklist
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dropout2d
3 participants