Skip to content

Commit

Permalink
accurate-gelu - added doc links
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist1 committed Jul 17, 2023
1 parent 9f3c7bb commit 03b5397
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/nn/activations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ activation_impls!(Abs, try_abs, #[doc="Calls [abs()]."]);
activation_impls!(Softmax, try_softmax, #[doc="Calls [softmax()]."]);
activation_impls!(LogSoftmax, try_log_softmax, #[doc="Calls [log_softmax()]."]);

/// Use [FastGeLU] instead
#[deprecated(since = "0.12.0", note = "please use `FastGeLU` instead")]
#[derive(Default, Debug, Clone, Copy)]
pub struct GeLU;
Expand Down
2 changes: 1 addition & 1 deletion src/tensor_ops/accurate_gelu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct AccurateGeLUKernelOp;
/// GeLU(x) ~ 0.5 ∗ x ∗ (1.0 + tanh((sqrt(2.0/π) ∗ (x + 0.044715 ∗ x^3)))
/// ```
///
/// See [gelu](crate::tensor_ops::gelu::gelu) to use this approximation
/// See [fast_gelu](super::fast_gelu::fast_gelu) to use this approximation
///
///
/// Examples:
Expand Down
16 changes: 12 additions & 4 deletions src/tensor_ops/fast_gelu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ pub type GeLUKernelOp = FastGeLUKernelOp;
#[derive(Debug, Default, Copy, Clone)]
pub struct FastGeLUKernelOp;

/// [Fast Gaussian Linear Unit (GeLU)](https://paperswithcode.com/method/gelu). `0.5 * x * (1 + tanh(sqrt(2 / pi) * (x + 0.044715 * x^3)))`
/// [Fast Gaussian Linear Unit (GeLU)](https://paperswithcode.com/method/gelu). A fast version of the gaussiane linear unit
/// calculated by
/// ```text
/// 0.5 * x * (1 + tanh(sqrt(2 / pi) * (x + 0.044715 * x^3)))
/// ````
/// See also [accurate_gelu](super::accurate_gelu::accurate_gelu) for the more accurate version.
///
/// Examples:
/// ```rust
Expand All @@ -29,6 +34,7 @@ pub fn fast_gelu<S: Shape, E: Dtype, D: UnaryKernel<FastGeLUKernelOp, E>, T: Tap
t.fast_gelu()
}

/// Use [fast_gelu] instead
#[deprecated(since = "0.12.0", note = "Use `fast_gelu` instead")]
pub fn gelu<S: Shape, E: Dtype, D: UnaryKernel<FastGeLUKernelOp, E>, T: Tape<E, D>>(
t: Tensor<S, E, D, T>,
Expand All @@ -37,20 +43,22 @@ pub fn gelu<S: Shape, E: Dtype, D: UnaryKernel<FastGeLUKernelOp, E>, T: Tape<E,
}

impl<S: Shape, E: Dtype, D: UnaryKernel<FastGeLUKernelOp, E>, T: Tape<E, D>> Tensor<S, E, D, T> {
/// See [gelu]
/// See [fast_gelu]
pub fn fast_gelu(self) -> Self {
self.try_fast_gelu().unwrap()
}
/// See [gelu]
/// See [fast_gelu]
pub fn try_fast_gelu(self) -> Result<Self, D::Err> {
try_unary_op(FastGeLUKernelOp, self)
}

#[deprecated(since = "0.12.0", note = "Use `fast_gelu` instead")]
/// Use [fast_gelu] instead
#[deprecated(since = "0.12.0", note = "Use [fast_gelu](#method.fast_gelu) instead")]
pub fn gelu(self) -> Self {
self.fast_gelu()
}

/// Use [try_fast_gelu] instead

Check warning on line 61 in src/tensor_ops/fast_gelu/mod.rs

View workflow job for this annotation

GitHub Actions / cargo-check

unresolved link to `try_fast_gelu`
#[deprecated(since = "0.12.0", note = "Use `try_fast_gelu` instead")]
pub fn try_gelu(self) -> Result<Self, D::Err> {
self.try_fast_gelu()
Expand Down

0 comments on commit 03b5397

Please sign in to comment.