Skip to content

Add Nn::StatefulTransducerOnnxLabelScorer - #149

Merged
curufinwe merged 26 commits into
masterfrom
transducer_label_scorer
Oct 30, 2026
Merged

curufinwe merged 26 commits into
masterfrom
transducer_label_scorer

Conversation

@SimBe195

@SimBe195 SimBe195 commented Oct 2, 2025

Copy link
Copy Markdown
Collaborator

Add a new label scorer class StatefulTransducerOnnxLabelScorer. This is similar to the StatefulOnnxLabelScorer but hidden-state and encoder features are decoupled. Here, the state initializer and state updater only take tokens and no encoder features. Instead, the scorer receives the encoder state at the current time step and the hidden state and is supposed to combine the two.

This can be used for transducer models with unlimited context.

Depends on #144.

@SimBe195
SimBe195 marked this pull request as ready for review October 2, 2025 17:56
Base automatically changed from finalize-scoring-context to master November 13, 2025 12:57
SimBe195 and others added 12 commits May 26, 2026 12:29
…n StatefulOnnxLabelScorer and StatefulTransducerOnnxLabelScorer
Resolve the conflict with #261 in StatefulOnnxLabelScorer and port both
hidden-state scorers to the StatTrackingLabelScorer interface
(resetInternal, computeScoreAccessor(s)).

The session runs and the state marshalling now live in
OnnxHiddenStateModel, so the helper owns the session and marshalling
timers. StatefulOnnxLabelScorer reports the same statistics as on master
by combining them with its own marshalling timer.
StatefulTransducerOnnxLabelScorer reports the same breakdown, without
the initializer, which runs outside of the scoring time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
StatefulTransducerOnnxLabelScorer runs its state initializer in
getInitialScoringContext, outside getScoreAccessor(s), so neither the
scoring-time total nor the breakdown included it. Time it with
scoringTime_ and report initializer + updater as
state-update-session-time, as StatefulOnnxLabelScorer already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reorder the definitions in StatefulTransducerOnnxLabelScorer.cc and
OnnxHiddenStateModel.cc to follow the declaration order in the
headers. No code changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move OnnxHiddenState and OnnxHiddenStateModel from Nn/LabelScorer into
src/Onnx (namespace Onnx), next to the other ONNX implementations of
Nn interfaces. ScoringContext.hh no longer includes Onnx/Value.hh, so
headers shared by all searches don't pull in ONNX Runtime.

Register the ONNX label scorers in Nn::Module only with MODULE_ONNX.

CtcPrefixLabelScorer.hh used Math::FastMatrix without including it and
only got it transitively through Onnx/Value.hh; include it directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nn::Module included Onnx headers and defined createStateManager
(OnnxLstmStateManager, OnnxTransformerStateManager) unconditionally,
so builds with MODULE_ONNX=OFF failed to link. Put the includes, the
state-manager type choice and parameter, and createStateManager under
MODULE_ONNX. Its callers (StateManagedOnnxLabelScorer and
Lm::OnnxRecurrentLanguageModel) are only built with ONNX enabled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#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

@curufinwe curufinwe changed the title Add stateful-transducer-onnx label scorer Add Nn::StatefulTransducerOnnxLabelScorer Oct 28, 2026

@larissakl larissakl left a comment

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.

TODO: update the docs

Comment thread src/Onnx/OnnxHiddenStateModel.hh Resolved
larissakl and others added 4 commits October 29, 2026 16:06
The class bundles three Onnx::Models (state initializer, state updater
and scorer) rather than being one, so "Model" was misleading. Its state
type is just a set of named ONNX values, hence OnnxHiddenState becomes
OnnxNamedValues (stateValueMap -> valueMap). The bundle methods
initialHiddenState/updatedHiddenStates become initialState/updatedStates,
and the scorer members hiddenStateModel_ become initUpdateScoreBundle_.

No functional change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The hidden state only depends on the label sequence, not on the step, so
`stateCache_` now uses `LabelSeqHash`/`LabelSeqEq`. The same label
sequence reached at different steps no longer reruns the state updater,
and already finalized contexts are no longer inserted into the cache.

Since `FIFOCache::put` doesn't refresh an existing key, a cached state
could be evicted between being looked up and being read. States needed
within one `computeScoreAccessors` call are therefore collected in a
local map when they are looked up or computed, and all later reads use
that map.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Remove the outdated comment on `getInitialScoringContext`
- Pass `requiresFinalize` directly to the scoring context constructor
- Return the minimum active step from `getMinActiveInputIndex` so that the
  input buffer is trimmed; only the input of the current step is read

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@curufinwe
curufinwe merged commit 6d2cfd7 into master Oct 30, 2026
4 checks passed
@curufinwe
curufinwe deleted the transducer_label_scorer branch October 30, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants