Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
540c311
Introduce finalizeScoringContext function for updating hidden states
larissakl Sep 23, 2025
39888ef
Refactor: Handle finalization internally in LabelScorer
SimBe195 Sep 29, 2025
ad702b3
Revert docstring in LabelScorer
SimBe195 Sep 29, 2025
1b9a55e
Add StatefulTransducerOnnxLabelScorer class
SimBe195 Oct 2, 2025
c167092
Remove wrong verify
SimBe195 Oct 2, 2025
5c67ff7
Remove wrong timeframe insertion
SimBe195 Oct 2, 2025
b3728ec
Actually use `finalizeScoringContext`
SimBe195 Oct 8, 2025
b2d150c
Merge branch 'master' into transducer_label_scorer
SimBe195 Apr 16, 2026
63c4d74
Update interface and add batching and state caching like in StatefulO…
SimBe195 Apr 16, 2026
3c914be
Apply suggestions from code review
SimBe195 Apr 22, 2026
f81fbbc
Cache state of already finalized scoring contexts
SimBe195 May 26, 2026
a3423e8
Merge branch 'master' into transducer_label_scorer
SimBe195 May 26, 2026
c6ab994
Merge branch 'master' into transducer_label_scorer
SimBe195 Aug 27, 2026
dbd0ef7
Move StepOnnxHiddenStateScoringContext next to corresponding label sc…
SimBe195 Aug 27, 2026
9ee4f69
Introduce OnnxHiddenStateModel to refactor out common behavior betwee…
SimBe195 Sep 9, 2026
d45c6d6
Rename `ExtraInputs` to `SessionInputs`
SimBe195 Sep 10, 2026
96bf61e
Merge branch 'master' into transducer_label_scorer
SimBe195 Sep 10, 2026
7246118
Merge branch 'master' into transducer_label_scorer
curufinwe Oct 27, 2026
8172020
Count the transducer state initializer towards the scoring time
curufinwe Oct 28, 2026
a0493c5
Order method definitions like their declarations
curufinwe Oct 28, 2026
f6f7220
Move OnnxHiddenStateModel to Onnx and guard ONNX label scorers
curufinwe Oct 28, 2026
3d53448
Guard the ONNX state manager code in Nn::Module
curufinwe Oct 28, 2026
4e8c906
Update docs
larissakl Oct 29, 2026
7dab3c4
Rename OnnxHiddenStateModel to OnnxInitUpdateScoreBundle
curufinwe Oct 29, 2026
a41d950
Key the transducer state cache by the label sequence only
curufinwe Oct 29, 2026
6b65bd3
Address review comments on StatefulTransducerOnnxLabelScorer
curufinwe Oct 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions doc/search_v2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,9 @@ built-in way to do this.

Built-in label scorer types include:

* ``no-context-onnx``, ``fixed-context-onnx``, ``stateful-onnx``, ``state-managed-onnx``: forward
features (and, depending on type, label history/hidden state) through an ONNX model.
* ``no-context-onnx``, ``fixed-context-onnx``, ``stateful-onnx``, ``stateful-transducer-onnx``,
``state-managed-onnx``: forward features (and, depending on type, label history/hidden state) through an ONNX
model.
* ``encoder-decoder`` / ``encoder-only``: wrap a separate encoder (see :ref:`Encoders` below) that
pre-processes features, combined with a decoder label scorer (or no decoder, for encoder-only models).
* ``ctc-prefix``: wraps a time-synchronous CTC scorer and derives label-synchronous prefix scores from it
Expand Down Expand Up @@ -816,7 +817,7 @@ have no ``transition-preset`` of their own and always report whichever transitio
ONNX model configuration
^^^^^^^^^^^^^^^^^^^^^^^^^

The four ``*-onnx`` label scorers below (and the ``onnx``/``chunked-onnx`` :ref:`encoders <Encoders>` used by
The ``*-onnx`` label scorers below (and the ``onnx``/``chunked-onnx`` :ref:`encoders <Encoders>` used by
:ref:`encoder-decoder / encoder-only`) all wrap one or more ONNX Runtime sessions and share the same
sub-configuration pattern for each wrapped model, under a model-specific selector (e.g. ``onnx-model`` for the
single-model scorers):
Expand Down Expand Up @@ -910,7 +911,8 @@ stateful (recurrent) language model.
the respective label types trigger a state update. Default ``false``.
* ``max-batch-size`` (int): maximum number of hidden states forwarded through the scorer model at once. Default unbounded.
* ``max-cached-score-vectors`` (int): size of an LRU cache mapping scoring contexts to already-computed score
vectors, to avoid recomputation and bound memory use on very long segments. Default ``1000``.
vectors, to avoid recomputation and bound memory use on very long segments. The same size is used for a second
cache that maps scoring contexts to their updated hidden states. Default ``10000``.
* Default :ref:`transition-preset <Transition types and presets>`: ``lm``.

.. code-block:: ini
Expand All @@ -921,6 +923,50 @@ stateful (recurrent) language model.
state-updater-model.session.file = /path/to/state_update.onnx
scorer-model.session.file = /path/to/scorer.onnx

stateful-transducer-onnx
^^^^^^^^^^^^^^^^^^^^^^^^^

Transducer counterpart of ``stateful-onnx``: uses the same three ONNX models (state initializer, state updater,
scorer) and the same hidden-state metadata convention, but each scoring context additionally tracks the current
time step, and the scorer receives the input feature of that step alongside the hidden state(s). A typical use
case is a neural transducer whose prediction network has unlimited (recurrent) context, i.e. the counterpart of
``fixed-context-onnx`` without a fixed history window.

Differences to ``stateful-onnx``:

* the **state initializer** takes no inputs (in particular no encoder states), it is run once and its output is
reused across segments.
* the **state updater** takes only the next ``token`` (plus the hidden state(s)), no encoder states.
* the **scorer** takes the hidden state(s) and the ``input-feature`` of the context's current time step, with
shape ``[1, F]``. Since all contexts in a scorer batch share the same time step, this single feature row is
passed for the whole batch, so the model has to broadcast it against the ``[B, *]`` hidden states.

The hidden state is updated lazily. Extending a context with a token only records the token and the state
updater runs (batched) the next time that context is scored.

* ``state-initializer-model.*`` / ``state-updater-model.*`` / ``scorer-model.*`` : as for ``stateful-onnx``.
Logical I/O names: ``token`` (state updater, required) and ``input-feature`` / ``scores`` (scorer, required).
* ``blank-updates-history`` / ``silence-updates-history`` / ``loop-updates-history`` (bool): whether the
respective label types are fed to the state updater. Default ``false``.
* ``vertical-label-transition`` (bool): as for ``fixed-context-onnx``, whether non-blank label transitions keep
the time step instead of advancing it. Default ``false``.
* ``max-batch-size`` (int): maximum number of scoring contexts forwarded through the state updater and scorer
at once. Default unbounded.
* ``max-cached-score-vectors`` (int): size of the score cache and of the hidden-state cache, as for
``stateful-onnx``. Default ``10000``.
* Default :ref:`transition-preset <Transition types and presets>`: ``transducer``.

.. code-block:: ini

[*.search-algorithm.label-scorer]
type = stateful-transducer-onnx
state-initializer-model.session.file = /path/to/state_init.onnx
state-updater-model.session.file = /path/to/state_update.onnx
state-updater-model.io-map.token = token
scorer-model.session.file = /path/to/scorer.onnx
scorer-model.io-map.input-feature = encoder_frame
scorer-model.io-map.scores = log_probs

state-managed-onnx
^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion src/Nn/LabelScorer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ target_sources(
if(${MODULE_ONNX})
target_sources(
RasrNn
PRIVATE FixedContextOnnxLabelScorer.cc NoContextOnnxLabelScorer.cc
PRIVATE FixedContextOnnxLabelScorer.cc
NoContextOnnxLabelScorer.cc
StatefulOnnxLabelScorer.cc
StatefulTransducerOnnxLabelScorer.cc
StateManagedOnnxLabelScorer.cc
)
endif()
Expand Down
2 changes: 2 additions & 0 deletions src/Nn/LabelScorer/CtcPrefixLabelScorer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#ifndef CTC_PREFIX_LABEL_SCORER_HH
#define CTC_PREFIX_LABEL_SCORER_HH

#include <Math/FastMatrix.hh>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header uses Math::FastMatrix (ctcScores_, the CtcPrefixScoreAccessor constructor) but never included it. It only compiled because the type arrived transitively: LabelScorer.hh → DataView.hh → Onnx/Value.hh → Math/FastMatrix.hh. DataView.hh includes Onnx/Value.hh only under #ifdef MODULE_ONNX, so on master a build with -DMODULE_ONNX=OFF already fails here.

The previous state of this PR hid that, because ScoringContext.hh included Onnx/Value.hh unconditionally (for OnnxHiddenState). Now that OnnxHiddenState lives in Onnx/OnnxHiddenStateModel.hh and ScoringContext.hh is back to master's version, the transitive path is gone in ONNX-off builds. The explicit include fixes that; the ONNX-off build is green with it.

— Claude Code


#include "LabelScorer.hh"
#include "ModelCache.hh"
#include "ScaledLabelScorer.hh"
Expand Down
Loading
Loading