pub struct TensorActivation { /* private fields */ }Expand description
Activation layer with forward/backward support and call statistics.
Implementations§
Source§impl TensorActivation
impl TensorActivation
Sourcepub fn new(config: ActivationConfig) -> Self
pub fn new(config: ActivationConfig) -> Self
Create a new activation layer from the given configuration.
Sourcepub fn gelu(x: f64) -> f64
pub fn gelu(x: f64) -> f64
GELU activation (approximate): 0.5 * x * (1 + tanh(sqrt(2/pi) * (x + 0.044715 * x^3)))
Sourcepub fn softmax(input: &[f64]) -> Vec<f64>
pub fn softmax(input: &[f64]) -> Vec<f64>
Softmax over a slice of values, using the log-sum-exp trick for numerical stability.
Sourcepub fn forward(&mut self, input: &[f64]) -> Vec<f64>
pub fn forward(&mut self, input: &[f64]) -> Vec<f64>
Apply the configured activation element-wise (Softmax across all elements).
Sourcepub fn backward(&mut self, input: &[f64], grad_output: &[f64]) -> Vec<f64>
pub fn backward(&mut self, input: &[f64], grad_output: &[f64]) -> Vec<f64>
Compute the gradient of the loss w.r.t. the activation input.
input– the original pre-activation values.grad_output– the upstream gradient (dL/d(output)).
Returns dL/d(input).
Sourcepub fn stats(&self) -> ActivationStats
pub fn stats(&self) -> ActivationStats
Return runtime statistics.
Auto Trait Implementations§
impl Freeze for TensorActivation
impl RefUnwindSafe for TensorActivation
impl Send for TensorActivation
impl Sync for TensorActivation
impl Unpin for TensorActivation
impl UnsafeUnpin for TensorActivation
impl UnwindSafe for TensorActivation
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more