Skip to content

Commit 44cb56c

Browse files
author
gushiqiao
committed
fix gradio
1 parent 9d11341 commit 44cb56c

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

app/gradio_demo.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,11 @@ def get_quant_scheme(quant_detected, quant_op_val):
16521652
"use_image_encoder": False if "wan2.2" in model_cls else True,
16531653
"rope_type": "flashinfer" if apply_rope_with_cos_sin_cache_inplace else "torch",
16541654
"t5_lazy_load": lazy_load,
1655+
"bucket_shape": {
1656+
"0.667": [[480, 832], [544, 960], [720, 960]],
1657+
"1.500": [[832, 480], [960, 544], [960, 720]],
1658+
"1.000": [[480, 480], [576, 576], [720, 720]],
1659+
},
16551660
}
16561661

16571662
# If it's a qwen_image model, override related configuration

app/gradio_demo_zh.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,11 @@ def get_quant_scheme(quant_detected, quant_op_val):
16521652
"use_image_encoder": False if "wan2.2" in model_cls else True,
16531653
"rope_type": "flashinfer" if apply_rope_with_cos_sin_cache_inplace else "torch",
16541654
"t5_lazy_load": lazy_load,
1655+
"bucket_shape": {
1656+
"0.667": [[480, 832], [544, 960], [720, 960]],
1657+
"1.500": [[832, 480], [960, 544], [960, 720]],
1658+
"1.000": [[480, 480], [576, 576], [720, 720]],
1659+
},
16551660
}
16561661

16571662
# 如果是 qwen_image 模型,覆盖相关配置

lightx2v/models/runners/default_runner.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@
2222
torch_device_module = getattr(torch, AI_DEVICE)
2323

2424

25-
def resize_image(img, resolution):
25+
def resize_image(img, resolution, bucket_shape=None):
2626
assert resolution in ["480p", "540p", "720p"]
27-
bucket_config = {
28-
0.667: np.array([[480, 832], [544, 960], [720, 1280]], dtype=np.int64),
29-
1.500: np.array([[832, 480], [960, 544], [1280, 720]], dtype=np.int64),
30-
1.000: np.array([[480, 480], [576, 576], [720, 720]], dtype=np.int64),
31-
}
27+
if bucket_shape is None:
28+
bucket_config = {
29+
0.667: np.array([[480, 832], [544, 960], [720, 1280]], dtype=np.int64),
30+
1.500: np.array([[832, 480], [960, 544], [1280, 720]], dtype=np.int64),
31+
1.000: np.array([[480, 480], [576, 576], [960, 960]], dtype=np.int64),
32+
}
33+
else:
34+
bucket_config = {}
35+
for ratio, resolutions in bucket_shape.items():
36+
bucket_config[float(ratio)] = np.array(resolutions, dtype=np.int64)
3237
ori_height = img.shape[-2]
3338
ori_weight = img.shape[-1]
3439
ori_ratio = ori_height / ori_weight
@@ -246,7 +251,7 @@ def read_image_input(self, img_path):
246251
self.input_info.original_size = img_ori.size
247252

248253
if self.config.get("resize_mode", None) == "adaptive":
249-
img, h, w = resize_image(img, self.config.get("resolution", "480p"))
254+
img, h, w = resize_image(img, self.config.get("resolution", "480p"), self.config.get("bucket_shape", None))
250255
logger.info(f"resize_image target_h: {h}, target_w: {w}")
251256
patched_h = h // self.config["vae_stride"][1] // self.config["patch_size"][1]
252257
patched_w = w // self.config["vae_stride"][2] // self.config["patch_size"][2]

0 commit comments

Comments
 (0)