[Fix]: Refactor _build_req_from_sampling to use shallow_asdict#13782
[Fix]: Refactor _build_req_from_sampling to use shallow_asdict#13782mickqian merged 4 commits intosgl-project:mainfrom
Conversation
Summary of ChangesHello @cocoshe, 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 addresses a critical bug in the image generation API where user-defined sampling parameters were not being correctly propagated to the underlying request object. The fix involves refactoring the request construction logic to dynamically pass all parameters from the 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 refactors _build_req_from_sampling to use shallow_asdict, which correctly propagates all sampling parameters to the request object. This is a good improvement for maintainability and fixes the issue of some parameters not being passed. However, the current implementation could raise a TypeError if the SamplingParams object contains fields not present in the Req dataclass. I've suggested a more robust implementation that filters the parameters to prevent this issue.
|
You should modify |
Compare to the sglang/python/sglang/multimodal_gen/runtime/entrypoints/openai/image_api.py Lines 108 to 110 in b087ef8 sglang/python/sglang/multimodal_gen/runtime/entrypoints/utils.py Lines 21 to 42 in b087ef8 I think it better to assign the params with |
|
@cocoshe Regarding that, I still think a question should be addressed first:
|
|
hi, could you retry? |
Sure It can be easily done by adding code like: |
|
/tag-and-rerun-ci |
We need this. Could you please rebase? We can merge it once the CI passes. Also, could you check if Req contains all the members of SamplingParams (for example, fps)? |
* 'main' of https://github.com/sgl-project/sglang: (136 commits) fix: unreachable error check in retraction (sgl-project#15433) [sgl-kernel] chore: update deepgemm version (sgl-project#13402) [diffusion] multi-platform: support diffusion on amd and fix encoder loading on MI325 (sgl-project#13760) [amd] Add deterministic all-reduce kernel for AMD (ROCm) (sgl-project#15340) [diffusion] refactor: refactor _build_req_from_sampling to use shallow_asdict (sgl-project#13782) Add customized sampler registration (sgl-project#15423) Update readme (sgl-project#15425) Fix Mindspore model import warning (sgl-project#15287) [Feature] Xiaomi `MiMo-V2-Flash` day0 support (sgl-project#15207) [diffusion] profiling: add bench_serving.py and VBench (sgl-project#15410) [DLLM] Fix dLLM regression (sgl-project#15371) [Deepseek V3.2] Fix Deepseek MTP in V1 mode (sgl-project#15429) chore: update CI_PERMISSIONS (sgl-project#15431) [DLLM] Add CI for diffusion LLMs (sgl-project#14723) Support using different attention backend for draft decoding. (sgl-project#14843) feat(dsv32): better error handling for DeepSeek-v3.2 encoder (sgl-project#14353) tiny fix lint on main (sgl-project#15424) multimodal: precompute hash for MultimodalDataItem (sgl-project#14354) [AMD] Clear pre-built AITER kernels and warmup to prevent segfaults and test timeouts (sgl-project#15318) [Performance] optimize NSA backend metadata computation for multi-step speculative decoding (sgl-project#14781) ...
Motivation
sglang/python/sglang/multimodal_gen/configs/sample/qwenimage.py
Lines 9 to 18 in a90435c
When modify params in model config, for example,
num_inference_steps = 28.But when using the edits endpoint, the original
_build_req_from_samplingcan't deal with it.print
Sampling paramsget theinfer_steps=28, but still use the default50as the num steps.Modifications
Use
shallow_asdictto buildReqwithSamplingParamsChecklist