Skip to content

[bugfix] Web UI: load from checkpoint path by type instead of dirty exception check#8340

Open
alphadl wants to merge 1 commit intomodelscope:mainfrom
alphadl:fix/ui-checkpoint-load-no-dirty-fix
Open

[bugfix] Web UI: load from checkpoint path by type instead of dirty exception check#8340
alphadl wants to merge 1 commit intomodelscope:mainfrom
alphadl:fix/ui-checkpoint-load-no-dirty-fix

Conversation

@alphadl
Copy link

@alphadl alphadl commented Mar 14, 2026

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 using BaseArguments._check_is_adapter(model).

  • Before: arg_cls(resume_from_checkpoint=model, ...) was called; on exception containing "using \--model`", we called arg_cls(model=model, ...)`. This was fragile and commented as a dirty fix.
  • After: If _check_is_adapter(model) is true (adapter/peft dir with adapter_config.json etc.), we use resume_from_checkpoint=model; otherwise we use model=model for full checkpoint paths. No reliance on exception text.

Changes:

  • In swift/ui/base.py, when local_args_path exists and arg_cls has resume_from_checkpoint, use BaseArguments._check_is_adapter(model) to choose between resume_from_checkpoint=model and model=model.
  • Removed the try/except that checked for 'using \--model`' in str(e)` and the "TODO a dirty fix" comment.

Please take a look when you have time. cc @Jintao-Huang @hjh0119

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • Robust Checkpoint Loading: Replaced a fragile exception-based mechanism for loading local checkpoints in the Web UI with a direct check using BaseArguments._check_is_adapter(model).
  • Logic Simplification: Eliminated a "TODO a dirty fix" try/except block that relied on parsing an exception message to determine if a model should be loaded as an adapter or a full checkpoint.

🧠 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
  • swift/ui/base.py
    • Modified the update_input_model function to use BaseArguments._check_is_adapter(model) for deciding whether to load a model using resume_from_checkpoint or model arguments.
    • Removed the try...except block that previously caught exceptions containing 'using --model' to switch loading methods.
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 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.

Comment on lines +346 to +349
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

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