CoolFace
Modelpublic

Montey/php-edge

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
utils.py62 linesDownload Raw Back to cache_diffusion
1# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.2# SPDX-License-Identifier: MIT3#4# Permission is hereby granted, free of charge, to any person obtaining a5# copy of this software and associated documentation files (the "Software"),6# to deal in the Software without restriction, including without limitation7# the rights to use, copy, modify, merge, publish, distribute, sublicense,8# and/or sell copies of the Software, and to permit persons to whom the9# Software is furnished to do so, subject to the following conditions:10#11# The above copyright notice and this permission notice shall be included in12# all copies or substantial portions of the Software.13#14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20# DEALINGS IN THE SOFTWARE.21 22import re23 24SDXL_DEFAULT_CONFIG = [25    {26        "wildcard_or_filter_func": lambda name: "up_blocks.2" not in name,27        "select_cache_step_func": lambda step: (step % 2) != 0,28    }29]30 31PIXART_DEFAULT_CONFIG = [32    {33        "wildcard_or_filter_func": lambda name: not re.search(34            r"transformer_blocks\.(2[1-7])\.", name35        ),36        "select_cache_step_func": lambda step: (step % 3) != 0,37    }38]39 40SVD_DEFAULT_CONFIG = [41    {42        "wildcard_or_filter_func": lambda name: "up_blocks.3" not in name,43        "select_cache_step_func": lambda step: (step % 2) != 0,44    }45]46 47SD3_DEFAULT_CONFIG = [48    {49        "wildcard_or_filter_func": lambda name: re.search(50            r"^((?!transformer_blocks\.(1[6-9]|2[0-3])).)*$", name51        ),52        "select_cache_step_func": lambda step: (step % 2) != 0,53    }54]55 56 57def replace_module(parent, name_path, new_module):58    path_parts = name_path.split(".")59    for part in path_parts[:-1]:60        parent = getattr(parent, part)61    setattr(parent, path_parts[-1], new_module)62