[Refactor]Base class for dit pipelines with unified parameter declaration[1/N] (#4225)

Signed-off-by: princepride <wangzhipeng628@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-06-18 17:14:18 +08:00
1 parent dff8cda844
commit f75c437a60
26 files changed
+1026 -1586

No files matched your search

@@ -1,6 +1,8 @@
# Image-To-Image
This example demonstrates how to deploy Qwen-Image-Edit model for online image editing service using vLLM-Omni.
This example demonstrates how to deploy image-to-image models for online image editing service using vLLM-Omni.
Supported models include Qwen-Image-Edit, BAGEL, and other image-to-image pipelines.
For **multi-image** input editing, use **Qwen-Image-Edit-2509** (QwenImageEditPlusPipeline) and send multiple images in the user message content.
@@ -21,6 +23,12 @@ vllm serve Qwen/Qwen-Image-Edit --omni --port 8092
vllm serve Qwen/Qwen-Image-Edit-2509 --omni --port 8092
```
### BAGEL
```bash
vllm serve ByteDance-Seed/BAGEL-7B-MoT --omni --port 8091
```
### Start with Parameters
@@ -119,6 +127,16 @@ python openai_chat_client.py --input input.png --prompt "Convert to oil painting
python openai_chat_client.py --input input1.png input2.png --prompt "Combine these images into a single scene" --output output.png
```
Pass model-specific parameters through `--extra-body` (e.g. for BAGEL):
```bash
python openai_chat_client.py \
--input input.png \
--prompt "Make the scene look like a watercolor painting" \
--server http://localhost:8091 \
--extra-body '{"cfg_text_scale": 4.0, "cfg_img_scale": 1.5}'
```
### Method 4: Using Gradio Demo
```bash
@@ -318,6 +336,9 @@ count, use `size` and `n` rather than `height`, `width`, or
| `layers` | int | 4 | Number of layers (Qwen-Image-Layered) |
| `resolution` | int | 640 | Resolution, 640 or 1024 (Qwen-Image-Layered) |
Models like BAGEL accept additional parameters via `extra_body` (e.g.
`cfg_text_scale`, `cfg_img_scale`). See the [BAGEL recipe](../../../recipes/Bagel/BAGEL-7B-MoT.md) for the full list.
## Response Format
```json
@@ -38,6 +38,7 @@ def edit_image(
guidance_scale: float | None = None,
seed: int | None = None,
negative_prompt: str | None = None,
extra_body: dict | None = None,
) -> bytes | None:
"""Edit an image using the chat completions API.
@@ -51,6 +52,7 @@ def edit_image(
guidance_scale: CFG guidance scale
seed: Random seed
negative_prompt: Negative prompt
extra_body: Additional model-specific params (e.g. cfg_text_scale for BAGEL)
Returns:
Edited image bytes or None if failed
@@ -75,24 +77,26 @@ def edit_image(
]
# Build extra_body with generation parameters
extra_body = {}
merged_extra_body: dict[str, object] = {}
if height is not None:
extra_body["height"] = height
merged_extra_body["height"] = height
if width is not None:
extra_body["width"] = width
merged_extra_body["width"] = width
if steps is not None:
extra_body["num_inference_steps"] = steps
merged_extra_body["num_inference_steps"] = steps
if guidance_scale is not None:
extra_body["guidance_scale"] = guidance_scale
merged_extra_body["guidance_scale"] = guidance_scale
if seed is not None:
extra_body["seed"] = seed
merged_extra_body["seed"] = seed
if negative_prompt:
extra_body["negative_prompt"] = negative_prompt
merged_extra_body["negative_prompt"] = negative_prompt
if extra_body:
merged_extra_body.update(extra_body)
# Build request payload
payload = {"messages": messages}
if extra_body:
payload["extra_body"] = extra_body
payload: dict[str, object] = {"messages": messages}
if merged_extra_body:
payload["extra_body"] = merged_extra_body
# Send request
try:
@@ -121,6 +125,19 @@ def edit_image(
return None
def parse_extra_body(value: str) -> dict:
"""Parse a JSON string into a dict for --extra-body."""
import json
try:
obj = json.loads(value)
except json.JSONDecodeError as e:
raise argparse.ArgumentTypeError(f"--extra-body must be valid JSON: {e}") from e
if not isinstance(obj, dict):
raise argparse.ArgumentTypeError("--extra-body must be a JSON object")
return obj
def main():
parser = argparse.ArgumentParser(description="Qwen-Image-Edit chat client")
parser.add_argument("--input", "-i", required=True, nargs="+", help="Input image path(s)")
@@ -133,6 +150,12 @@ def main():
parser.add_argument("--guidance", type=float, default=7.5, help="Guidance scale")
parser.add_argument("--seed", type=int, default=0, help="Random seed")
parser.add_argument("--negative", help="Negative prompt")
parser.add_argument(
"--extra-body",
type=parse_extra_body,
default=None,
help="JSON object merged into request extra_body, e.g. '{\"cfg_text_scale\": 4.0}'.",
)
args = parser.parse_args()
@@ -152,6 +175,7 @@ def main():
guidance_scale=args.guidance,
seed=args.seed,
negative_prompt=args.negative,
extra_body=args.extra_body,
)
if image_bytes: