[BugFix] Respect configured precision in Qwen layered path#21980
Open
jy-song-hub wants to merge 12 commits into
Open
[BugFix] Respect configured precision in Qwen layered path#21980jy-song-hub wants to merge 12 commits into
jy-song-hub wants to merge 12 commits into
Conversation
Pass configured VAE and text encoder dtypes into the layered Qwen stage so it no longer hardcodes bf16 for the VAE, text encoder, and preprocessed image tensor.
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Contributor
Author
|
The following unit test was used to validate the correctness of this change. As the code modification is small while the test is relatively lengthy, it is included here instead of in the codebase to avoid unnecessary bloat. |
Contributor
Author
|
@mickqian Please take a look. Thanks~ |
mickqian
reviewed
Apr 4, 2026
mickqian
approved these changes
Apr 4, 2026
Collaborator
|
/tag-and-rerun-ci |
Collaborator
|
/rerun-failed-ci |
1 similar comment
Collaborator
|
/rerun-failed-ci |
Collaborator
|
/tag-and-rerun-ci |
Collaborator
|
/rerun-failed-ci |
1 similar comment
Collaborator
|
/rerun-failed-ci |
Collaborator
|
/tag-and-rerun-ci |
Collaborator
|
/rerun-failed-ci |
1 similar comment
Collaborator
|
/rerun-failed-ci |
Collaborator
|
/tag-and-rerun-ci |
Collaborator
|
/rerun-failed-ci |
1 similar comment
Collaborator
|
/rerun-failed-ci |
Contributor
Author
|
/rerun-failed-ci |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
SGLang already exposes precision control via pipeline config:
However, the layered Qwen image path did not respect these settings. Specifically, in qwen_image.py, the configured precisions were not passed into QwenImageLayeredBeforeDenoisingStage; in qwen_image_layered.py, the implementation instead hardcoded torch.bfloat16 for the VAE, text encoder, and input image tensor.
As a result, this path ignored user-configured precision and implicitly assumed bf16, creating a mismatch with the configuration surface and potentially causing issues on devices or backends without reliable bf16 support.
Modifications
PRECISION_TO_TYPEinpython/sglang/multimodal_gen/runtime/pipelines/qwen_image.py.vae_dtypeandtext_encoder_dtypefromQwenImageLayeredPipeline.create_pipeline_stages()intoQwenImageLayeredBeforeDenoisingStage.QwenImageLayeredBeforeDenoisingStage.__init__()inpython/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/qwen_image_layered.pyto acceptvae_dtypeandtext_encoder_dtype.torch.bfloat16cast for the VAE withvae.to(dtype=vae_dtype).torch.bfloat16cast for the text encoder with.to(dtype=self.text_encoder_dtype).torch.bfloat16cast for the preprocessed image tensor withimage.to(dtype=self.vae_dtype).Accuracy Tests
Tested via unit test. To avoid expanding the PR surface area, the unittest is not included in this PR. For the unittest details, see the code snippet in the comment.
The test was run separately and validates the following old-fails / new-passes behavior:
QwenImageLayeredBeforeDenoisingStagehardcodestorch.bfloat16for the VAE and text encodertorch.bfloat16for the preprocessed image tensorvae_precisionandtext_encoder_precisionsSpeed Tests and Profiling
This change is a correctness fix for dtype selection in the layered Qwen path. It is not intended as a performance optimization, so no dedicated speed benchmark or profiling result is included.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ci