[Bugfix] Fix image edit RoPE crash when explicit height/width are provided (#1265)

Signed-off-by: lishunyang <lishunyang12@163.com>
Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
SYLARandHongsheng Liu authored and GitHub committed 2026-02-10 21:18:36 +00:00
1 parent 8228b5a8fe
commit 8a9644c821
3 files changed
+14 -11

No files matched your search

@@ -76,6 +76,10 @@ def edit_image(
# Build extra_body with generation parameters # Build extra_body with generation parameters
extra_body = {} extra_body = {}
if height is not None:
extra_body["height"] = height
if width is not None:
extra_body["width"] = width
if steps is not None: if steps is not None:
extra_body["num_inference_steps"] = steps extra_body["num_inference_steps"] = steps
if guidance_scale is not None: if guidance_scale is not None:
@@ -19,26 +19,25 @@ if [[ ! -f "$INPUT_IMG" ]]; then
exit 1 exit 1
fi fi
IMG_B64=$(base64 -w0 "$INPUT_IMG") REQUEST_JSON_FILE=$(mktemp)
trap 'rm -f "$REQUEST_JSON_FILE"' EXIT
REQUEST_JSON=$( # Pipe base64 into jq via stdin to avoid ARG_MAX limit on large images
jq -n --arg prompt "$PROMPT" --arg img "$IMG_B64" '{ base64 -w0 "$INPUT_IMG" \
| jq -Rs --arg prompt "$PROMPT" '{
messages: [{ messages: [{
role: "user", role: "user",
content: [ content: [
{"type": "text", "text": $prompt}, {"type": "text", "text": $prompt},
{"type": "image_url", "image_url": {"url": ("data:image/png;base64," + $img)}} {"type": "image_url", "image_url": {"url": ("data:image/png;base64," + .)}}
] ]
}], }],
extra_body: { extra_body: {
height: 1024,
width: 1024,
num_inference_steps: 50, num_inference_steps: 50,
guidance_scale: 1, guidance_scale: 1,
seed: 42 seed: 42
} }
}' }' > "$REQUEST_JSON_FILE"
)
echo "Generating edited image..." echo "Generating edited image..."
echo "Server: $SERVER" echo "Server: $SERVER"
@@ -48,7 +47,7 @@ echo "Output: $OUTPUT"
curl -s "$SERVER/v1/chat/completions" \ curl -s "$SERVER/v1/chat/completions" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$REQUEST_JSON" \ -d @"$REQUEST_JSON_FILE" \
| jq -r '.choices[0].message.content[0].image_url.url' \ | jq -r '.choices[0].message.content[0].image_url.url' \
| cut -d',' -f2 \ | cut -d',' -f2 \
| base64 -d > "$OUTPUT" | base64 -d > "$OUTPUT"
@@ -110,9 +110,9 @@ def get_qwen_image_edit_pre_process_func(
if image is not None and not ( if image is not None and not (
isinstance(image, torch.Tensor) and len(image.shape) > 1 and image.shape[1] == latent_channels isinstance(image, torch.Tensor) and len(image.shape) > 1 and image.shape[1] == latent_channels
): ):
image = image_processor.resize(image, height, width) image = image_processor.resize(image, calculated_height, calculated_width)
prompt_image = image prompt_image = image
image = image_processor.preprocess(image, height, width) image = image_processor.preprocess(image, calculated_height, calculated_width)
image = image.unsqueeze(2) image = image.unsqueeze(2)
# Store preprocessed image and prompt image in request # Store preprocessed image and prompt image in request