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

Adding GeLU operator (used in Gpt2) #397

Merged
merged 5 commits into from
Jan 25, 2023

Conversation

Narsil
Copy link
Contributor

@Narsil Narsil commented Jan 24, 2023

  • Added the operations as found here:

https://github.com/pytorch/pytorch/blob/acdd462b1a070790799ce4623ce8ecc83e197e81/torch/_decomp/decompositions.py#L217
https://github.com/pytorch/pytorch/blob/acdd462b1a070790799ce4623ce8ecc83e197e81/caffe2/operators/gelu_op.cu#L84
https://pytorch.org/docs/stable/generated/torch.nn.GELU.html

  • Added both cuda and cpu versions.
  • Added a simplify helper method, because the results are slightly
    different between cuda and cpu (this is relatively common IMO).

@coreylowman coreylowman linked an issue Jan 24, 2023 that may be closed by this pull request
Copy link
Owner

@coreylowman coreylowman left a comment

Choose a reason for hiding this comment

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

Looks great! Small nits and then good to go. We can use this PR as a model for how to contribute new unary ops 🔥

src/tensor_ops/gelu/cpu_kernel.rs Outdated Show resolved Hide resolved
let x = dev.tensor([-2.0, -1.0, 0.0, 1.0, 2.0]);
let r = x.trace().gelu();
assert_eq!(
simplify(&r.array()),
Copy link
Owner

Choose a reason for hiding this comment

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

Yeah definitely seen slightly different results between cpu/cuda. Can you use crate::tests::assert_close() that some of the other tests use? This checks equality within a certain tolerance

Copy link
Owner

Choose a reason for hiding this comment

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

Ahh yeah looks like there's small failure in github actions, I think moving to assert_close should resolve that (probably don't need simplify)

@Narsil
Copy link
Contributor Author

Narsil commented Jan 25, 2023

The last failing test is the example I think, were I cannot use assert_close (afaik).

Should assert_close be opened ? Or maybe relax the assertion in a simple print statement ?

Narsil and others added 2 commits January 25, 2023 08:57
Co-authored-by: Corey Lowman <coreylowman@users.noreply.github.com>
@Narsil
Copy link
Contributor Author

Narsil commented Jan 25, 2023

Why was the last test cancelled ??

@coreylowman
Copy link
Owner

Why was the last test cancelled ??

No idea, but the rest of them passed so looks good to me!

@coreylowman
Copy link
Owner

The last failing test is the example I think, were I cannot use assert_close (afaik).

Should assert_close be opened ? Or maybe relax the assertion in a simple print statement ?

Ah yeah, for doctests you don't need to call any assertions about data, they are more about just showing usage. You can just remove those lines

Copy link
Owner

@coreylowman coreylowman left a comment

Choose a reason for hiding this comment

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

Looks great from my end!

src/tensor_ops/gelu/mod.rs Outdated Show resolved Hide resolved
Co-authored-by: Corey Lowman <coreylowman@users.noreply.github.com>
@Narsil
Copy link
Contributor Author

Narsil commented Jan 25, 2023

I'll let you merge in then ;) cheers !

@coreylowman coreylowman merged commit a1eab9b into coreylowman:main Jan 25, 2023
@coreylowman
Copy link
Owner

Nice contribution!

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.

Add tensor_ops::gelu and nn::GELU
2 participants