ivy icon indicating copy to clipboard operation
ivy copied to clipboard

fix ivy.dropout returning native arrays/tensors

Open Sam-Armstrong opened this issue 1 year ago • 1 comments

Fixes problem where ivy.dropout can return things like tf.EagerTensor instead of ivy.Array.

Min example:

import ivy

if __name__ == '__main__':
    ivy.set_backend("tensorflow")

    x = ivy.random_normal(shape=(5, 5, 5))
    x = ivy.dropout(x, 0.1)
    print(type(x))
    x = x.reshape((25, 5))

Sam-Armstrong avatar Jun 21 '23 17:06 Sam-Armstrong

If you are working on an open task, please edit the PR description to link to the issue you've created.

For more information, please check ToDo List Issues Guide.

Thank you :hugs:

ivy-leaves avatar Jun 21 '23 17:06 ivy-leaves

Why was it returning native arrays? It is a composition of ivy functions so this shouldn't be happening 🤔

AnnaTz avatar Jun 22 '23 08:06 AnnaTz

@AnnaTz I've honestly got no idea what the problem is here, all the inner ivy functions seem to be working fine and when I create an identical sample dropout function in a test script it also returns ivy arrays rather than native. So I guess there must be some other problem within ivy that's causing this, but I'm no expert on what it could be 😅. What do you think we should do here? This solution does solve the problem ^

Sam-Armstrong avatar Jun 22 '23 11:06 Sam-Armstrong

@AnnaTz I've honestly got no idea what the problem is here, all the inner ivy functions seem to be working fine and when I create an identical sample dropout function in a test script it also returns ivy arrays rather than native. So I guess there must be some other problem within ivy that's causing this, but I'm no expert on what it could be 😅. What do you think we should do here? This solution does solve the problem ^

I think I figured it out. dropout is a mixed function so it should have amixed_backend_wrappers attribute to define its decorators as in interpolate for example.

AnnaTz avatar Jun 22 '23 12:06 AnnaTz

@AnnaTz Ah yes, looks like that solved it. Nice spot! Have updated this PR

Sam-Armstrong avatar Jun 22 '23 12:06 Sam-Armstrong