Skip to content

Fix for Tracing ECAPA-TDNN Embedding Model#2982

Merged
TParcollet merged 2 commits intospeechbrain:developfrom
jordanozang:ecapa_tdnn_dynamo_compile
Nov 2, 2025
Merged

Fix for Tracing ECAPA-TDNN Embedding Model#2982
TParcollet merged 2 commits intospeechbrain:developfrom
jordanozang:ecapa_tdnn_dynamo_compile

Conversation

@jordanozang
Copy link
Copy Markdown
Contributor

What does this PR do?

Currently the torch.onnx.export tracer fails to export the ecapa-tdnn embedding model, giving the error described in #149760. This error occurs because an exception is part of the control flow of the model, used to check whether or not a given layer supports the length argument. When this is thrown, the tracer has already pushed the layer onto its stack so that, while the layer is not used, it sticks around until the end of the trace, where it is encountered instead of the root node, hence the key mismatch.

The following very minimal code triggers the failure. I have also successfully exported the embedding model to onnx with the dynamo exporter, including dynamic batch and audio sample dimensions.

import torch
from speechbrain.inference.speaker import EncoderClassifier

enc = EncoderClassifier.from_hparams(source='speechbrain/spkrec-ecapa-voxceleb').to('cpu')

torch.export.export(enc.mods.embedding_model, (torch.zeros(1, 1000, 80), torch.ones(1)))

Fixes #149760

Before submitting
  • Did you read the contributor guideline?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • [ x Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Does your code adhere to project-specific code style and conventions?

PR review

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified
  • Confirm that the changes adhere to compatibility requirements (e.g., Python version, platform)
  • Review the self-review checklist to ensure the code is ready for review

Copy link
Copy Markdown
Collaborator

@TParcollet TParcollet left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

@TParcollet TParcollet merged commit c6d2a8b into speechbrain:develop Nov 2, 2025
4 of 7 checks passed
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.

2 participants