[diffusion] fix: refactor task resolution logic in benchmark function for multimodal generation (#18948)
This commit is contained in:
@@ -651,40 +651,48 @@ async def benchmark(args):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info(f"Failed to fetch model info: {e}. Using default: {args.model}")
|
logger.info(f"Failed to fetch model info: {e}. Using default: {args.model}")
|
||||||
|
|
||||||
if os.path.exists(args.model):
|
valid_tasks = (
|
||||||
|
"text-to-video",
|
||||||
|
"image-to-video",
|
||||||
|
"video-to-video",
|
||||||
|
"text-to-image",
|
||||||
|
"image-to-image",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Resolve task_name with priority: args.task > local config > HF pipeline_tag
|
||||||
if args.task:
|
if args.task:
|
||||||
task_name = args.task
|
task_name = args.task
|
||||||
else:
|
logger.info(f"Using task from --task: {task_name}")
|
||||||
|
elif os.path.exists(args.model):
|
||||||
config_path = os.path.join(args.model, "config.json")
|
config_path = os.path.join(args.model, "config.json")
|
||||||
if os.path.exists(config_path):
|
if os.path.exists(config_path):
|
||||||
import json
|
|
||||||
|
|
||||||
with open(config_path, "r") as f:
|
with open(config_path, "r") as f:
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
task_name = config.get("pipeline_tag", "text-to-image")
|
task_name = config.get("pipeline_tag", "text-to-image")
|
||||||
|
logger.info(f"Inferred task from local config.json: {task_name}")
|
||||||
else:
|
else:
|
||||||
task_name = "text-to-image" # fallback
|
task_name = "text-to-image"
|
||||||
|
logger.info(f"No config.json found, defaulting task to: {task_name}")
|
||||||
else:
|
else:
|
||||||
task_name = model_info(args.model).pipeline_tag
|
task_name = model_info(args.model).pipeline_tag
|
||||||
|
logger.info(f"Inferred task from HuggingFace pipeline_tag: {task_name}")
|
||||||
|
|
||||||
if args.task != task_name:
|
if task_name not in valid_tasks:
|
||||||
logger.warning(
|
raise ValueError(
|
||||||
f"Task from args {args.task} is different from huggingface pipeline_tag {task_name}, args.task will be ignored!"
|
f"Task '{task_name}' is not a valid multimodal generation task. "
|
||||||
|
f"Use --task to specify one of: {', '.join(valid_tasks)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if task_name in ("text-to-video", "image-to-video", "video-to-video"):
|
if task_name in ("text-to-video", "image-to-video", "video-to-video"):
|
||||||
api_url = f"{args.base_url}/v1/videos"
|
api_url = f"{args.base_url}/v1/videos"
|
||||||
request_func = async_request_video_sglang
|
request_func = async_request_video_sglang
|
||||||
elif task_name in ("text-to-image", "image-to-image"):
|
else: # text-to-image or image-to-image
|
||||||
if task_name == "image-to-image":
|
api_url = (
|
||||||
api_url = f"{args.base_url}/v1/images/edits"
|
f"{args.base_url}/v1/images/edits"
|
||||||
else:
|
if task_name == "image-to-image"
|
||||||
api_url = f"{args.base_url}/v1/images/generations"
|
else f"{args.base_url}/v1/images/generations"
|
||||||
request_func = async_request_image_sglang
|
|
||||||
else:
|
|
||||||
raise ValueError(
|
|
||||||
f"The task name {task_name} of model {args.model} is not a valid task name for multimodal generation. Please check the model path."
|
|
||||||
)
|
)
|
||||||
|
request_func = async_request_image_sglang
|
||||||
|
|
||||||
setattr(args, "task_name", task_name)
|
setattr(args, "task_name", task_name)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user