Skip to content

Comments

Fix #2806: NameError: name 'ClusterBackend' is not defined#2818

Open
danielalanbates wants to merge 1 commit intomodelscope:mainfrom
danielalanbates:fix/issue-2806
Open

Fix #2806: NameError: name 'ClusterBackend' is not defined#2818
danielalanbates wants to merge 1 commit intomodelscope:mainfrom
danielalanbates:fix/issue-2806

Conversation

@danielalanbates
Copy link

Fixes #2806

Summary

This PR addresses: NameError: name 'ClusterBackend' is not defined

Changes

funasr/auto/auto_model.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Testing

Please review the changes carefully. The fix was verified against the existing test suite.


This PR was created with the assistance of Claude Sonnet 4.6 by Anthropic | effort: low. Happy to make any adjustments!

…error message

Replace bare except/pass with proper fallback initialization and a
warning log when speaker-related modules fail to import. At the usage
site, raise an informative ImportError instead of a cryptic NameError
so users understand which dependency is missing.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @danielalanbates, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the stability and user experience of the funasr library by addressing a critical NameError that could arise during the import of speaker diarization components. The changes ensure that even if certain modules fail to load, the application handles the situation gracefully, provides clear diagnostic messages, and guides users on resolving dependency issues, thereby preventing runtime crashes and improving overall reliability.

Highlights

  • NameError Resolution: Resolved a NameError that occurred when ClusterBackend was not defined due to failed imports, preventing speaker diarization functionality.
  • Robust Import Handling: Improved the robustness of module imports for speaker-related functionalities by initializing variables to None and catching specific exceptions with informative logging.
  • Clearer Error Messaging: Introduced an explicit check for ClusterBackend availability, raising a detailed ImportError with guidance on missing dependencies if the module fails to load.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • funasr/auto/auto_model.py
    • Initialized sv_chunk, postprocess, distribute_spk, and ClusterBackend to None to prevent NameError if imports fail.
    • Updated the generic except block to catch Exception as e and log a warning message, providing more context on import failures.
    • Added a conditional check to verify ClusterBackend is not None before instantiation, raising an ImportError with specific dependency requirements if it's unavailable.
Activity
  • The pull request was created with the assistance of Claude Sonnet 4.6 by Anthropic, indicating a low effort for the author.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes a NameError for ClusterBackend by initializing it to None before a try-except block that handles its import. This is a good approach. The PR also improves error handling by replacing a bare except with except Exception as e and logging a warning, and by adding a check to fail early if ClusterBackend could not be imported.

My review includes one suggestion to make the error handling even more robust by checking all related modules that are imported within the same try-except block, not just ClusterBackend. This will prevent potential TypeErrors at runtime and provide a consistent early-failure mechanism for missing speaker diarization dependencies.

Comment on lines +173 to +178
if ClusterBackend is None:
raise ImportError(
"ClusterBackend is not available. This is likely because required dependencies "
"(e.g. scikit-learn with HDBSCAN support, scipy) failed to import. "
"Please ensure scikit-learn>=1.3.0 and scipy are properly installed."
)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While adding a check for ClusterBackend is a great improvement to fail early and provide a clear error message, the other modules imported in the same try-except block (sv_chunk, postprocess, distribute_spk) are not checked.

If their import fails, they will also be None, and calling them later in inference_with_vad will result in a TypeError: 'NoneType' object is not callable.

To make the error handling more robust, I suggest checking for all these modules at once. This ensures that if any of the speaker-related dependencies are missing, the program fails early with a clear error message.

            if any(x is None for x in (sv_chunk, postprocess, distribute_spk, ClusterBackend)):
                raise ImportError("Speaker diarization dependencies failed to import. Check logs and ensure optional packages are installed (e.g., scikit-learn, scipy).")

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.

NameError: name 'ClusterBackend' is not defined

1 participant