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::{
17 CoordTransformer, Interpolator, Nearest, NearestUpsample, Resize,
18 rewrite_nearest_upsample_to_broadcast,
19};
20pub use self::rms_norm::{RmsNorm, ScaledRmsNorm};
21pub use self::silu::Silu;
22pub use self::softmax::{Softmax, SoftmaxKind};
23
24pub use crate::internal::*;
25
26use tract_linalg::routines::Func;
27use tract_num_traits::AsPrimitive;
28
29element_wise!(sigmoid, Sigmoid,
30 [f16] => |_, xs| { Func::Sigmoid.ew_f16()?.run(xs) },
31 [f32] => |_, xs| { Func::Sigmoid.ew_f32()?.run(xs) };
32 q: [i8, u8, i32, i32] => |x: f32| 1.0 / (1.0+(-x).exp());
33 cost: |dt| {tvec!((Cost::FMA(dt), 11), (Cost::Div(dt), 1))};
34 declutter: silu::detect_silu
35);
36
37element_wise!(hard_swish, HardSwish,
38[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(()) },
39[f32] => |_, xs| { Func::Hardswish.ew_f32()?.run(xs) }
40 );
41
42element_wise!(leaky_relu, LeakyRelu { alpha: f32 },
43 [f16] => |op, xs| { Func::LeakyRelu.ew_f16_param()?.run_with_params(xs, f16::from_f32(op.alpha)) },
44 [f32] => |op, xs| { Func::LeakyRelu.ew_f32_param()?.run_with_params(xs, op.alpha) }
45);