Skip to content

Conversation

Jintao-Huang
Copy link
Collaborator

No description provided.

Copy link
Contributor

Summary of Changes

Hello @Jintao-Huang, 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 implements a minor but essential adjustment to the DPOConfig within the swift framework. The change specifically addresses compatibility requirements for version 0.15 of the trl library by introducing an optional parameter. This ensures that the system can continue to function correctly and integrate seamlessly with the updated trl library without encountering configuration issues.

Highlights

  • TRL 0.15 Compatibility: The DPOConfig class has been updated to include an optional ld_alpha parameter, ensuring compatibility with version 0.15 of the trl library.
  • Type Hinting: The Optional type from the typing module has been imported to support the new optional parameter.
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

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 introduces a compatibility fix for trl. It adds the ld_alpha field to DPOConfig to support older versions of trl where this field is not present, preventing potential AttributeError. The change is correct and minimal. I've added one suggestion to improve the clarity of a code comment for better future maintainability.

@dataclass
class DPOConfig(SwiftArgumentsMixin, HfDPOConfig):
pass
ld_alpha: Optional[float] = None # compat trl==0.15
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The comment # compat trl==0.15 is a bit confusing as there doesn't seem to be a 0.15 version for the trl library. This could make future maintenance more difficult. The ld_alpha parameter was introduced in trl version 0.7.1. To improve clarity, consider updating the comment to specify the correct version range, for example: # compat trl < 0.7.1.

Suggested change
ld_alpha: Optional[float] = None # compat trl==0.15
ld_alpha: Optional[float] = None # compat trl < 0.7.1

@Jintao-Huang
Copy link
Collaborator Author

/gemini review

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 aims to add compatibility for trl version 0.15 and includes a refactoring of the model conversion logic. The changes involve adding a new ld_alpha field to DPOConfig and modifying convert_mcore2hf to delay model loading, which is a good memory optimization. My review focuses on a potential performance consideration in the refactored code.

from swift.megatron import prepare_mcore_model, adapter_state_dict_context
hf_model, template = prepare_model_template(
args, load_model=args.to_hf, patch_offload=not args.test_convert_precision)
_, template = prepare_model_template(args, load_model=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This change refactors the logic to delay loading the hf_model until it's needed inside the if args.to_hf: block, which is a good practice for memory efficiency. However, this introduces a second call to prepare_model_template on line 297. While this improves code structure, it's worth ensuring that calling prepare_model_template twice doesn't introduce a significant performance overhead. If the function is lightweight when load_model=False, this is fine. Otherwise, it might be better to refactor prepare_model_template to separate template creation from model loading more explicitly.

@Jintao-Huang Jintao-Huang merged commit 67cd30c into modelscope:main Sep 22, 2025
2 checks passed
Jintao-Huang added a commit that referenced this pull request Sep 22, 2025
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.

2 participants