-
Notifications
You must be signed in to change notification settings - Fork 217
Add approximate parameter to GELU activation function #1548
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2977,15 +2977,31 @@ public Tensor elu_(Scalar alpha, Scalar scale, Scalar input_scale) | |
|
|
||
| public Tensor gelu() | ||
| { | ||
| var res = NativeMethods.THSTensor_gelu(Handle); | ||
| var res = NativeMethods.THSTensor_gelu(Handle, "none"); | ||
| if (res == IntPtr.Zero) | ||
| CheckForErrors(); | ||
| return new Tensor(res); | ||
| } | ||
|
|
||
| public Tensor gelu(TorchSharp.Modules.GELU.Approximate approximate) | ||
| { | ||
| var res = NativeMethods.THSTensor_gelu(Handle, approximate == TorchSharp.Modules.GELU.Approximate.tanh ? "tanh" : "none"); | ||
| if (res == IntPtr.Zero) | ||
| CheckForErrors(); | ||
| return new Tensor(res); | ||
| } | ||
|
|
||
| public Tensor gelu_() | ||
| { | ||
| var res = NativeMethods.THSTensor_gelu_(Handle); | ||
| var res = NativeMethods.THSTensor_gelu_(Handle, "none"); | ||
| if (res == IntPtr.Zero) | ||
| CheckForErrors(); | ||
| return new Tensor(res); | ||
| } | ||
|
|
||
| public Tensor gelu_(TorchSharp.Modules.GELU.Approximate approximate) | ||
| { | ||
| var res = NativeMethods.THSTensor_gelu_(Handle, approximate == TorchSharp.Modules.GELU.Approximate.tanh ? "tanh" : "none"); | ||
|
Comment on lines
+2986
to
+3004
|
||
| if (res == IntPtr.Zero) | ||
| CheckForErrors(); | ||
| return new Tensor(res); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new P/Invoke declarations for THSTensor_gelu/THSTensor_gelu_ introduce an LPStr string parameter but don’t specify CharSet/BestFitMapping/ThrowOnUnmappableChar like the other LPStr-based imports in this file (e.g., THSTensor_load/meshgrid/div). This can lead to inconsistent marshaling behavior across platforms and re-enables best-fit character mapping. Consider updating these DllImport attributes to match the existing pattern used for other string parameters in LibTorchSharp.THSTensor.cs.