[bugfix] Web UI: load from checkpoint path by type instead of dirty exception check#8340
[bugfix] Web UI: load from checkpoint path by type instead of dirty exception check#8340alphadl wants to merge 1 commit intomodelscope:mainfrom
Conversation
Summary of ChangesHello, 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 maintainability of the Web UI's checkpoint loading functionality. It refactors the logic for determining how to load a model from a local path, moving away from an unreliable exception-catching mechanism to a more explicit and robust check based on the model's type. This change ensures that models are loaded correctly without relying on specific error message strings, improving the overall reliability of the system. Highlights
🧠 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
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.
Code Review
This pull request provides a good improvement by refactoring the logic for loading local checkpoints in the Web UI. It replaces a fragile approach of parsing exception messages with a more robust check on the path type using BaseArguments._check_is_adapter. This enhances code clarity and reliability. I have one suggestion to further improve the consistency of this logic.
| if BaseArguments._check_is_adapter(model): | ||
| args = arg_cls(resume_from_checkpoint=model, load_data_args=True) | ||
| except Exception as e: | ||
| if 'using `--model`' in str(e): # TODO a dirty fix | ||
| args = arg_cls(model=model, load_data_args=True) | ||
| else: | ||
| raise e | ||
| else: | ||
| args = arg_cls(model=model, load_data_args=True) |
There was a problem hiding this comment.
Using BaseArguments._check_is_adapter here is a great improvement for robustness. For consistency, consider also using this function in the else block (starting on line 350) which handles cases where arg_cls does not have resume_from_checkpoint. That block currently uses a more limited check (os.path.exists(os.path.join(model, 'adapter_config.json'))), and unifying the logic would make adapter detection consistent.
Summary: Replaces the "TODO a dirty fix" in Web UI when loading a local checkpoint: instead of catching the error message and retrying with
--model, we now decide the constructor up front usingBaseArguments._check_is_adapter(model).arg_cls(resume_from_checkpoint=model, ...)was called; on exception containing"using \--model`", we calledarg_cls(model=model, ...)`. This was fragile and commented as a dirty fix._check_is_adapter(model)is true (adapter/peft dir withadapter_config.jsonetc.), we useresume_from_checkpoint=model; otherwise we usemodel=modelfor full checkpoint paths. No reliance on exception text.Changes:
swift/ui/base.py, whenlocal_args_pathexists andarg_clshasresume_from_checkpoint, useBaseArguments._check_is_adapter(model)to choose betweenresume_from_checkpoint=modelandmodel=model.'using \--model`' in str(e)` and the "TODO a dirty fix" comment.Please take a look when you have time. cc @Jintao-Huang @hjh0119