Skip to content

Conversation

@mickqian
Copy link
Collaborator

@mickqian mickqian commented Nov 24, 2025

this pr add support for LoRA with Wan-series, in:

  1. openai-api
  2. python api

for Qwen-Image and Flux, lora could be merged, but the accuracy needs further checking

TODO

  1. verify LoRA with image-model
  2. add TestLoRAWorkflow

Motivation

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

@github-actions github-actions bot added lora diffusion SGLang Diffusion labels Nov 24, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @mickqian, 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 significantly enhances the diffusion model inference capabilities by integrating LoRA support. It provides a robust mechanism for managing LoRA adapters and their weights through new API endpoints and a refactored scheduler, allowing for more flexible and efficient model customization during generation. The changes focus on enabling dynamic LoRA application without impacting the core model architecture.

Highlights

  • LoRA Support for Diffusion Models: Introduced comprehensive support for LoRA (Low-Rank Adaptation) in diffusion models, allowing dynamic loading, merging, and unmerging of LoRA weights during inference.
  • New API Endpoints for LoRA Management: Added new FastAPI endpoints (/set_lora_adapter, /merge_lora_weights, /unmerge_lora_weights) to enable external control over LoRA adapters and weights.
  • Scheduler Integration for LoRA Operations: The core scheduler now processes control messages for LoRA operations, forwarding requests to the worker for execution, ensuring seamless integration into the existing inference pipeline.
  • Refactored LoRA Layer Implementation: Simplified the internal LoRA layer (lora/linear.py) by removing training-specific logic and parameters, streamlining it for inference-only use cases.
  • Improved Logging and Argument Handling: Enhanced logging for image saving operations and introduced new command-line arguments (--lora-path, --lora-nickname) for configuring LoRA settings.
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 introduces support for LoRA (Low-Rank Adaptation) for inference, which is a significant feature enhancement. The changes are well-distributed across different components, including the main generator entrypoint, API endpoints, model layers, and the scheduler. A key part of this change is the removal of training-related LoRA code to streamline the implementation for inference. My review focuses on improving code maintainability by reducing duplication in the newly added LoRA control methods and removing some leftover debugging code. Overall, this is a solid contribution towards more flexible model adaptation at runtime.

Comment on lines 138 to 154
method = reqs.get("method")
if method == "set_lora_adapter":
self.worker.set_lora_adapter(
reqs["lora_nickname"],
reqs["lora_path"],
)
output_batch = {"status": "ok"}
elif method == "unmerge_lora_weights":
self.worker.unmerge_lora_weights()
output_batch = {"status": "ok"}
elif method == "merge_lora_weights":
self.worker.merge_lora_weights()
output_batch = {"status": "ok"}
else:
error_msg = f"Unknown method: {method}"
logger.error(error_msg)
output_batch = {"status": "error", "message": error_msg}
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 if/elif/else chain for handling different control methods is functional but can become cumbersome to maintain as more methods are added. Using a dispatch dictionary (mapping method names to handler functions) would make this code more scalable, readable, and align with the open/closed principle.

Suggested change
method = reqs.get("method")
if method == "set_lora_adapter":
self.worker.set_lora_adapter(
reqs["lora_nickname"],
reqs["lora_path"],
)
output_batch = {"status": "ok"}
elif method == "unmerge_lora_weights":
self.worker.unmerge_lora_weights()
output_batch = {"status": "ok"}
elif method == "merge_lora_weights":
self.worker.merge_lora_weights()
output_batch = {"status": "ok"}
else:
error_msg = f"Unknown method: {method}"
logger.error(error_msg)
output_batch = {"status": "error", "message": error_msg}
method = reqs.get("method")
handlers = {
"set_lora_adapter": lambda: self.worker.set_lora_adapter(
reqs["lora_nickname"], reqs["lora_path"]
),
"unmerge_lora_weights": self.worker.unmerge_lora_weights,
"merge_lora_weights": self.worker.merge_lora_weights,
}
handler = handlers.get(method)
if handler:
handler()
output_batch = {"status": "ok"}
else:
error_msg = f"Unknown method: {method}"
logger.error(error_msg)
output_batch = {"status": "error", "message": error_msg}

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Nov 25, 2025
@mickqian
Copy link
Collaborator Author

/tag-and-rerun-ci

@mickqian mickqian changed the title WIP: [diffusion] feat: support LoRA [diffusion] feat: support LoRA Nov 25, 2025
@mickqian mickqian merged commit dfd7ab9 into sgl-project:main Nov 25, 2025
5 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion documentation Improvements or additions to documentation lora run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant