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

Enable the function linalg_vector_norm #759

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ramon-garcia
Copy link

This pull request is to enable the function linalg_vector_norm, disable in the original code.

I need it to compute the L2 norm of matrices and vectors.

It looks like it was disabled because of compile errors, caused by the removal of the parameter ord in the code generator, because it had a default value. After removing the default_value attribute in Declarations-v2.0.0.yaml, the code is correctly generated.

Of course, there are better solutions, but I wasn't able to make changes in the Ocaml code in gen/gen.ml.

Thank you for your time.

@ramon-garcia
Copy link
Author

ping

@LaurentMazare
Copy link
Owner

Sorry for the delayed answer, making changes to the Definitions.yaml file would be a bit tricky to maintain when upgrading to new torch versions. If your goal is to compute the l2 norm, maybe you can use mse_loss or compute it directly via something like x.pow_tensor_scalar(2).sum(Kind::float).sqrt()?

@ramon-garcia
Copy link
Author

ramon-garcia commented Aug 2, 2023

Thanks, I overlooked the fact that the files Declarations*.yaml are autogenerated. I am going to review the patch to change the code generator instead.

Note that in addition of the particular case of generating the norm, one needs the general case of having access to all the Torch API. So that one looks the documentation and finds the solution. Your solution would work for me, thank you.

@LaurentMazare
Copy link
Owner

I would still encourage you to try the manual computations from my previous post if you can, it's certainly easier to get working and should cover all needs of norm computations that I can think of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants