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

Torch frontend lerp #10690

Merged
merged 9 commits into from
Feb 22, 2023
Merged

Torch frontend lerp #10690

merged 9 commits into from
Feb 22, 2023

Conversation

aparna2071
Copy link
Contributor

Closes #10683

@ivy-leaves ivy-leaves added the PyTorch Frontend Developing the PyTorch Frontend, checklist triggered by commenting add_frontend_checklist label Feb 20, 2023
Copy link
Contributor

@fspyridakos fspyridakos left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! I left a few comments please go over them and ask for another review once you're done.


@to_ivy_arrays_and_back
def lerp(start, end, weight):
return ivy.lerp(start, end, weight)
Copy link
Contributor

Choose a reason for hiding this comment

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

ivy.lerp doesn't exist in the ivy API, you can suggest its addition by following the steps here: https://lets-unify.ai/ivy/deep_dive/ivy_frontends.html#missing-ivy-functions.
That being said the function can simply composed by a few arithmetic operations as described here: https://pytorch.org/docs/stable/generated/torch.lerp.html.
Also please add the out argument

Comment on lines 9 to 11
import torch
from torch.testing import assert_allclose

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove these imports



@to_ivy_arrays_and_back
def lerp(start, end, weight):
Copy link
Contributor

Choose a reason for hiding this comment

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

The first argument should be input as stated in the torch docs: https://pytorch.org/docs/stable/generated/torch.lerp.html

Comment on lines 2108 to 2111
expected_output = torch.lerp(start, end, weight)
output = frontend.torch.lerp(start, end, weight)

assert_allclose(expected_output, output, rtol=1e-03, atol=1e-05)
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to do this here, test_frontend_fuction handles this

Comment on lines 2118 to 2119
input=(start, end, weight),
expected_output=expected_output,
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 pack all input arguments into one, make them seperate keyword args, i.e. input=start, end=end, weight=weight.
Remove expected_output
No need to include the out argument when you add it

@aparna2071
Copy link
Contributor Author

Thank you so much for your detailed review, will help me a lot.
I will make the necessary changes as soon as possible.

@aparna2071
Copy link
Contributor Author

Hi @fspyridakos, as far as the addition of ivy.lerp function is concerned, I've raised a new issue #10762.
Other than that, I've tried to make all necessary changes as suggested by you.
Kindly review & please feel free to suggest if any more changes are required.
Also, thanks a lot for detailed suggestions.

Copy link
Contributor

@fspyridakos fspyridakos left a comment

Choose a reason for hiding this comment

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

Thanks for the changes! Also your ivy.lerp issue mentions the .interp function in jax and numpy, and ivy.interp already exists, if you think you can use that function here go ahead, but I think lerp and interp do different things, just chaning some elementwise functions is fine for now

Comment on lines 457 to 459
if out is None:
out = ivy.zeros_like(input)
out = ivy.multiply_add(ivy.subtract(end, input), weight, ivy.subtract(input, out), out=out)
Copy link
Contributor

Choose a reason for hiding this comment

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

most lines are redundant, you can just do return <operation> as with the above functions (out in the docs practically means the return) also look over your implementation, ivy.multiply_add doesn't exist

fn_tree="torch.lerp",
dtype_and_input=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
default=0.5,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what default is here, but you should probably use num_arrays=3

Comment on lines 2102 to 2113
input_dtype, inputs = dtype_and_input
start, end, weight = inputs
helpers.test_frontend_function(
input_dtypes=input_dtype,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
input_start=start,
input_end=end,
input_weight=weight,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

fix indentation here to match functions above

@aparna2071
Copy link
Contributor Author

Hi @fspyridakos, once again thanks a lot.
As far as ivy.lerp issue is concerned, I've deleted the links for interp & have tried to make all necessary changes as required for this PR.
Kindly review & please let me know if any more changes are required.

Copy link
Contributor

@fspyridakos fspyridakos left a comment

Choose a reason for hiding this comment

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

Few more chnages and you're golden

@@ -450,3 +450,9 @@ def hypot(input, other, *, out=None):
@to_ivy_arrays_and_back
def sigmoid(input, *, out=None):
return ivy.sigmoid(input, out=out)


@to_ivy_arrays_and_back
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add float16 and bfloat16 as unsupprted dtypes for torch (like other functions above)

fn_tree="torch.lerp",
dtype_and_input=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
num_arrays=3,
Copy link
Contributor

Choose a reason for hiding this comment

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

Add the following:
large_abs_safety_factor=2.5, small_abs_safety_factor=2.5, safety_factor_scale="log",
Some large values will not interpolate properly due to float percision limitations, this prevents those from being generated

Comment on lines 2110 to 2112
input_start=start,
input_end=end,
input_weight=weight,
Copy link
Contributor

Choose a reason for hiding this comment

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

just have this be input=start, end=end and so on, the kwargs must have the same names as the function args

@aparna2071
Copy link
Contributor Author

Hi @fspyridakos, thanks for all your help.
I've made the changes, please let me know if anything else is required.

@fspyridakos
Copy link
Contributor

fspyridakos commented Feb 22, 2023

LGTM, had to make 2 small changes but it's good now and the test passes. Thanks again for your contribution!

@fspyridakos fspyridakos merged commit b8151bf into ivy-llc:master Feb 22, 2023
@aparna2071
Copy link
Contributor Author

Thanks a lot for merging @fspyridakos.

Dsantra92 pushed a commit to Dsantra92/ivy that referenced this pull request Feb 22, 2023
vedpatwardhan pushed a commit to vedpatwardhan/ivy that referenced this pull request Feb 23, 2023
Co-authored-by: Fotios Spyridakos <[email protected]>
vedpatwardhan pushed a commit to vedpatwardhan/ivy that referenced this pull request Feb 23, 2023
Co-authored-by: Fotios Spyridakos <[email protected]>
vedpatwardhan pushed a commit to vedpatwardhan/ivy that referenced this pull request Feb 26, 2023
Co-authored-by: Fotios Spyridakos <[email protected]>
vedpatwardhan pushed a commit to vedpatwardhan/ivy that referenced this pull request Feb 26, 2023
Co-authored-by: Fotios Spyridakos <[email protected]>
@AnnaTz AnnaTz mentioned this pull request Feb 27, 2023
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.

lerp
3 participants