softmax
Classes
SoftmaxOperator
SoftmaxOperator(ident: int, op: OperatorT, model: ModelT, subgraph: SubGraphT, prefix: str = 'aot', attributes: dict[str, str] = {})
SOFTMAX operator.
This operator computes the softmax activation function on the input tensor.
Parameters:
-
ident
int
) –Operator identifier.
-
op
OperatorT
) –Operator object from LiteRT model.
-
model
ModelT
) –LiteRT model object.
-
subgraph
SubGraphT
) –Subgraph object from LiteRT model.
-
prefix
str
, default:'aot'
) –Prefix for generated files. Defaults to "aot".
-
attributes
dict[str, str]
, default:{}
) –Attributes for template values. Defaults to {}.
Attributes
Functions
compute_values
generate_source_code
Generate the source code for the operator.
Parameters:
-
save_path
Path
) –Path to save the generated code.
Functions
preprocess_softmax_scaling
preprocess_softmax_scaling(beta: float, input_scale: float, scaled_diff_integer_bits: int = 5) -> tuple[int, int]
Mimics litert::PreprocessSoftmaxScaling.
Parameters:
-
beta
float
) –The softmax beta parameter (often 1.0).
-
input_scale
float
) –The quantization scale for the input tensor.
-
scaled_diff_integer_bits
int
, default:5
) –Number of integer bits to reserve in the scaled difference (typically 5).
Returns:
calculate_input_radius
Mimics litert::CalculateInputRadius (non-emulated version).
This computes the maximum representable difference in the scaled domain.
Parameters:
-
input_integer_bits
int
) –Number of integer bits reserved (e.g., kScaledDiffIntegerBits, typically 5).
-
input_left_shift
int
) –The left shift computed from PreprocessSoftmaxScaling.
-
total_signed_bits
int
, default:31
) –Total bits available in the representation (typically 31 for Q31 arithmetic).
Returns:
-
int
(int
) –The computed input radius.