Skip to content

Conversation

@hjh0119
Copy link
Collaborator

@hjh0119 hjh0119 commented Nov 16, 2025

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hjh0119, 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 integrates an optional, memory-optimized loss function from the Liger Kernel into the GKDTrainer. The primary goal is to enhance training efficiency, particularly concerning memory consumption, by employing a fused Jensen-Shannon Divergence (JSD) loss that processes hidden states and output embeddings directly. This provides an alternative, more resource-conscious approach to knowledge distillation.

Highlights

  • Liger Kernel Integration: Adds support for LigerFusedLinearJSDLoss from the liger_kernel library, providing an alternative, potentially more efficient, loss computation method for GKD training.
  • Memory Optimization: The new Liger loss path is designed to reduce peak memory usage by directly operating on model hidden states and output heads, and explicitly releasing intermediate tensors after use.
  • Conditional Loss Computation: The compute_loss method now dynamically switches between the standard JSD loss and the Liger fused JSD loss based on a configuration flag (use_liger_kernel).
  • SFT Loss Constraint: An assertion has been added to ensure that SFT (Supervised Fine-Tuning) loss is not used concurrently with the Liger fused JSD loss, indicating a current incompatibility or design choice.
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 adds support for Liger Kernel Loss in the GKD trainer, which is a valuable addition for memory-efficient training. The implementation is mostly well-structured, introducing a new code path in compute_loss for the fused JSD loss. However, I've identified a critical issue with a misplaced assertion that could break existing SFT loss functionality for users not using the Liger kernel. Additionally, there's an opportunity to refactor some duplicated code to enhance maintainability. Please see my detailed comments.

@hjh0119
Copy link
Collaborator Author

hjh0119 commented Nov 16, 2025

/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 introduces support for Liger Kernel for GKD loss calculation, which is a valuable optimization for memory efficiency. The implementation is largely well-executed. My review focuses on a potential bug in handling PEFT teacher models and a structural improvement to enhance code clarity and maintainability.

@hjh0119 hjh0119 merged commit 9388330 into modelscope:main Nov 17, 2025
1 of 2 checks passed
@hjh0119 hjh0119 deleted the gkd-liger branch November 17, 2025 02:36
vx120 pushed a commit to vx120/ms-swift that referenced this pull request Nov 19, 2025
Jintao-Huang pushed a commit that referenced this pull request Nov 20, 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.

3 participants