Skip to content

Conversation

@csukuangfj
Copy link
Collaborator

@csukuangfj csukuangfj commented Jul 16, 2025

You can find the checkpoints at
https://hf-mirror.com/YangQiangCD/fluent_speech_commands

Summary by CodeRabbit

  • New Features
    • Added a script to export speech recognition transducer model components (encoder, decoder, joiner) to ONNX format.
    • Enabled optional export of quantized (int8) ONNX models for improved efficiency.
    • Included detailed logging and metadata in exported ONNX files for better traceability.

@coderabbitai
Copy link

coderabbitai bot commented Jul 16, 2025

Walkthrough

A new script is introduced to export a speech recognition transducer model's encoder, decoder, and joiner components to ONNX format, with optional int8 quantization. The script defines an ONNX-compatible encoder wrapper, provides export functions for each component, adds metadata, and supports command-line execution with logging.

Changes

File(s) Change Summary
egs/fluent_speech_commands/SLU/transducer/export-onnx.py Added script to export encoder, decoder, and joiner to ONNX; includes quantization, metadata, logging, and CLI.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Script
    participant Model
    participant ONNXExporter
    participant Quantizer

    User->>Script: Run export-onnx.py with arguments
    Script->>Model: Load and prepare model (encoder, decoder, joiner)
    Script->>ONNXExporter: Export encoder to ONNX
    Script->>ONNXExporter: Export decoder to ONNX
    Script->>ONNXExporter: Export joiner to ONNX
    Script->>Quantizer: Quantize ONNX models (encoder, decoder, joiner)
    Script->>Script: Add metadata to ONNX files
    Script->>User: Log progress and completion
Loading

Poem

In a warren of code, the models now hop,
To ONNX fields, where exports won't stop.
Encoder and friends leap into the night,
Quantized and nimble, they're ready for flight.
With logs and with care, the script does its run—
The rabbit declares: "Exporting is done!" 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (2)
egs/fluent_speech_commands/SLU/transducer/export-onnx.py (2)

11-11: Consider using absolute imports for better portability.

The import from decode appears to be a relative import. Consider using absolute imports or making the relative nature explicit with a dot prefix to avoid import issues when the script is run from different directories.

-from decode import get_params, get_parser, get_transducer_model
+from .decode import get_params, get_parser, get_transducer_model

31-32: Consider using a more idiomatic approach to clear metadata.

The while loop for clearing metadata could be replaced with a more direct approach if the API supports it.

-    while len(model.metadata_props):
-        model.metadata_props.pop()
+    del model.metadata_props[:]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e22bc78 and d14d2d1.

📒 Files selected for processing (1)
  • egs/fluent_speech_commands/SLU/transducer/export-onnx.py (1 hunks)
🔇 Additional comments (2)
egs/fluent_speech_commands/SLU/transducer/export-onnx.py (2)

42-75: LGTM!

The OnnxEncoder wrapper class is well-implemented with clear documentation and proper type annotations.


77-130: LGTM!

The encoder export function is well-structured with comprehensive documentation, proper dynamic axes configuration, and appropriate metadata handling.

hidden_dim=params.hidden_dim,
vocab_size=params.vocab_size,
)
logging.info(f"Exported decoder to {joiner_filename}")
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect log message.

The log message incorrectly states "decoder" instead of "joiner".

-    logging.info(f"Exported decoder to {joiner_filename}")
+    logging.info(f"Exported joiner to {joiner_filename}")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
logging.info(f"Exported decoder to {joiner_filename}")
logging.info(f"Exported joiner to {joiner_filename}")
🤖 Prompt for AI Agents
In egs/fluent_speech_commands/SLU/transducer/export-onnx.py at line 304, the log
message incorrectly refers to "decoder" instead of "joiner". Update the
logging.info message to correctly state "Exported joiner to {joiner_filename}"
to accurately reflect the exported component.

"vocab_size": vocab_size,
"hidden_dim": hidden_dim,
}
print("joiner meta_data", meta_data)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use logging.info() for consistency.

Replace the print statement with logging.info() to maintain consistency with the rest of the codebase.

-    print("joiner meta_data", meta_data)
+    logging.info(f"joiner meta_data: {meta_data}")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
print("joiner meta_data", meta_data)
logging.info(f"joiner meta_data: {meta_data}")
🤖 Prompt for AI Agents
In egs/fluent_speech_commands/SLU/transducer/export-onnx.py at line 230, replace
the print statement with logging.info() to maintain consistency with the rest of
the codebase. Ensure that logging is properly imported and configured if not
already done.

"num_layers": h.shape[0],
"hidden_dim": h.shape[2],
}
print("decoder meta_data", meta_data)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use logging.info() for consistency.

Replace the print statement with logging.info() to maintain consistency with the rest of the codebase.

-    print("decoder meta_data", meta_data)
+    logging.info(f"decoder meta_data: {meta_data}")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
print("decoder meta_data", meta_data)
- print("decoder meta_data", meta_data)
+ logging.info(f"decoder meta_data: {meta_data}")
🤖 Prompt for AI Agents
In egs/fluent_speech_commands/SLU/transducer/export-onnx.py at line 179, replace
the print statement used for outputting "decoder meta_data" with logging.info()
to maintain consistency with the project's logging practices. Ensure logging is
properly imported and configured if not already done.

Comment on lines +250 to +256
start = params.epoch - params.avg + 1
filenames = []
for i in range(start, params.epoch + 1):
if start >= 0:
filenames.append(f"{params.exp_dir}/epoch-{i}.pt")
logging.info(f"averaging {filenames}")
model.load_state_dict(average_checkpoints(filenames))
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Move loop-invariant condition outside the loop.

The condition if start >= 0: doesn't depend on the loop variable and should be checked once outside the loop for better efficiency.

-        start = params.epoch - params.avg + 1
-        filenames = []
-        for i in range(start, params.epoch + 1):
-            if start >= 0:
-                filenames.append(f"{params.exp_dir}/epoch-{i}.pt")
+        start = params.epoch - params.avg + 1
+        filenames = []
+        if start >= 0:
+            for i in range(start, params.epoch + 1):
+                filenames.append(f"{params.exp_dir}/epoch-{i}.pt")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
start = params.epoch - params.avg + 1
filenames = []
for i in range(start, params.epoch + 1):
if start >= 0:
filenames.append(f"{params.exp_dir}/epoch-{i}.pt")
logging.info(f"averaging {filenames}")
model.load_state_dict(average_checkpoints(filenames))
start = params.epoch - params.avg + 1
filenames = []
if start >= 0:
for i in range(start, params.epoch + 1):
filenames.append(f"{params.exp_dir}/epoch-{i}.pt")
logging.info(f"averaging {filenames}")
model.load_state_dict(average_checkpoints(filenames))
🤖 Prompt for AI Agents
In egs/fluent_speech_commands/SLU/transducer/export-onnx.py around lines 250 to
256, the condition 'if start >= 0:' is inside the loop but does not depend on
the loop variable. Move this condition outside the loop to check it once before
iterating, and only run the loop to append filenames if 'start' is greater than
or equal to zero. This will improve efficiency by avoiding redundant checks in
each iteration.

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.

1 participant