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
//! Defines the precedence of the output keys in the session outputs.
//!
//! # Note
//!
//! The purpose of this module is to replicate the existing output key selection mechanism
//! in the library. This is an acceptable solution in lieu of a model-specific solution,
//! e.g. reading the output keys from the model file.
/// Enum for defining the key of the output.
/// Trait for defining a precedence of keys in the output.
///
/// This defines the order of precedence for selecting the output from the session outputs.
/// By convention, an ONNX model will have at least one output called `last_hidden_state`,
/// which is however not guaranteed. This trait allows the user to define the order of
/// precedence for selecting the output.
///
/// Any [`OutputPrecedence`] should be usable multiple times, and should not consume itself;
/// this is due to use of [`rayon`] parallelism, which means
/// [`OutputPrecedence::key_precedence`] will have to be called once per batch.
/// Any slices of [`OutputKey`] can be used as an [`OutputPrecedence`].