-
Notifications
You must be signed in to change notification settings - Fork 88
fix(transformers_4.54_base): supplement condition of taking model as processor #1347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: hf-transformers-4.54
Are you sure you want to change the base?
fix(transformers_4.54_base): supplement condition of taking model as processor #1347
Conversation
Summary of ChangesHello @wcrzlh, 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, authored by wcrzlh, addresses a fix in the Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
I've reviewed the changes and the refactoring in processing_utils.py
is a significant improvement in terms of code clarity and robustness. The new get_possibly_dynamic_module
method is much better than the previous approach of string-matching module names. I have one suggestion to fix a potential bug in the sys.path
manipulation logic.
sub_path = os.path.abspath(os.path.dirname(__file__)) | ||
sub_path = str(Path(sub_path).parent) | ||
sys.path.insert(0, sub_path) | ||
mindone_transformers_module = importlib.import_module("mindone.transformers") | ||
if not hasattr(mindone_transformers_module, module_name): | ||
raise ValueError( | ||
f"Expect to have `{module_name}` registered in `mindone.transformers`, but failed to load it!" | ||
) | ||
return getattr(mindone_transformers_module, module_name) | ||
else: | ||
if sub_path not in sys.path: | ||
sys.path.insert(0, sub_path) | ||
mindone_tsf_path = importlib.import_module("mindone.transformers") | ||
return getattr(mindone_tsf_path, module_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There appears to be a bug in the sys.path
manipulation and a confusing variable name here.
-
Path issue: The code adds the
mindone
directory tosys.path
, but to importmindone.transformers
, the parent directory ofmindone
(the project root) should be added. The current implementation will likely fail with anImportError
in environments where the project root is not already insys.path
. -
Naming issue: The variable
mindone_tsf_path
is misleading as it holds a module object, not a path.
I suggest refactoring this block to correctly set the path and use a clearer variable name.
sub_path = os.path.abspath(os.path.dirname(__file__)) | |
sub_path = str(Path(sub_path).parent) | |
sys.path.insert(0, sub_path) | |
mindone_transformers_module = importlib.import_module("mindone.transformers") | |
if not hasattr(mindone_transformers_module, module_name): | |
raise ValueError( | |
f"Expect to have `{module_name}` registered in `mindone.transformers`, but failed to load it!" | |
) | |
return getattr(mindone_transformers_module, module_name) | |
else: | |
if sub_path not in sys.path: | |
sys.path.insert(0, sub_path) | |
mindone_tsf_path = importlib.import_module("mindone.transformers") | |
return getattr(mindone_tsf_path, module_name) | |
project_root = str(Path(__file__).resolve().parent.parent.parent) | |
if project_root not in sys.path: | |
sys.path.insert(0, project_root) | |
mindone_transformers_module = importlib.import_module("mindone.transformers") | |
return getattr(mindone_transformers_module, module_name) |
What does this PR do?
Fixes # (issue)
✅ supplement condition of taking model as processor on hf transformers 4.54 base
Before submitting
What's New
. Here are thedocumentation guidelines
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@xxx