Skip to content

Conversation

csukuangfj
Copy link
Collaborator

@csukuangfj csukuangfj commented Jul 26, 2025

Fixes #2420

Summary by CodeRabbit

  • Bug Fixes

    • Improved compatibility by supporting both int32 and int64 data types for sequence length handling in the decoder.
  • Style

    • Minor formatting adjustments for improved code readability.

Copy link

coderabbitai bot commented Jul 26, 2025

"""

Walkthrough

This change updates the decoding logic in the offline transducer NeMo decoder to support both int32 and int64 tensor types for the encoder output length, adding type checks and conditional access. Additionally, it includes minor formatting corrections in the decoding loop without altering existing logic or control flow.

Changes

File(s) Change Summary
sherpa-onnx/csrc/offline-transducer-greedy-search-nemo-decoder.cc Added support for both int32 and int64 encoder output length tensors; improved error handling for unsupported types; fixed code formatting in the inner decoding loop.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Decoder
    participant EncoderOutLenTensor

    User->>Decoder: Call Decode()
    Decoder->>EncoderOutLenTensor: Check element type
    alt int32
        Decoder->>EncoderOutLenTensor: Access data as int32_t
    else int64
        Decoder->>EncoderOutLenTensor: Access data as int64_t
    else unsupported
        Decoder->>Decoder: Log error and exit
    end
    Decoder->>Decoder: Perform decoding loop (formatting adjusted)
    Decoder-->>User: Return decoded results
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Poem

A bunny hopped through code today,
Adjusting types along the way.
int32 or int64, now both are fine—
Decoding works for every line!
With tidy loops and checks anew,
This patch brings joy to me and you.
🐇✨
"""

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 37ed7ac and 586bf70.

📒 Files selected for processing (1)
  • sherpa-onnx/csrc/offline-transducer-greedy-search-nemo-decoder.cc (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • sherpa-onnx/csrc/offline-transducer-greedy-search-nemo-decoder.cc
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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 generate unit tests to generate unit tests for 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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 10e845a and 37ed7ac.

📒 Files selected for processing (1)
  • sherpa-onnx/csrc/offline-transducer-greedy-search-nemo-decoder.cc (2 hunks)
🔇 Additional comments (3)
sherpa-onnx/csrc/offline-transducer-greedy-search-nemo-decoder.cc (3)

65-92: LGTM! Formatting improvements enhance readability.

The indentation and spacing corrections improve code readability without altering the existing logic or control flow.


107-114: Excellent type safety implementation.

The addition of explicit type checking for encoder_out_length tensor properly addresses the data type compatibility issue. The error handling provides clear diagnostics and follows good practices with appropriate logging and program termination.


123-125: Correct implementation of type-safe conditional access.

The conditional logic properly handles both int32_t and int64_t data types using the detected length_type. The implementation is clean and ensures type safety when accessing the tensor data.

@csukuangfj csukuangfj requested a review from Copilot July 26, 2025 15:37
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a data type compatibility issue in the GigaAM transducer encoder where the output length tensor could be either int32 or int64, but the code only handled int32. The fix adds runtime type checking and supports both data types.

  • Adds runtime detection of encoder output length tensor data type (int32 vs int64)
  • Implements conditional data access based on the detected type
  • Adds error handling for unsupported data types

Comment on lines 118 to +124
std::vector<OfflineTransducerDecoderResult> ans(batch_size);

for (int32_t i = 0; i != batch_size; ++i) {
const float *this_p = p + dim1 * dim2 * i;
int32_t this_len = p_length[i];
int32_t this_len = length_type == ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32
? encoder_out_length.GetTensorData<int32_t>()[i]
: encoder_out_length.GetTensorData<int64_t>()[i];
Copy link

Copilot AI Jul 26, 2025

Choose a reason for hiding this comment

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

The tensor data is being accessed inside the loop for each iteration. Consider caching the tensor data pointer outside the loop to avoid repeated GetTensorData calls.

Copilot uses AI. Check for mistakes.

@csukuangfj csukuangfj merged commit 9252f16 into k2-fsa:master Jul 26, 2025
206 of 228 checks passed
@csukuangfj csukuangfj deleted the fix-giga-am branch July 26, 2025 15:39
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.

Wrong output type in GigaAM2 onnx leads to segmentation fault

1 participant