From b77e840578d90e09fee985fe45a82accfd818cc7 Mon Sep 17 00:00:00 2001 From: chaofengw Date: Wed, 25 Nov 2026 04:46:01 +0000 Subject: [PATCH 1/4] feat(aiperf-qual): native references for Chinese-CLIP and Stable Video Diffusion Chinese-CLIP scores each query as the logit scale times the cosine, with the Python processor and the 64-token window its E2E uses. Stable Video Diffusion runs Diffusers' pipeline on the initial image alone with the runtime's noise stream. Its testcases state no prompt, so the benchmark sends the empty prompt the Task requires and reads num_steps. The COCO start frames are fitted to the bundle's video size when the request states none, since SVD declares no width or height config. The SVD testcase image paths are now relative to tests/, as the benchmark resolves them. Signed-off-by: chaofengw --- .../models/chinese-clip-vit-base-patch16.yaml | 7 +++ .../config/models/svd-xt-fp32.yaml | 9 +++ apps/aiperf_qual/config/models/svd-xt.yaml | 9 +++ .../tests/test_parity_and_matrix.py | 12 ++++ apps/aiperf_qual/trtmc_aiperf_qual/models.py | 21 +++++-- apps/aiperf_qual/trtmc_aiperf_qual/suites.py | 7 ++- .../trtmc_benchmark/task_adapters.py | 16 +++-- .../tests/test_new_task_operations.py | 6 ++ families/chinese_clip/reference/adapter.py | 48 +++++++++++++++ .../reference/adapter.py | 59 +++++++++++++++++++ .../tests/manifests/svd-xt-fp16-l0.json | 2 +- .../tests/manifests/svd-xt-fp32.json | 2 +- .../tests/manifests/svd-xt.json | 2 +- .../stable_video_diffusion/tests/test_e2e.py | 2 +- 14 files changed, 188 insertions(+), 14 deletions(-) create mode 100644 apps/aiperf_qual/config/models/chinese-clip-vit-base-patch16.yaml create mode 100644 apps/aiperf_qual/config/models/svd-xt-fp32.yaml create mode 100644 apps/aiperf_qual/config/models/svd-xt.yaml create mode 100644 families/chinese_clip/reference/adapter.py create mode 100644 families/stable_video_diffusion/reference/adapter.py diff --git a/apps/aiperf_qual/config/models/chinese-clip-vit-base-patch16.yaml b/apps/aiperf_qual/config/models/chinese-clip-vit-base-patch16.yaml new file mode 100644 index 0000000000..f3d9284361 --- /dev/null +++ b/apps/aiperf_qual/config/models/chinese-clip-vit-base-patch16.yaml @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Imagenette's class prompts are English: the Chinese text tower still ranks them, and the benchmark compares TRTMC +# with the native model on the same prompts (its gate is the regression against native, not an absolute accuracy). +reference: + adapter: families/chinese_clip/reference/adapter.py # the runtime's relevance logit (scale x cosine) diff --git a/apps/aiperf_qual/config/models/svd-xt-fp32.yaml b/apps/aiperf_qual/config/models/svd-xt-fp32.yaml new file mode 100644 index 0000000000..0292dd0c7f --- /dev/null +++ b/apps/aiperf_qual/config/models/svd-xt-fp32.yaml @@ -0,0 +1,9 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# An image-only model: the catalog request's prompt is empty, and the COCO start frames are fitted to the bundle's +# video size (its manifest's image_width x image_height), which the request does not state. +reference: + adapter: families/stable_video_diffusion/reference/adapter.py # Diffusers StableVideoDiffusionPipeline + requirements: families/stable_video_diffusion/requirements.txt + options: {num_frames: 14} # the manifest's video_num_frames diff --git a/apps/aiperf_qual/config/models/svd-xt.yaml b/apps/aiperf_qual/config/models/svd-xt.yaml new file mode 100644 index 0000000000..d1dd905294 --- /dev/null +++ b/apps/aiperf_qual/config/models/svd-xt.yaml @@ -0,0 +1,9 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# An image-only model: the catalog request's prompt is empty, and the COCO start frames are fitted to the bundle's +# video size (its manifest's image_width x image_height), which the request does not state. +reference: + adapter: families/stable_video_diffusion/reference/adapter.py # Diffusers StableVideoDiffusionPipeline + requirements: families/stable_video_diffusion/requirements.txt + options: {num_frames: 25} # the manifest's video_num_frames diff --git a/apps/aiperf_qual/tests/test_parity_and_matrix.py b/apps/aiperf_qual/tests/test_parity_and_matrix.py index 765059783f..b8b762f78a 100644 --- a/apps/aiperf_qual/tests/test_parity_and_matrix.py +++ b/apps/aiperf_qual/tests/test_parity_and_matrix.py @@ -540,6 +540,18 @@ def test_a_fitted_image_covers_the_video_size_and_keeps_its_center(tmp_path): assert _cover_crop(inline, tmp_path / "cache", 16, 32) == fitted # a decoded dataset image column + +def test_a_video_suite_fits_its_images_to_the_bundle_size_when_the_request_states_none(): + from trtmc_aiperf_qual.models import _suite, _video_size + + size = _video_size({"image_width": 1024, "image_height": 576}) + assert size == {"width": 1024, "height": 576} and _video_size({"image_width": 1024}) is None + fitted = {"suite": "s", "version": 1, "source": {"kind": "hf_dataset"}, "selection": {"method": "first", "count": 1}, + "fit_to_request": ["image_path"]} + assert _suite(fitted, "p", None, size)["fit_size"] == {"width": 1024, "height": 576} + plain = {key: value for key, value in fitted.items() if key != "fit_to_request"} + assert "fit_size" not in _suite(plain, "p", None, size) and "fit_size" not in _suite(fitted, "p") + def test_structure_parity_compares_the_written_structure_with_the_native_coordinates(tmp_path): import json diff --git a/apps/aiperf_qual/trtmc_aiperf_qual/models.py b/apps/aiperf_qual/trtmc_aiperf_qual/models.py index 9432f9ab06..362d876eaf 100644 --- a/apps/aiperf_qual/trtmc_aiperf_qual/models.py +++ b/apps/aiperf_qual/trtmc_aiperf_qual/models.py @@ -97,9 +97,11 @@ def _reference_backend(operation: str, task: str) -> str: return "reference" if operation in HF_OPERATIONS and task not in NO_GENERIC_TASKS else "unsupported" -def _suite(reference: str | Mapping[str, Any], profile: str, catalog_request: Mapping[str, Any] | None = None) -> dict[str, Any]: +def _suite(reference: str | Mapping[str, Any], profile: str, catalog_request: Mapping[str, Any] | None = None, + video_size: Mapping[str, int] | None = None) -> dict[str, Any]: """A suite definition; ``catalog_request`` (config/models ``request``) states controls the catalog request - leaves to each side's default, in every suite built on that request (the suite's own request wins).""" + leaves to each side's default, in every suite built on that request (the suite's own request wins). + ``video_size`` (the bundle's frame size) fits a suite's images when its requests state no width and height.""" if isinstance(reference, Mapping): suite = dict(reference) if (suite.get("source") or {}).get("kind") == "catalog_testcase" and not suite["source"].get("profile"): @@ -115,12 +117,20 @@ def _suite(reference: str | Mapping[str, Any], profile: str, catalog_request: Ma on_catalog = suite.get("base_profile") or (suite.get("source") or {}).get("kind") == "catalog_testcase" if catalog_request and on_catalog: suite["request"] = {**dict(catalog_request), **dict(suite.get("request") or {})} + if video_size and suite.get("fit_to_request"): + suite["fit_size"] = dict(video_size) return suite +def _video_size(manifest: Mapping[str, Any]) -> dict[str, int] | None: + """A video bundle's frame size from its catalog manifest (``image_width`` x ``image_height``).""" + width, height = int(manifest.get("image_width") or 0), int(manifest.get("image_height") or 0) + return {"width": width, "height": height} if width > 0 and height > 0 else None + + def model_suite(reference: str | Mapping[str, Any], model: Mapping[str, Any]) -> dict[str, Any]: """``_suite`` for a resolved model (its catalog profile and stated catalog request).""" - return _suite(reference, model["catalog_profile"], model.get("catalog_request")) + return _suite(reference, model["catalog_profile"], model.get("catalog_request"), model.get("video_size")) def _absolute(names: list[Any], definitions: Mapping[str, Any], testcase: Mapping[str, Any], @@ -272,7 +282,7 @@ def resolve_model(profile: str, environment: Environment, root: Path = CONFIG_RO if not item.get("suite_definition"): # a benchmark whose suite each profile states raise ConfigError(f"{profile}: benchmark {item.get('suite')!r} names no suite_definition; the " "profile's own configuration states its suite") - suite = _suite(item["suite_definition"], profile, config.get("request")) + suite = _suite(item["suite_definition"], profile, config.get("request"), _video_size(manifest)) if item.get("request"): # a null removes the suite's field (a Task that declares no such config) request = {**suite.get("request", {}), **item.pop("request")} suite = {**suite, "request": {key: value for key, value in request.items() if value is not None}} @@ -300,7 +310,7 @@ def resolve_model(profile: str, environment: Environment, root: Path = CONFIG_RO if source is None or not isinstance(source.get("suite_definition"), Mapping): raise ConfigError(f"{profile}: performance.suite.from_benchmark {name!r} is not one of its gold suites") policy["suite"] = {**source["suite_definition"], "suite": f"{profile}-{name}-first", "selection": {"method": "first", "count": 1}} - policy["suite"] = _suite(policy["suite"], profile, config.get("request")) + policy["suite"] = _suite(policy["suite"], profile, config.get("request"), _video_size(manifest)) reference_model = reference.pop("model", None) reference_revision = reference.pop("revision", None) or (None if reference_model else revision) size = checkpoint_bytes(reference_model or catalog_model.hf_id, reference_revision) # the native's checkpoint @@ -316,6 +326,7 @@ def resolve_model(profile: str, environment: Environment, root: Path = CONFIG_RO "model": profile, "catalog_profile": profile, "operation": operation, "family": catalog_model.family, **({"qualified_as": base} if base != profile else {}), **({"catalog_request": dict(config["request"])} if config.get("request") else {}), + **({"video_size": _video_size(manifest)} if _video_size(manifest) else {}), "task": catalog_model.task, "candidate": {"bundle": bundle, "precision": candidate_precision, "build": build, "manifest": str(catalog_model.manifest_path), "checkpoint": catalog_model.hf_id, diff --git a/apps/aiperf_qual/trtmc_aiperf_qual/suites.py b/apps/aiperf_qual/trtmc_aiperf_qual/suites.py index 2a6aa91d62..da19126315 100644 --- a/apps/aiperf_qual/trtmc_aiperf_qual/suites.py +++ b/apps/aiperf_qual/trtmc_aiperf_qual/suites.py @@ -797,8 +797,13 @@ def build_suite(definition: Mapping[str, Any], environment: Environment) -> Suit for source_field, request_field in (definition.get("fields") or {}).items(): request[request_field] = record[source_field] if source_field in record else _field(record, source_field) for field in definition.get("fit_to_request", []): # an image at the request's width x height + size = {**(definition.get("fit_size") or {}), **{key: request[key] for key in ("width", "height") + if key in request}} + if "width" not in size or "height" not in size: + raise ConfigError(f"suite {definition['suite']}: fit_to_request needs the request's width and " + "height, or the bundle's video size") request[field] = str(_cover_crop(request[field], Path(environment["hf_datasets_cache"]), - int(request["width"]), int(request["height"]))) + int(size["width"]), int(size["height"]))) if isinstance(request.get("prompt"), str) and (definition.get("prompt_prefix") or definition.get("prompt_suffix")): request["prompt"] = f"{definition.get('prompt_prefix', '')}{request['prompt']}{definition.get('prompt_suffix', '')}" try: # the media go to the shared store once; the request keeps their digests diff --git a/apps/benchmark/trtmc_benchmark/task_adapters.py b/apps/benchmark/trtmc_benchmark/task_adapters.py index 6b14a69a1e..5060685ec8 100644 --- a/apps/benchmark/trtmc_benchmark/task_adapters.py +++ b/apps/benchmark/trtmc_benchmark/task_adapters.py @@ -977,12 +977,20 @@ def _image_generation_request(task: str, case: Mapping[str, Any], root: Path) -> def _initial_image_video_request(case: Mapping[str, Any], root: Path) -> dict[str, Any]: """The Task's inputs (prompt, initial image) and only the generation controls the testcase states; the image is optional here because a testcase may only flag ``initial_image`` and leave the picture to the - benchmark (an AIPerf suite supplies one of the bundle's size).""" - base = _image_generation_request("image_generation", case, root) - request: dict[str, Any] = {"prompt": base["prompt"]} + benchmark (an AIPerf suite supplies one of the bundle's size). An image-only model (Stable Video Diffusion) + states no prompt: its request carries the empty prompt its Task requires.""" + stated = any(case.get(key) for key in ("prompt", "test_prompt", "prompt_file", "prompt_repeat")) or any( + _inputs(case).get(key) for key in ("prompt", "source_text")) + base = _image_generation_request("image_generation", case if stated else {**case, "prompt": "unused"}, root) + request: dict[str, Any] = {"prompt": base["prompt"] if stated else ""} if base["negative_prompt"]: request["negative_prompt"] = base["negative_prompt"] - for name in ("seed", "num_steps", "height", "width"): + steps = _explicit(case, "num_inference_steps", "num_steps") + if steps is not _MISSING and int(steps) > 0: + request["num_steps"] = int(steps) + elif base["num_steps"] > 0: # inputs.num_sampling_steps + request["num_steps"] = base["num_steps"] + for name in ("seed", "height", "width"): if base[name] > 0 or (name == "seed" and base[name] == 0): request[name] = base[name] if base["guidance_scale"] >= 0: diff --git a/apps/benchmark/trtmc_benchmark/tests/test_new_task_operations.py b/apps/benchmark/trtmc_benchmark/tests/test_new_task_operations.py index 13a4dd2392..fd0526a229 100644 --- a/apps/benchmark/trtmc_benchmark/tests/test_new_task_operations.py +++ b/apps/benchmark/trtmc_benchmark/tests/test_new_task_operations.py @@ -94,6 +94,12 @@ def test_image_to_video_requests_send_only_the_stated_controls_and_an_optional_i assert flagged.request == {"prompt": "waves", "seed": 42, "num_steps": 50, "guidance_scale": 5.0} pictured = resolve_task_case("initial_image_text_to_video", {**case, "image": "start.png"}, tmp_path) assert pictured.request["image_path"] == str(tmp_path / "start.png") + # an image-only model's testcase (Stable Video Diffusion): no prompt, its steps named num_steps + image_only = resolve_task_case("initial_image_text_to_video", {"image": "start.png", "seed": 42, "num_steps": 25}, + tmp_path) + assert image_only.request == {"prompt": "", "seed": 42, "num_steps": 25, "image_path": str(tmp_path / "start.png")} + with pytest.raises(BenchmarkError): + resolve_task_case("initial_image_text_to_video", {**case, "num_steps": 25}, tmp_path) def test_structure_requests_name_the_document_and_only_stated_sampling_controls(tmp_path): diff --git a/families/chinese_clip/reference/adapter.py b/families/chinese_clip/reference/adapter.py new file mode 100644 index 0000000000..cbd98ac483 --- /dev/null +++ b/families/chinese_clip/reference/adapter.py @@ -0,0 +1,48 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +"""Chinese-CLIP's Transformers model for ``relevance``, as tests/test_e2e.py runs it: the Python processor +(``use_fast=False``), every query of the request against the one image with the text padded to the 64-token window, +and each pair scored as the logit scale times the cosine of the projected embeddings (the runtime's logit).""" + +from pathlib import Path +from typing import Any, Mapping + + +class Adapter: + def __init__(self, spec: Any, host: Any) -> None: + from transformers import ChineseCLIPModel, ChineseCLIPProcessor + + self.spec, self.host = spec, host + self.processor = ChineseCLIPProcessor.from_pretrained(spec.model, **{**spec.pretrained_kwargs(), + "use_fast": False}) + self.model = host.maybe_compile(ChineseCLIPModel.from_pretrained( + spec.model, **spec.model_kwargs()).to(spec.device, spec.dtype).eval(), spec) + + def invoke(self, request: Mapping[str, Any], artifact_base: Path) -> Any: + import torch + + image = self.host.load_image(str(self.host.required(request, "image_path"))) + queries = [str(query) for query in self.host.required(request, "queries")] + batch = self.processor(text=queries, images=image, padding="max_length", max_length=64, truncation=True, + return_tensors="pt") + pixels = batch["pixel_values"].to(self.spec.device, self.spec.dtype) + tokens = {key: batch[key].to(self.spec.device) for key in ("input_ids", "attention_mask")} + + def score() -> Any: + def embedded(output: Any, name: str) -> Any: + if torch.is_tensor(output): + return output + vector = getattr(output, name, None) + return output.pooler_output if vector is None else vector + + image_vector = embedded(self.model.get_image_features(pixel_values=pixels), "image_embeds")[0].float() + texts = embedded(self.model.get_text_features(**tokens), "text_embeds").float() + image_unit = image_vector / image_vector.norm() + texts = texts / texts.norm(dim=-1, keepdim=True) + return float(self.model.logit_scale.exp()) * (texts @ image_unit) + + scores, model_ms = self.host.timed(score) + values = scores.cpu().tolist() + return self.host.invocation({"scored_pairs": len(values), "scores": values, "queries": queries, + "top_class": max(range(len(values)), key=values.__getitem__)}, model_ms) diff --git a/families/stable_video_diffusion/reference/adapter.py b/families/stable_video_diffusion/reference/adapter.py new file mode 100644 index 0000000000..e55c7a7b9c --- /dev/null +++ b/families/stable_video_diffusion/reference/adapter.py @@ -0,0 +1,59 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +"""Stable Video Diffusion's native pipeline for ``generate_image``, as tests/test_e2e.py runs it: Diffusers' +``StableVideoDiffusionPipeline`` on the initial image alone (an image-only model: a stated prompt is refused, as the +runtime does), at the image's size and the bundle's frame count, with the request's steps, seed and conditioning +controls. The noise follows the runtime's stream: a CPU generator seeded with ``seed`` draws the float32 +conditioning-image noise and then the float32 latents, cast to the pipeline dtype. Frames THWC in 0-1.""" + +from __future__ import annotations + +from pathlib import Path +from typing import Any, Mapping + +import numpy as np + +# The runtime's conditioning controls (its Task config) that the pipeline also takes. +CONTROLS = {"min_guidance_scale": float, "max_guidance_scale": float, "fps": int, "motion_bucket_id": int, + "noise_aug_strength": float} + + +class Adapter: + def __init__(self, spec: Any, host: Any) -> None: + import torch + from diffusers import StableVideoDiffusionPipeline + + self.spec, self.host, self.torch = spec, host, torch + kwargs = {"revision": spec.revision} if spec.revision else {} + self.pipe = StableVideoDiffusionPipeline.from_pretrained(spec.model, torch_dtype=spec.dtype, + **kwargs).to(spec.device) + self.pipe.set_progress_bar_config(disable=True) + host.maybe_compile(self.pipe.unet, spec) + self.frames = int(spec.options["num_frames"]) # the bundle's frame count (its manifest's video_num_frames) + + def invoke(self, request: Mapping[str, Any], artifact_base: Path) -> Any: + torch, host = self.torch, self.host + if str(request.get("prompt") or ""): + raise host.Error("Stable Video Diffusion is conditioned on the initial image only; pass an empty prompt") + image = host.load_image(str(host.required(request, "image_path"))).convert("RGB") + width, height = image.size + seed = int(request.get("seed", 0)) + generator = torch.Generator("cpu").manual_seed(seed) + torch.randn((1, 3, height, width), generator=generator) # the conditioning-image noise draw + factor = self.pipe.vae_scale_factor + latents = torch.randn((1, self.frames, self.pipe.unet.config.in_channels // 2, height // factor, + width // factor), generator=generator).to(self.spec.dtype) + kwargs: dict[str, Any] = { + "image": image, "height": height, "width": width, "num_frames": self.frames, + "decode_chunk_size": self.frames, "generator": torch.Generator("cpu").manual_seed(seed), + "latents": latents, "output_type": "np"} + if int(request.get("num_steps", -1)) > 0: + kwargs["num_inference_steps"] = int(request["num_steps"]) + kwargs.update({name: convert(request[name]) for name, convert in CONTROLS.items() if name in request}) + with torch.no_grad(): + result, model_ms = host.timed(lambda: self.pipe(**kwargs)) + video = np.asarray(result.frames[0], dtype=np.float32) + return host.invocation({**host.tensor_observation(video, artifact_base), "media_type": "video", + "num_frames": int(video.shape[0]), "height": int(video.shape[1]), + "width": int(video.shape[2])}, model_ms) diff --git a/families/stable_video_diffusion/tests/manifests/svd-xt-fp16-l0.json b/families/stable_video_diffusion/tests/manifests/svd-xt-fp16-l0.json index 3c0719c444..7cee8608bc 100644 --- a/families/stable_video_diffusion/tests/manifests/svd-xt-fp16-l0.json +++ b/families/stable_video_diffusion/tests/manifests/svd-xt-fp16-l0.json @@ -15,7 +15,7 @@ { "name": "svd-xt-fp16-l0", "premerge": true, - "image": "test_img.jpeg", + "image": "data/test_img.jpeg", "seed": 7, "num_steps": 25, "reference_precisions": [ diff --git a/families/stable_video_diffusion/tests/manifests/svd-xt-fp32.json b/families/stable_video_diffusion/tests/manifests/svd-xt-fp32.json index 05271def29..4d498ee445 100644 --- a/families/stable_video_diffusion/tests/manifests/svd-xt-fp32.json +++ b/families/stable_video_diffusion/tests/manifests/svd-xt-fp32.json @@ -15,7 +15,7 @@ { "name": "svd-xt-fp32", "premerge": true, - "image": "test_img.jpeg", + "image": "data/test_img.jpeg", "seed": 7, "num_steps": 25, "reference_precisions": [ diff --git a/families/stable_video_diffusion/tests/manifests/svd-xt.json b/families/stable_video_diffusion/tests/manifests/svd-xt.json index 3858c6e07a..49f3fbb36a 100644 --- a/families/stable_video_diffusion/tests/manifests/svd-xt.json +++ b/families/stable_video_diffusion/tests/manifests/svd-xt.json @@ -15,7 +15,7 @@ { "name": "svd-xt-fp16", "premerge": false, - "image": "test_img.jpeg", + "image": "data/test_img.jpeg", "seed": 42, "num_steps": 25, "reference_precisions": [ diff --git a/families/stable_video_diffusion/tests/test_e2e.py b/families/stable_video_diffusion/tests/test_e2e.py index 112534f5b7..7ab13847a0 100644 --- a/families/stable_video_diffusion/tests/test_e2e.py +++ b/families/stable_video_diffusion/tests/test_e2e.py @@ -158,7 +158,7 @@ def _initial_image(manifest: dict, case: dict, tmp_path: Path) -> tuple[Path, np from PIL import Image height, width = int(manifest["image_height"]), int(manifest["image_width"]) - source = Image.open(TEST_ROOT / "data" / case["image"]).convert("RGB") + source = Image.open(TEST_ROOT / case["image"]).convert("RGB") crop_width = min(source.width, round(source.height * width / height)) crop_height = min(source.height, round(crop_width * height / width)) left = (source.width - crop_width) // 2 From 0b237df3c63bf57e09cc87d649c4217f1904820a Mon Sep 17 00:00:00 2001 From: chaofengw Date: Wed, 25 Nov 2026 05:02:12 +0000 Subject: [PATCH 2/4] fix(aiperf-qual): remove the catalog size SVD declares no config for trtmc-bench fills the catalog request's width and height from the manifest, and the worker passes them as Task config, which Stable Video Diffusion does not declare. A null in a suite request now removes the field, as it already does for an absolute benchmark's request; the SVD profiles null width and height, and their start frames are fitted to the bundle's video size. Signed-off-by: chaofengw --- apps/aiperf_qual/config/models/svd-xt-fp32.yaml | 5 +++-- apps/aiperf_qual/config/models/svd-xt.yaml | 5 +++-- apps/aiperf_qual/trtmc_aiperf_qual/suites.py | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/aiperf_qual/config/models/svd-xt-fp32.yaml b/apps/aiperf_qual/config/models/svd-xt-fp32.yaml index 0292dd0c7f..abdcd36c8e 100644 --- a/apps/aiperf_qual/config/models/svd-xt-fp32.yaml +++ b/apps/aiperf_qual/config/models/svd-xt-fp32.yaml @@ -1,9 +1,10 @@ # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -# An image-only model: the catalog request's prompt is empty, and the COCO start frames are fitted to the bundle's -# video size (its manifest's image_width x image_height), which the request does not state. +# An image-only model: the catalog request's prompt is empty. Its runtime declares no width or height config, so the +# catalog request's size (from the manifest) is removed and the COCO start frames are fitted to the bundle's video size. reference: adapter: families/stable_video_diffusion/reference/adapter.py # Diffusers StableVideoDiffusionPipeline requirements: families/stable_video_diffusion/requirements.txt options: {num_frames: 14} # the manifest's video_num_frames +request: {width: null, height: null} diff --git a/apps/aiperf_qual/config/models/svd-xt.yaml b/apps/aiperf_qual/config/models/svd-xt.yaml index d1dd905294..b704710199 100644 --- a/apps/aiperf_qual/config/models/svd-xt.yaml +++ b/apps/aiperf_qual/config/models/svd-xt.yaml @@ -1,9 +1,10 @@ # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -# An image-only model: the catalog request's prompt is empty, and the COCO start frames are fitted to the bundle's -# video size (its manifest's image_width x image_height), which the request does not state. +# An image-only model: the catalog request's prompt is empty. Its runtime declares no width or height config, so the +# catalog request's size (from the manifest) is removed and the COCO start frames are fitted to the bundle's video size. reference: adapter: families/stable_video_diffusion/reference/adapter.py # Diffusers StableVideoDiffusionPipeline requirements: families/stable_video_diffusion/requirements.txt options: {num_frames: 25} # the manifest's video_num_frames +request: {width: null, height: null} diff --git a/apps/aiperf_qual/trtmc_aiperf_qual/suites.py b/apps/aiperf_qual/trtmc_aiperf_qual/suites.py index da19126315..0e377ef47f 100644 --- a/apps/aiperf_qual/trtmc_aiperf_qual/suites.py +++ b/apps/aiperf_qual/trtmc_aiperf_qual/suites.py @@ -794,6 +794,9 @@ def build_suite(definition: Mapping[str, Any], environment: Environment) -> Suit record = {**record, field: str(_square_crop(Path(record[field]), Path(environment["hf_datasets_cache"])))} request = {**base, **(record.get("request") or {})} request.update(definition.get("request") or {}) + # A null removes a field of the catalog request: a control the Task declares no config for (Stable Video + # Diffusion has no width or height; its frames are then fitted to the bundle's video size). + request = {key: value for key, value in request.items() if value is not None} for source_field, request_field in (definition.get("fields") or {}).items(): request[request_field] = record[source_field] if source_field in record else _field(record, source_field) for field in definition.get("fit_to_request", []): # an image at the request's width x height From 9b8f3f898d6ee5f013f79a26f80c8ad1eedb7cd9 Mon Sep 17 00:00:00 2001 From: chaofengw Date: Wed, 25 Nov 2026 05:40:49 +0000 Subject: [PATCH 3/4] fix(aiperf-qual): state SVD's size and guidance the way its Task takes them Revert the null-removal and bundle-size fitting: the request keeps the catalog size, as the request contract requires. The worker treats height and width as the expected frame size of an image-to-video Task that declares no size config, as it does num_frames, and checks the result against them. A per-frame guidance range (min and max guidance scale) states a request's guidance; the SVD profiles state it at the pipeline's defaults. Signed-off-by: chaofengw --- .../config/models/svd-xt-fp32.yaml | 6 ++--- apps/aiperf_qual/config/models/svd-xt.yaml | 6 ++--- .../tests/test_parity_and_matrix.py | 12 --------- .../tests/test_request_contract.py | 4 +++ apps/aiperf_qual/trtmc_aiperf_qual/models.py | 21 ++++----------- apps/aiperf_qual/trtmc_aiperf_qual/suites.py | 12 +++------ apps/benchmark/native/benchmark_worker.cpp | 27 +++++++++++++++---- 7 files changed, 40 insertions(+), 48 deletions(-) diff --git a/apps/aiperf_qual/config/models/svd-xt-fp32.yaml b/apps/aiperf_qual/config/models/svd-xt-fp32.yaml index abdcd36c8e..beb09072db 100644 --- a/apps/aiperf_qual/config/models/svd-xt-fp32.yaml +++ b/apps/aiperf_qual/config/models/svd-xt-fp32.yaml @@ -1,10 +1,10 @@ # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -# An image-only model: the catalog request's prompt is empty. Its runtime declares no width or height config, so the -# catalog request's size (from the manifest) is removed and the COCO start frames are fitted to the bundle's video size. +# An image-only model: the catalog request's prompt is empty and its size is the bundle's. Its guidance is a per-frame +# range, stated here at the pipeline's defaults (the runtime's too) so neither side falls back on its own. reference: adapter: families/stable_video_diffusion/reference/adapter.py # Diffusers StableVideoDiffusionPipeline requirements: families/stable_video_diffusion/requirements.txt options: {num_frames: 14} # the manifest's video_num_frames -request: {width: null, height: null} +request: {min_guidance_scale: 1.0, max_guidance_scale: 3.0} diff --git a/apps/aiperf_qual/config/models/svd-xt.yaml b/apps/aiperf_qual/config/models/svd-xt.yaml index b704710199..4177b33d6a 100644 --- a/apps/aiperf_qual/config/models/svd-xt.yaml +++ b/apps/aiperf_qual/config/models/svd-xt.yaml @@ -1,10 +1,10 @@ # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -# An image-only model: the catalog request's prompt is empty. Its runtime declares no width or height config, so the -# catalog request's size (from the manifest) is removed and the COCO start frames are fitted to the bundle's video size. +# An image-only model: the catalog request's prompt is empty and its size is the bundle's. Its guidance is a per-frame +# range, stated here at the pipeline's defaults (the runtime's too) so neither side falls back on its own. reference: adapter: families/stable_video_diffusion/reference/adapter.py # Diffusers StableVideoDiffusionPipeline requirements: families/stable_video_diffusion/requirements.txt options: {num_frames: 25} # the manifest's video_num_frames -request: {width: null, height: null} +request: {min_guidance_scale: 1.0, max_guidance_scale: 3.0} diff --git a/apps/aiperf_qual/tests/test_parity_and_matrix.py b/apps/aiperf_qual/tests/test_parity_and_matrix.py index b8b762f78a..765059783f 100644 --- a/apps/aiperf_qual/tests/test_parity_and_matrix.py +++ b/apps/aiperf_qual/tests/test_parity_and_matrix.py @@ -540,18 +540,6 @@ def test_a_fitted_image_covers_the_video_size_and_keeps_its_center(tmp_path): assert _cover_crop(inline, tmp_path / "cache", 16, 32) == fitted # a decoded dataset image column - -def test_a_video_suite_fits_its_images_to_the_bundle_size_when_the_request_states_none(): - from trtmc_aiperf_qual.models import _suite, _video_size - - size = _video_size({"image_width": 1024, "image_height": 576}) - assert size == {"width": 1024, "height": 576} and _video_size({"image_width": 1024}) is None - fitted = {"suite": "s", "version": 1, "source": {"kind": "hf_dataset"}, "selection": {"method": "first", "count": 1}, - "fit_to_request": ["image_path"]} - assert _suite(fitted, "p", None, size)["fit_size"] == {"width": 1024, "height": 576} - plain = {key: value for key, value in fitted.items() if key != "fit_to_request"} - assert "fit_size" not in _suite(plain, "p", None, size) and "fit_size" not in _suite(fitted, "p") - def test_structure_parity_compares_the_written_structure_with_the_native_coordinates(tmp_path): import json diff --git a/apps/aiperf_qual/tests/test_request_contract.py b/apps/aiperf_qual/tests/test_request_contract.py index 099f20f5b1..420b93f79a 100644 --- a/apps/aiperf_qual/tests/test_request_contract.py +++ b/apps/aiperf_qual/tests/test_request_contract.py @@ -14,6 +14,10 @@ def test_image_video_controls_must_be_present_but_do_not_apply_to_text_or_speech assert unstated_defaults(image, "generate_image") == [] assert unstated_defaults({**image, "media_type": "video"}, "generate_image") == ["num_frames"] assert unstated_defaults({**image, "num_steps": -1}, "generate_image") == ["num_steps"] + # a per-frame guidance range (Stable Video Diffusion) states the guidance; one end alone does not + ranged = {"num_steps": 25, "min_guidance_scale": 1.0, "max_guidance_scale": 3.0, "height": 576, "width": 1024} + assert unstated_defaults(ranged, "generate_image") == [] + assert unstated_defaults({**ranged, "max_guidance_scale": None}, "generate_image") == ["guidance_scale"] assert unstated_defaults({"prompt": "cat"}, "generate") == [] assert unstated_defaults({"text": "hello"}, "generate_audio") == [] diff --git a/apps/aiperf_qual/trtmc_aiperf_qual/models.py b/apps/aiperf_qual/trtmc_aiperf_qual/models.py index 362d876eaf..9432f9ab06 100644 --- a/apps/aiperf_qual/trtmc_aiperf_qual/models.py +++ b/apps/aiperf_qual/trtmc_aiperf_qual/models.py @@ -97,11 +97,9 @@ def _reference_backend(operation: str, task: str) -> str: return "reference" if operation in HF_OPERATIONS and task not in NO_GENERIC_TASKS else "unsupported" -def _suite(reference: str | Mapping[str, Any], profile: str, catalog_request: Mapping[str, Any] | None = None, - video_size: Mapping[str, int] | None = None) -> dict[str, Any]: +def _suite(reference: str | Mapping[str, Any], profile: str, catalog_request: Mapping[str, Any] | None = None) -> dict[str, Any]: """A suite definition; ``catalog_request`` (config/models ``request``) states controls the catalog request - leaves to each side's default, in every suite built on that request (the suite's own request wins). - ``video_size`` (the bundle's frame size) fits a suite's images when its requests state no width and height.""" + leaves to each side's default, in every suite built on that request (the suite's own request wins).""" if isinstance(reference, Mapping): suite = dict(reference) if (suite.get("source") or {}).get("kind") == "catalog_testcase" and not suite["source"].get("profile"): @@ -117,20 +115,12 @@ def _suite(reference: str | Mapping[str, Any], profile: str, catalog_request: Ma on_catalog = suite.get("base_profile") or (suite.get("source") or {}).get("kind") == "catalog_testcase" if catalog_request and on_catalog: suite["request"] = {**dict(catalog_request), **dict(suite.get("request") or {})} - if video_size and suite.get("fit_to_request"): - suite["fit_size"] = dict(video_size) return suite -def _video_size(manifest: Mapping[str, Any]) -> dict[str, int] | None: - """A video bundle's frame size from its catalog manifest (``image_width`` x ``image_height``).""" - width, height = int(manifest.get("image_width") or 0), int(manifest.get("image_height") or 0) - return {"width": width, "height": height} if width > 0 and height > 0 else None - - def model_suite(reference: str | Mapping[str, Any], model: Mapping[str, Any]) -> dict[str, Any]: """``_suite`` for a resolved model (its catalog profile and stated catalog request).""" - return _suite(reference, model["catalog_profile"], model.get("catalog_request"), model.get("video_size")) + return _suite(reference, model["catalog_profile"], model.get("catalog_request")) def _absolute(names: list[Any], definitions: Mapping[str, Any], testcase: Mapping[str, Any], @@ -282,7 +272,7 @@ def resolve_model(profile: str, environment: Environment, root: Path = CONFIG_RO if not item.get("suite_definition"): # a benchmark whose suite each profile states raise ConfigError(f"{profile}: benchmark {item.get('suite')!r} names no suite_definition; the " "profile's own configuration states its suite") - suite = _suite(item["suite_definition"], profile, config.get("request"), _video_size(manifest)) + suite = _suite(item["suite_definition"], profile, config.get("request")) if item.get("request"): # a null removes the suite's field (a Task that declares no such config) request = {**suite.get("request", {}), **item.pop("request")} suite = {**suite, "request": {key: value for key, value in request.items() if value is not None}} @@ -310,7 +300,7 @@ def resolve_model(profile: str, environment: Environment, root: Path = CONFIG_RO if source is None or not isinstance(source.get("suite_definition"), Mapping): raise ConfigError(f"{profile}: performance.suite.from_benchmark {name!r} is not one of its gold suites") policy["suite"] = {**source["suite_definition"], "suite": f"{profile}-{name}-first", "selection": {"method": "first", "count": 1}} - policy["suite"] = _suite(policy["suite"], profile, config.get("request"), _video_size(manifest)) + policy["suite"] = _suite(policy["suite"], profile, config.get("request")) reference_model = reference.pop("model", None) reference_revision = reference.pop("revision", None) or (None if reference_model else revision) size = checkpoint_bytes(reference_model or catalog_model.hf_id, reference_revision) # the native's checkpoint @@ -326,7 +316,6 @@ def resolve_model(profile: str, environment: Environment, root: Path = CONFIG_RO "model": profile, "catalog_profile": profile, "operation": operation, "family": catalog_model.family, **({"qualified_as": base} if base != profile else {}), **({"catalog_request": dict(config["request"])} if config.get("request") else {}), - **({"video_size": _video_size(manifest)} if _video_size(manifest) else {}), "task": catalog_model.task, "candidate": {"bundle": bundle, "precision": candidate_precision, "build": build, "manifest": str(catalog_model.manifest_path), "checkpoint": catalog_model.hf_id, diff --git a/apps/aiperf_qual/trtmc_aiperf_qual/suites.py b/apps/aiperf_qual/trtmc_aiperf_qual/suites.py index 0e377ef47f..de0a84c5c6 100644 --- a/apps/aiperf_qual/trtmc_aiperf_qual/suites.py +++ b/apps/aiperf_qual/trtmc_aiperf_qual/suites.py @@ -597,6 +597,8 @@ def unstated_defaults(request: Mapping[str, Any], operation: str | None = None) required = ["num_steps", "guidance_scale", "height", "width"] if request.get("media_type") == "video": required.append("num_frames") + if all(request.get(name) not in (None, "") for name in ("min_guidance_scale", "max_guidance_scale")): + required.remove("guidance_scale") # a per-frame guidance range (Stable Video Diffusion) states it problems += [field for field in required if request.get(field) in (None, "") and field not in problems] problems += [field for field in ("num_steps", "height", "width", "num_frames") if field in request and (not isinstance(request[field], (int, float)) @@ -794,19 +796,11 @@ def build_suite(definition: Mapping[str, Any], environment: Environment) -> Suit record = {**record, field: str(_square_crop(Path(record[field]), Path(environment["hf_datasets_cache"])))} request = {**base, **(record.get("request") or {})} request.update(definition.get("request") or {}) - # A null removes a field of the catalog request: a control the Task declares no config for (Stable Video - # Diffusion has no width or height; its frames are then fitted to the bundle's video size). - request = {key: value for key, value in request.items() if value is not None} for source_field, request_field in (definition.get("fields") or {}).items(): request[request_field] = record[source_field] if source_field in record else _field(record, source_field) for field in definition.get("fit_to_request", []): # an image at the request's width x height - size = {**(definition.get("fit_size") or {}), **{key: request[key] for key in ("width", "height") - if key in request}} - if "width" not in size or "height" not in size: - raise ConfigError(f"suite {definition['suite']}: fit_to_request needs the request's width and " - "height, or the bundle's video size") request[field] = str(_cover_crop(request[field], Path(environment["hf_datasets_cache"]), - int(size["width"]), int(size["height"]))) + int(request["width"]), int(request["height"]))) if isinstance(request.get("prompt"), str) and (definition.get("prompt_prefix") or definition.get("prompt_suffix")): request["prompt"] = f"{definition.get('prompt_prefix', '')}{request['prompt']}{definition.get('prompt_suffix', '')}" try: # the media go to the shared store once; the request keeps their digests diff --git a/apps/benchmark/native/benchmark_worker.cpp b/apps/benchmark/native/benchmark_worker.cpp index 8c98444e6e..a9de6ab5ba 100644 --- a/apps/benchmark/native/benchmark_worker.cpp +++ b/apps/benchmark/native/benchmark_worker.cpp @@ -2896,10 +2896,25 @@ Json run_generate_image(const trtmc::Model& model, const Json& request, const Ti observe_video); } if (initial) { - // The frame count is fixed by the bundle; a stated one must be what it produced. - const auto expected = request.value("num_frames", std::int64_t{0}); + // The frame count is fixed by the bundle; a stated one must be what it produced. So is the + // frame size of a Task that declares no height or width config (Stable Video Diffusion). const auto task = task_for_operation(model, task_id); - const auto config = sdk_config(request, task.config_fields(), + const auto fields = task.config_fields(); + const auto declares = [&](std::string_view name) { + return std::any_of(fields.begin(), fields.end(), + [&](const auto& field) { return field.name == name; }); + }; + const bool fixed_size = !declares("height") && !declares("width"); + Json inputs = request; + std::vector> expected{ + {"num_frames", request.value("num_frames", std::int64_t{0})}}; + if (fixed_size) + for (const char* name : {"height", "width"}) + if (inputs.contains(name)) { + expected.emplace_back(name, inputs.at(name).get()); + inputs.erase(name); + } + const auto config = sdk_config(inputs, fields, {"prompt", "image_path", "image_paths", "num_frames", "batch_size", "media_type", "_artifact_prefix"}); return run( @@ -2910,8 +2925,10 @@ Json run_generate_image(const trtmc::Model& model, const Json& request, const Ti }, [&](const trtmc::VideoGenerationResult& result) { auto output = observe_video(result); - if (expected > 0 && output.at("num_frames").get() != expected) - throw std::runtime_error("generated video does not have the stated num_frames"); + for (const auto& [name, value] : expected) + if (value > 0 && output.at(name).get() != value) + throw std::runtime_error("generated video does not have the stated " + + name); return output; }); } From 827ca7c099640031ddb9641a352be7f05c1f2545 Mon Sep 17 00:00:00 2001 From: chaofengw Date: Wed, 25 Nov 2026 05:43:45 +0000 Subject: [PATCH 4/4] fix(chinese_clip): lowercase the native reference's text as the runtime does Signed-off-by: chaofengw --- families/chinese_clip/reference/adapter.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/families/chinese_clip/reference/adapter.py b/families/chinese_clip/reference/adapter.py index cbd98ac483..6018e8f0db 100644 --- a/families/chinese_clip/reference/adapter.py +++ b/families/chinese_clip/reference/adapter.py @@ -2,8 +2,9 @@ # SPDX-License-Identifier: Apache-2.0 """Chinese-CLIP's Transformers model for ``relevance``, as tests/test_e2e.py runs it: the Python processor -(``use_fast=False``), every query of the request against the one image with the text padded to the 64-token window, -and each pair scored as the logit scale times the cosine of the projected embeddings (the runtime's logit).""" +(``use_fast=False``), lowercasing as the runtime does, every query of the request against the one image with the +text padded to the 64-token window, and each pair scored as the logit scale times the cosine of the projected +embeddings (the runtime's logit).""" from pathlib import Path from typing import Any, Mapping @@ -14,8 +15,10 @@ def __init__(self, spec: Any, host: Any) -> None: from transformers import ChineseCLIPModel, ChineseCLIPProcessor self.spec, self.host = spec, host + # The checkpoint ships no tokenizer config, and Transformers' BertTokenizer does not lowercase by default: + # its vocabulary is lowercase, so a capital such as "English" would become [UNK]. The runtime lowercases. self.processor = ChineseCLIPProcessor.from_pretrained(spec.model, **{**spec.pretrained_kwargs(), - "use_fast": False}) + "use_fast": False, "do_lower_case": True}) self.model = host.maybe_compile(ChineseCLIPModel.from_pretrained( spec.model, **spec.model_kwargs()).to(spec.device, spec.dtype).eval(), spec)