Skip to main content

tract_core/ops/nn/
mod.rs

1mod data_formats;
2pub mod gelu_approximate;
3pub mod gelu_exact;
4pub mod grid_sample;
5mod reduce;
6pub mod resize;
7pub mod rms_norm;
8pub mod silu;
9mod softmax;
10
11pub use self::data_formats::{BaseDataShape, DataFormat, DataShape, SymDataShape};
12pub use self::gelu_approximate::GeluApproximate;
13pub use self::gelu_exact::GeluExact;
14pub use self::grid_sample::{GridSample, InterpolationMode, PaddingMode};
15pub use self::reduce::{Reduce, Reducer, expand_mean_of_squares};
16pub use self::resize::{CoordTransformer, Interpolator, Nearest, Resize};
17pub use self::rms_norm::RmsNorm;
18pub use self::silu::Silu;
19pub use self::softmax::{Softmax, SoftmaxKind};
20
21pub use crate::internal::*;
22
23use tract_linalg::routines::Func;
24use tract_num_traits::AsPrimitive;
25
26element_wise!(sigmoid, Sigmoid,
27 [f16] => |_, xs| { Func::Sigmoid.ew_f16()?.run(xs) },
28 [f32] => |_, xs| { Func::Sigmoid.ew_f32()?.run(xs) };
29 q: [i8, u8, i32, i32] => |x: f32| 1.0 / (1.0+(-x).exp());
30 cost: |dt| {tvec!((Cost::FMA(dt), 11), (Cost::Div(dt), 1))};
31 declutter: silu::detect_silu
32);
33
34element_wise!(hard_swish, HardSwish,
35[f16] => |_, xs| { xs.iter_mut().for_each(|x| *x = *x * f16::from_f32(0.0).max(f16::from_f32(1.0).min(f16::from_f32(1. / 6.) * *x + f16::from_f32(0.5)))); Ok(()) },
36[f32] => |_, xs| { Func::Hardswish.ew_f32()?.run(xs) }
37                                         );
38
39element_wise!(leaky_relu, LeakyRelu { alpha: f32 },
40 [f16] => |op, xs| { Func::LeakyRelu.ew_f16_param()?.run_with_params(xs, f16::from_f32(op.alpha)) },
41 [f32] => |op, xs| { Func::LeakyRelu.ew_f32_param()?.run_with_params(xs, op.alpha) }
42);