Trait burn_core::tensor::ops::ActivationOps

source ·
pub trait ActivationOps<B>
where B: Backend,
{ // Provided methods fn leaky_relu<const D: usize>( tensor: <B as Backend>::FloatTensorPrimitive<D>, negative_slope: <B as Backend>::FloatElem ) -> <B as Backend>::FloatTensorPrimitive<D> { ... } fn relu<const D: usize>( tensor: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D> { ... } fn relu_backward<const D: usize>( output: <B as Backend>::FloatTensorPrimitive<D>, grad: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D> { ... } fn gelu<const D: usize>( tensor: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D> { ... } fn prelu<const D: usize>( tensor: <B as Backend>::FloatTensorPrimitive<D>, alpha: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D> { ... } fn gelu_backward<const D: usize>( x: <B as Backend>::FloatTensorPrimitive<D>, grad: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D> { ... } fn sigmoid<const D: usize>( tensor: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D> { ... } fn sigmoid_backward<const D: usize>( output: <B as Backend>::FloatTensorPrimitive<D>, grad: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D> { ... } fn log_sigmoid<const D: usize>( tensor: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D> { ... } fn log_sigmoid_backward<const D: usize>( x: <B as Backend>::FloatTensorPrimitive<D>, grad: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D> { ... } }
Expand description

Activation function operations.

This trait let backend implementations override activation functions for better performance.

Provided Methods§

source

fn leaky_relu<const D: usize>( tensor: <B as Backend>::FloatTensorPrimitive<D>, negative_slope: <B as Backend>::FloatElem ) -> <B as Backend>::FloatTensorPrimitive<D>

Applies the LeakyReLU activation function.

§Arguments
  • tensor - The tensor.
  • negative_slope - The negative_slope value that values smaller than 0 are multiplied with.
§Returns

The output tensor.

source

fn relu<const D: usize>( tensor: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D>

Applies the ReLU activation function.

§Arguments
  • tensor - The tensor.
§Returns

The output tensor.

source

fn relu_backward<const D: usize>( output: <B as Backend>::FloatTensorPrimitive<D>, grad: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D>

Applies the ReLU activation function backward.

§Arguments
  • output - The output tensor.
§Returns

The gradient.

source

fn gelu<const D: usize>( tensor: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D>

Applies the Gelu activation function.

§Arguments
  • tensor - The tensor.
§Returns

The output tensor.

source

fn prelu<const D: usize>( tensor: <B as Backend>::FloatTensorPrimitive<D>, alpha: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D>

Applies the PReLu activation function.

§Arguments
  • tensor - The input tensor
  • alpha - The weight tensor
source

fn gelu_backward<const D: usize>( x: <B as Backend>::FloatTensorPrimitive<D>, grad: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D>

Applies the Gelu activation function backward.

§Arguments
  • x - The tensor.
  • grad - The gradient.
§Returns

The output tensor.

source

fn sigmoid<const D: usize>( tensor: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D>

Applies the Sigmoid activation function.

§Arguments
  • tensor - The tensor.
§Returns

The output tensor.

source

fn sigmoid_backward<const D: usize>( output: <B as Backend>::FloatTensorPrimitive<D>, grad: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D>

Applies the Sigmoid activation function backward.

§Arguments
  • output - The output tensor of the sigmoid function.
  • grad - The gradient.
§Returns

The output tensor.

source

fn log_sigmoid<const D: usize>( tensor: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D>

Applies the LogSigmoid activation function.

§Arguments
  • tensor - The tensor.
§Returns

The output tensor.

source

fn log_sigmoid_backward<const D: usize>( x: <B as Backend>::FloatTensorPrimitive<D>, grad: <B as Backend>::FloatTensorPrimitive<D> ) -> <B as Backend>::FloatTensorPrimitive<D>

Applies the LogSigmoid activation function backward.

§Arguments
  • x - The input tensor.
  • grad - The gradient.
§Returns

The output gradient.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<B> ActivationOps<Fusion<B>> for Fusion<B>
where B: FusionBackend,

source§

impl<R> ActivationOps<JitBackend<R>> for JitBackend<R>
where R: Runtime,

Implementors§

source§

impl<B, C> ActivationOps<Autodiff<B, C>> for Autodiff<B, C>

source§

impl<E> ActivationOps<LibTorch<E>> for LibTorch<E>
where E: TchElement,

source§

impl<E> ActivationOps<NdArray<E>> for NdArray<E>

source§

impl<F, I> ActivationOps<Candle<F, I>> for Candle<F, I>
where F: FloatCandleElement, I: IntCandleElement,