AttributeError: 'list' object has no attribute '__module__'. #7866
-
Bug DescriptionI planned to design a class that inherits DDIMPipeline and tracks the intermiate images, so I rewrtite the init() function as follows: class LocalDDIMPipeline(DDIMPipeline):
def __init__(self, unet, scheduler, extract_time):
super().__init__(unet, scheduler)
self.scheduler_forward = DDIMInverseScheduler.from_config(scheduler.config)
if isinstance(extract_time, list):
self.extract_time_list = extract_time
self.extract_time_count = len(extract_time)
else:
raise TypeError(f"The type of extract_time is not a List")
self.register_modules(unet=unet, scheduler=scheduler, extract_time=extract_time) However, when I run the following code, pipeline = LocalDDIMPipeline(
unet = model,
scheduler = DDIMScheduler.from_pretrained(args.save_path, subfolder="scheduler"),
extract_time=[100],
) and the terminal raised this error: Traceback (most recent call last):
File "/media/data3/wengzh/CodeRef/Pruning-Influence-via-Hardness/ddpm_prune.py", line 143, in <module>
pipeline = LocalDDIMPipeline(
File "/media/data3/wengzh/CodeRef/Pruning-Influence-via-Hardness/Local_ddim_pipeline.py", line 20, in __init__
self.register_modules(unet=unet, scheduler=scheduler, extract_time=extract_time)
File "/media/data3/wengzh/CodeRef/Pruning-Influence-via-Hardness/diffusers/pipelines/pipeline_utils.py", line 485, in register_modules
library = module.__module__.split(".")[0]
AttributeError: 'list' object has no attribute '__module__'. Did you mean: '__mul__'? The function register_modules() is as follows: def register_modules(self, **kwargs):
for name, module in kwargs.items():
# retrieve library
if module is None or isinstance(module, (tuple, list)) and module[0] is None:
register_dict = {name: (None, None)}
else:
library, class_name = _fetch_class_library_tuple(module)
register_dict = {name: (library, class_name)}
# save model index config
self.register_to_config(**register_dict)
# set models
setattr(self, name, module) This code could be found in pipeline_utils.py in diffusers |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Have you examined the callbacks page in the docs to be able to do this? |
Beta Was this translation helpful? Give feedback.
-
IMO the error is pretty much self explanatory, but I'm more curious in what version of
in the actual code it's an empty line: Also, this Anyway, why are you registering |
Beta Was this translation helpful? Give feedback.
yeah, more than inappropriate, is that all the args of the
__init__
are processed as modules when you inherit from a pipeline.So don't use the
__init__
to set variables that you need, do this in the__call__
method, you can learn from examples in the community pipelines, like this one.Also better to load the pipeline with
from_pretrained
instead, that way you get all the additional features thatdiffusers
gives if you need them.So for example:
If you're using the scheduler that's with the model, you don't need to provide the scheduler.