1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! # Mish Activation
//!
//! Mish: A Self Regularized Non-Monotonic Neural Activation Function.
//!
//! `mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + e^x))`
//!
//! **ONNX Spec**: <https://onnx.ai/onnx/operators/onnx__Mish.html>
//!
//! ## Type Constraints
//!
//! T: Float tensor types (float16, float, double, bfloat16)
//!
//! ## Opset Versions
//! - **Opset 18**: Initial support
//! - **Opset 22**: Added bfloat16
use onnx_ir_derive::NodeBuilder;
use crate::ir::{Argument, Node, RawNode};
use crate::processor::{
InputSpec, NodeProcessor, NodeSpec, OutputPreferences, OutputSpec, ProcessError, same_as_input,
validate_opset,
};
/// Node representation for Mish operation
#[derive(Debug, Clone, NodeBuilder)]
pub struct MishNode {
pub name: String,
pub inputs: Vec<Argument>,
pub outputs: Vec<Argument>,
}
/// Node processor for Mish activation
pub(crate) struct MishProcessor;
impl NodeProcessor for MishProcessor {
type Config = ();
fn spec(&self) -> NodeSpec {
NodeSpec {
min_opset: 18,
max_opset: None,
inputs: InputSpec::Exact(1),
outputs: OutputSpec::Exact(1),
}
}
fn infer_types(
&self,
node: &mut RawNode,
opset: usize,
_output_preferences: &OutputPreferences,
) -> Result<(), ProcessError> {
validate_opset(opset, 18)?;
same_as_input(node);
Ok(())
}
fn build_node(&self, builder: RawNode, _opset: usize) -> Node {
Node::Mish(MishNode {
name: builder.name,
inputs: builder.inputs,
outputs: builder.outputs,
})
}
}