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

Accurate gelu cuda fix #830

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9e140be
accurate-gelu
jcrist1 Jul 6, 2023
04eb169
accurate-gelu - make it actually available
jcrist1 Jul 13, 2023
cb8a99c
accurate-gelu - trying to tweak cuda kernel
jcrist1 Jul 13, 2023
b42b5e3
accurate-gelu - rename
jcrist1 Jul 13, 2023
8fbf249
accurate-gelu - more documentation, fix tests
jcrist1 Jul 14, 2023
d201f4a
accurate-gelu - describe corresponding pytorch algos for gelus
jcrist1 Jul 14, 2023
4e11335
accurate-gelu - rename gelu -> fast_gelu + bwd compat and deprecation…
jcrist1 Jul 15, 2023
f30a37f
accurate-gelu - correct cuda struct name
jcrist1 Jul 15, 2023
858d176
accurate-gelu - GuLU -> GeLU X-D
jcrist1 Jul 15, 2023
360c381
accurate-gelu - create backwards compatibility `gelu(t)` function
jcrist1 Jul 15, 2023
9fd8685
accurate-gelu - mark backwards compatible gelu import as allow(deprec…
jcrist1 Jul 15, 2023
9f3c7bb
accurate-gelu - fix backwards-compatibility for GeLU, rename test to …
jcrist1 Jul 15, 2023
03b5397
accurate-gelu - added doc links
jcrist1 Jul 17, 2023
2c2b3d9
accurat-gelu - last link
jcrist1 Jul 17, 2023
d00d2df
accurate-gelu - correct method links
jcrist1 Jul 17, 2023
284288e
accurate-gelu-cuda-fix - fix for failing cuda build
jcrist1 Jul 25, 2023
9d5d5df
test tweak
jcrist1 Jul 25, 2023
cdafd71
fix println debug
jcrist1 Jul 25, 2023
559ff2d
fix derivative
jcrist1 Jul 25, 2023
896aa80
remove copied code
jcrist1 Jul 25, 2023
cc966d9
Remove println debug
jcrist1 Jul 25, 2023
6adffdb
Merge remote-tracking branch 'origin/main' into accurate-gelu-cuda-fix
jcrist1 Jul 25, 2023
e7ebf8e
reformat
jcrist1 Jul 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions src/tensor_ops/accurate_gelu/accurate_gelu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,26 @@ template <typename T> __device__ T accurate_gelu_bwd(T x) {
T one = 1.0;
T half = 0.5;
T alpha = M_SQRT1_2;
T scale = M_2_SQRTPI;
T x_sq = x * x;
T beta = M_2_SQRTPI;
T normal_dist = beta * expg(half * -x_sq);
T arg = -half * x_sq;
T norm = scale * expg(arg);

T left = half * x;
T right = one + erfg(alpha * x);

T left_derivative = half * right;

T right_derivative = left * normal_dist;
T right_derivative = left * norm;

return left_derivative + right_derivative;
}

UNARY_OP(__half, accurate_gelu_fwd_f16, accurate_gelu_bwd_f16,
AccurateGeLUKernelOp,
accurate_gelu_fwd(x),
accurate_gelu_bwd(x)
)
AccurateGeLUKernelOp, accurate_gelu_fwd(x), accurate_gelu_bwd(x))

UNARY_OP(float, accurate_gelu_fwd_f32, accurate_gelu_bwd_f32,
AccurateGeLUKernelOp,
accurate_gelu_fwd(x),
accurate_gelu_bwd(x)
)
AccurateGeLUKernelOp, accurate_gelu_fwd(x), accurate_gelu_bwd(x))

UNARY_OP(double, accurate_gelu_fwd_f64, accurate_gelu_bwd_f64,
AccurateGeLUKernelOp,
accurate_gelu_fwd(x),
accurate_gelu_bwd(x)
)
AccurateGeLUKernelOp, accurate_gelu_fwd(x), accurate_gelu_bwd(x))
3 changes: 3 additions & 0 deletions src/tensor_ops/utilities/cuda_utils.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ __device__ __forceinline__ __half logg(__half a) { return hlog(a); }
__device__ __forceinline__ float expg(float a) { return expf(a); }
__device__ __forceinline__ double expg(double a) { return exp(a); }
__device__ __forceinline__ __half expg(__half a) { return hexp(a); }
__device__ __forceinline__ float erfg(float a) { return erff(a); }
__device__ __forceinline__ double erfg(double a) { return erf(a); }
__device__ __forceinline__ __half erfg(__half a) { return erff(float(a)); }
__device__ __forceinline__ float absg(float a) { return fabsf(a); }
__device__ __forceinline__ double absg(double a) { return fabs(a); }
__device__ __forceinline__ __half absg(__half a) { return __habs(a); }
Expand Down
Loading