Add the relu2 and relu6 activations. (#1201)

This commit is contained in:
Laurent Mazare
2023-10-27 21:51:16 +02:00
committed by GitHub
parent 85bea43e5b
commit c8face3f95
3 changed files with 61 additions and 0 deletions

View File

@ -9,6 +9,8 @@ pub enum Activation {
#[serde(rename = "gated-gelu")]
NewGelu,
Relu,
Relu2,
Relu6,
Silu,
Sigmoid,
Elu(f64),
@ -22,6 +24,8 @@ impl super::Module for Activation {
// https://github.com/huggingface/transformers/blob/12f043eaeaabfef6f6efea411d98e6f6d3c094b7/src/transformers/activations.py#L49-L78
Self::NewGelu => xs.gelu(),
Self::Relu => xs.relu(),
Self::Relu2 => xs.relu()?.sqr(),
Self::Relu6 => xs.clamp(0f32, 6f32),
Self::Silu => crate::ops::silu(xs),
Self::Sigmoid => crate::ops::sigmoid(xs),
&Self::Elu(alpha) => xs.elu(alpha),