Files
Model-Optimizer/tests/examples/diffusers/test_cache_diffusion.py
T
Keval Morabia 1ccd945a51 Remove unused diffusers/cache_diffusion/pipeline and cuda-python dependency (#996)
`cuda-python` has mixed license and needs EStaff approval for usage. And
till 0.42, it was only used in
`examples/diffusers/cache_diffusion/pipeline` which has not been updated
in 9 months and not used anymore hence removing.

Also cherry-picked to `release/0.42.0` branch:
https://github.com/NVIDIA/Model-Optimizer/pull/984

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Chores**
* Removed TensorRT/ONNX deployment and inference tooling, related model
export/configuration, and runtime helpers from the cache-optimized
diffusion examples; removed the cuda-python example dependency.
* **Tests**
* Removed the example benchmarking script and its associated benchmark
test.
* **Documentation**
* Strengthened dependency-review, security, and PR guidance; updated PR
template and contributing documentation.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com>
2026-03-07 00:37:19 +05:30

62 lines
2.4 KiB
Python

# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import subprocess
import sys
import pytest
import torch
from _test_utils.examples.models import PIXART_PATH, SXDL_PATH
from _test_utils.examples.run_command import MODELOPT_ROOT
from diffusers import DiffusionPipeline, PixArtAlphaPipeline
sys.path.append(str(MODELOPT_ROOT / "examples/diffusers/cache_diffusion"))
from cache_diffusion import cachify
from cache_diffusion.utils import PIXART_DEFAULT_CONFIG, SDXL_DEFAULT_CONFIG
def test_sdxl_cachify():
pipe = DiffusionPipeline.from_pretrained(
SXDL_PATH,
torch_dtype=torch.float16,
variant="fp16",
use_safetensors=True,
).to("cuda")
cachify.prepare(pipe, SDXL_DEFAULT_CONFIG)
prompt = "A random person with a head that is made of flowers, photo by James C. Leyendecker, \
Afrofuturism, studio portrait, dynamic pose, national geographic photo, retrofuturism, biomorphicy"
generator = torch.Generator(device="cuda").manual_seed(2946901)
pipe(prompt=prompt, generator=generator, num_inference_steps=30).images[0]
# Clear cuda memory as pytest doesnt clear it between tests
del pipe
torch.cuda.empty_cache()
def test_pixart_cachify():
# Fail test if apex is installed
if "apex" in subprocess.check_output(["pip", "list"]).decode("utf-8"):
pytest.xfail("Apex is installed, test is expected to fail")
pipe = PixArtAlphaPipeline.from_pretrained(PIXART_PATH, torch_dtype=torch.float16).to("cuda")
cachify.prepare(pipe, PIXART_DEFAULT_CONFIG)
prompt = "a small cactus with a happy face in the Sahara desert"
generator = torch.Generator(device="cuda").manual_seed(2946901)
pipe(prompt=prompt, generator=generator, num_inference_steps=30).images[0]
# Clear cuda memory as pytest doesnt clear it between tests
del pipe
torch.cuda.empty_cache()