feat: Improve LoRA compatibility by adding unified format detection and diffusers-based normalization#14659
Conversation
Summary of ChangesHello @MikukuOvO, 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 SGLang multimodal generation pipeline's ability to handle a wide array of LoRA (Low-Rank Adaptation) checkpoint formats. By implementing a robust detection and normalization layer, it ensures that LoRAs from various sources, which often have inconsistent naming conventions, can be seamlessly integrated and utilized. This change aims to improve the overall reliability and extensibility of LoRA loading without affecting inference performance or accuracy. Highlights
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 introduces a significant improvement to LoRA compatibility in SGLang by adding a unified format adapter. The new lora_format_adapter module intelligently detects and normalizes various LoRA checkpoint formats into a diffusers-compatible structure, which will greatly enhance robustness when loading LoRAs from different ecosystems. The implementation is well-designed, modular, and robustly handles dependencies and potential conversion failures. The integration into the LoRAPipeline is clean, and the addition of a comprehensive regression test suite with real-world checkpoints is a fantastic step to ensure correctness and prevent future regressions. Overall, this is an excellent contribution. I have one critical suggestion for the new test file to ensure its portability.
e2a6ee5 to
84cb1fb
Compare
|
/tag-and-rerun-ci |
python/sglang/multimodal_gen/runtime/pipelines_core/lora_format_adapter.py
Outdated
Show resolved
Hide resolved
python/sglang/multimodal_gen/runtime/pipelines_core/lora_format_adapter.py
Show resolved
Hide resolved
84cb1fb to
477006f
Compare
|
Addressed all the comments. Thanks for the review! |
|
have you tested them locally? |
I've test the |
|
I mean the actual LoRAs with these formats |
3ddf2f7 to
21ba69c
Compare
…xlabs-ai & standard)
…x, non-diffusers support
…, kohya-flux, etc.)
ef4c92b to
65145fa
Compare
…abs-FLUX, Kohya-FLUX, non-diffusers SD, and more
65145fa to
009cbde
Compare
|
I’ve verified that this issue is already fixed after rebasing onto the latest main (from #14543). |
|
/rerun-failed-ci |
1 similar comment
|
/rerun-failed-ci |
…n_eagle3_npu * 'main' of https://github.com/sgl-project/sglang: (25 commits) [NPU] perf update with kvcache nz & w4a8 quant (sgl-project#14423) [PP Prefill][NIXL] Fix PP mode transfer completion tracking to wait for all ranks (sgl-project#15027) Fix GLM-4.6 tool calls don't support streaming output for arguments i… (sgl-project#13989) feature: adding nightly wheel workflow and indexer (sgl-project#14924) [diffusion] feat: Improve LoRA compatibility by adding unified format detection and diffusers-based normalization (sgl-project#14659) [Fix] Disable trtllm moe backend for draft model for a qucik fix (sgl-project#15002) [diffusion] fix: use NDRotaryEmbedding in flux_2 (sgl-project#15034) Mistral Large 3 NVFP4 support (sgl-project#14485) call check_quantized_moe_compatibility after initialize (sgl-project#13876) Add sgl_router_attempt_http_responses_total for single attempt information (sgl-project#15037) Add error code in prometheus metrics and add X-SMG-Error-Code header (sgl-project#15036) Provide more fine grained error reason for reqwest error (sgl-project#15032) Tiny change http router response format to unify (sgl-project#15031) Tiny unify grpc existing error responses into new format (sgl-project#15030) Add `code` field and unify error responses for router (sgl-project#15028) Super tiny remove unused log_request (sgl-project#15035) Fix decode OOM caused by retraction (sgl-project#14939) [CI]Add gb200 runner back (sgl-project#15024) Add a special label for b200 CI runner that can run kernel tests (sgl-project#15033) Fix regression caused by fa3 block_table (sgl-project#15009) ... # Conflicts: # python/sglang/srt/hardware_backend/npu/attention/ascend_backend.py
… detection and diffusers-based normalization (sgl-project#14659)
… detection and diffusers-based normalization (sgl-project#14659)








Motivation
This PR introduces a complete LoRA format adapter for multimodal generation in SGLang.
LoRA checkpoints across the community vary widely in structure (Kohya/A1111, XLabs FLUX, Wan2.1/Comfy, Qwen-Image, Z-Image, etc.). Without a unified adapter, these heterogeneous naming schemes make it difficult to robustly load LoRAs into SGLang’s diffusers-based pipelines.
This PR provides:
Modifications
1. Added
lora_format_adaptermoduleA new adapter module is implemented to provide a two-stage normalization pipeline for external LoRA checkpoints.
Stage 1 — Format Detection
The adapter inspects the raw LoRA
state_dictand classifies it into one of several known ecosystems based on key patterns:This establishes a consistent and extensible abstraction for LoRA format recognition.
Stage 2 — Normalization via diffusers converters
Based on the detected format, the adapter sequentially tries the appropriate converter functions exposed in:
diffusers.loaders.lora_conversion_utilsThe adapter:
dictand(dict, …)return typesThis produces a uniform, diffusers-compatible LoRA state_dict that the SGLang pipeline can reliably consume.
2. Integrated the adapter into LoRA loading pipeline
After LoRA weights are loaded inside
lora_pipeline, the new adapter is now invoked automatically.All external LoRAs now go through a consistent:
detect → normalize
flow before being applied to the model.
This ensures broader compatibility with real-world LoRA checkpoints and reduces pipeline fragility.
3. Added unit tests for the adapter
A standalone regression test suite is added. It:
This provides confidence that the adapter works across diverse LoRA ecosystems and helps catch regressions early.
Accuracy Tests
This PR does not modify model execution or kernels.
Only LoRA loading behavior changes, and tests verify consistent normalization with no accuracy impact.
Benchmarking and Profiling
This PR does not affect runtime inference performance.
Normalization occurs only once at LoRA load time and has negligible overhead.
Checklist