|
| 1 | +# coding=utf-8 |
| 2 | +# Copyright 2024 HuggingFace Inc. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +import unittest |
| 17 | + |
| 18 | +from diffusers import ( |
| 19 | + MotionAdapter, |
| 20 | +) |
| 21 | +from diffusers.utils.testing_utils import ( |
| 22 | + enable_full_determinism, |
| 23 | +) |
| 24 | + |
| 25 | + |
| 26 | +enable_full_determinism() |
| 27 | + |
| 28 | + |
| 29 | +class MotionAdapterSingleFileTests(unittest.TestCase): |
| 30 | + model_class = MotionAdapter |
| 31 | + |
| 32 | + def test_single_file_components_version_v1_5(self): |
| 33 | + ckpt_path = "https://huggingface.co/guoyww/animatediff/blob/main/mm_sd_v15.ckpt" |
| 34 | + repo_id = "guoyww/animatediff-motion-adapter-v1-5" |
| 35 | + |
| 36 | + model = self.model_class.from_pretrained(repo_id) |
| 37 | + model_single_file = self.model_class.from_single_file(ckpt_path) |
| 38 | + |
| 39 | + PARAMS_TO_IGNORE = ["torch_dtype", "_name_or_path", "_use_default_values", "_diffusers_version"] |
| 40 | + for param_name, param_value in model_single_file.config.items(): |
| 41 | + if param_name in PARAMS_TO_IGNORE: |
| 42 | + continue |
| 43 | + assert ( |
| 44 | + model.config[param_name] == param_value |
| 45 | + ), f"{param_name} differs between pretrained loading and single file loading" |
| 46 | + |
| 47 | + def test_single_file_components_version_v1_5_2(self): |
| 48 | + ckpt_path = "https://huggingface.co/guoyww/animatediff/blob/main/mm_sd_v15_v2.ckpt" |
| 49 | + repo_id = "guoyww/animatediff-motion-adapter-v1-5-2" |
| 50 | + |
| 51 | + model = self.model_class.from_pretrained(repo_id) |
| 52 | + model_single_file = self.model_class.from_single_file(ckpt_path) |
| 53 | + |
| 54 | + PARAMS_TO_IGNORE = ["torch_dtype", "_name_or_path", "_use_default_values", "_diffusers_version"] |
| 55 | + for param_name, param_value in model_single_file.config.items(): |
| 56 | + if param_name in PARAMS_TO_IGNORE: |
| 57 | + continue |
| 58 | + assert ( |
| 59 | + model.config[param_name] == param_value |
| 60 | + ), f"{param_name} differs between pretrained loading and single file loading" |
| 61 | + |
| 62 | + def test_single_file_components_version_v1_5_3(self): |
| 63 | + ckpt_path = "https://huggingface.co/guoyww/animatediff/blob/main/v3_sd15_mm.ckpt" |
| 64 | + repo_id = "guoyww/animatediff-motion-adapter-v1-5-3" |
| 65 | + |
| 66 | + model = self.model_class.from_pretrained(repo_id) |
| 67 | + model_single_file = self.model_class.from_single_file(ckpt_path) |
| 68 | + |
| 69 | + PARAMS_TO_IGNORE = ["torch_dtype", "_name_or_path", "_use_default_values", "_diffusers_version"] |
| 70 | + for param_name, param_value in model_single_file.config.items(): |
| 71 | + if param_name in PARAMS_TO_IGNORE: |
| 72 | + continue |
| 73 | + assert ( |
| 74 | + model.config[param_name] == param_value |
| 75 | + ), f"{param_name} differs between pretrained loading and single file loading" |
| 76 | + |
| 77 | + def test_single_file_components_version_sdxl_beta(self): |
| 78 | + ckpt_path = "https://huggingface.co/guoyww/animatediff/blob/main/mm_sdxl_v10_beta.ckpt" |
| 79 | + repo_id = "guoyww/animatediff-motion-adapter-sdxl-beta" |
| 80 | + |
| 81 | + model = self.model_class.from_pretrained(repo_id) |
| 82 | + model_single_file = self.model_class.from_single_file(ckpt_path) |
| 83 | + |
| 84 | + PARAMS_TO_IGNORE = ["torch_dtype", "_name_or_path", "_use_default_values", "_diffusers_version"] |
| 85 | + for param_name, param_value in model_single_file.config.items(): |
| 86 | + if param_name in PARAMS_TO_IGNORE: |
| 87 | + continue |
| 88 | + assert ( |
| 89 | + model.config[param_name] == param_value |
| 90 | + ), f"{param_name} differs between pretrained loading and single file loading" |
0 commit comments