Skip to content

Commit

Permalink
fix(diffusers): correct usage of Cell.name_cells()
Browse files Browse the repository at this point in the history
  • Loading branch information
townwish4git committed Jun 6, 2024
1 parent d5176fc commit 29bdbb9
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 62 deletions.
8 changes: 4 additions & 4 deletions mindone/diffusers/models/autoencoders/autoencoder_kl.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ def fn_recursive_add_processors(name: str, module: nn.Cell, processors: Dict[str
if hasattr(module, "get_processor"):
processors[f"{name}.processor"] = module.get_processor()

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_add_processors(f"{name}.{sub_name}", child, processors)

return processors

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_add_processors(name, module, processors)

return processors
Expand Down Expand Up @@ -175,10 +175,10 @@ def fn_recursive_attn_processor(name: str, module: nn.Cell, processor):
else:
module.set_processor(processor.pop(f"{name}.processor"))

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_attn_processor(f"{name}.{sub_name}", child, processor)

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_attn_processor(name, module, processor)

# Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.set_default_attn_processor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ def fn_recursive_add_processors(name: str, module: nn.Cell, processors: Dict[str
if hasattr(module, "get_processor"):
processors[f"{name}.processor"] = module.get_processor()

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_add_processors(f"{name}.{sub_name}", child, processors)

return processors

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_add_processors(name, module, processors)

return processors
Expand Down Expand Up @@ -255,10 +255,10 @@ def fn_recursive_attn_processor(name: str, module: nn.Cell, processor):
else:
module.set_processor(processor.pop(f"{name}.processor"))

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_attn_processor(f"{name}.{sub_name}", child, processor)

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_attn_processor(name, module, processor)

def set_default_attn_processor(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ def fn_recursive_add_processors(name: str, module: nn.Cell, processors: Dict[str
if hasattr(module, "get_processor"):
processors[f"{name}.processor"] = module.get_processor()

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_add_processors(f"{name}.{sub_name}", child, processors)

return processors

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_add_processors(name, module, processors)

return processors
Expand Down Expand Up @@ -193,10 +193,10 @@ def fn_recursive_attn_processor(name: str, module: nn.Cell, processor):
else:
module.set_processor(processor.pop(f"{name}.processor"))

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_attn_processor(f"{name}.{sub_name}", child, processor)

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_attn_processor(name, module, processor)

# Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.set_default_attn_processor
Expand Down
8 changes: 4 additions & 4 deletions mindone/diffusers/models/controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,12 +549,12 @@ def fn_recursive_add_processors(name: str, module: nn.Cell, processors: Dict[str
if hasattr(module, "get_processor"):
processors[f"{name}.processor"] = module.get_processor()

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_add_processors(f"{name}.{sub_name}", child, processors)

return processors

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_add_processors(name, module, processors)

return processors
Expand Down Expand Up @@ -585,10 +585,10 @@ def fn_recursive_attn_processor(name: str, module: nn.Cell, processor):
else:
module.set_processor(processor.pop(f"{name}.processor"))

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_attn_processor(f"{name}.{sub_name}", child, processor)

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_attn_processor(name, module, processor)

# Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.set_default_attn_processor
Expand Down
8 changes: 4 additions & 4 deletions mindone/diffusers/models/transformers/prior_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ def fn_recursive_add_processors(name: str, module: nn.Cell, processors: Dict[str
if hasattr(module, "get_processor"):
processors[f"{name}.processor"] = module.get_processor()

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_add_processors(f"{name}.{sub_name}", child, processors)

return processors

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_add_processors(name, module, processors)

return processors
Expand Down Expand Up @@ -212,10 +212,10 @@ def fn_recursive_attn_processor(name: str, module: nn.Cell, processor):
else:
module.set_processor(processor.pop(f"{name}.processor"))

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_attn_processor(f"{name}.{sub_name}", child, processor)

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_attn_processor(name, module, processor)

# Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.set_default_attn_processor
Expand Down
8 changes: 4 additions & 4 deletions mindone/diffusers/models/unets/unet_2d_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,12 +708,12 @@ def fn_recursive_add_processors(name: str, module: nn.Cell, processors: Dict[str
if hasattr(module, "get_processor"):
processors[f"{name}.processor"] = module.get_processor()

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_add_processors(f"{name}.{sub_name}", child, processors)

return processors

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_add_processors(name, module, processors)

return processors
Expand Down Expand Up @@ -746,10 +746,10 @@ def fn_recursive_attn_processor(name: str, module: nn.Cell, processor):
else:
module.set_processor(processor.pop(f"{name}.processor"))

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_attn_processor(f"{name}.{sub_name}", child, processor)

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_attn_processor(name, module, processor)

def set_default_attn_processor(self):
Expand Down
16 changes: 8 additions & 8 deletions mindone/diffusers/models/unets/unet_3d_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,12 @@ def fn_recursive_add_processors(name: str, module: nn.Cell, processors: Dict[str
if hasattr(module, "get_processor"):
processors[f"{name}.processor"] = module.get_processor()

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_add_processors(f"{name}.{sub_name}", child, processors)

return processors

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_add_processors(name, module, processors)

return processors
Expand Down Expand Up @@ -344,10 +344,10 @@ def fn_recursive_attn_processor(name: str, module: nn.Cell, processor):
else:
module.set_processor(processor.pop(f"{name}.processor"))

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_attn_processor(f"{name}.{sub_name}", child, processor)

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_attn_processor(name, module, processor)

def enable_forward_chunking(self, chunk_size: Optional[int] = None, dim: int = 0) -> None:
Expand All @@ -373,21 +373,21 @@ def fn_recursive_feed_forward(module: nn.Cell, chunk_size: int, dim: int):
if hasattr(module, "set_chunk_feed_forward"):
module.set_chunk_feed_forward(chunk_size=chunk_size, dim=dim)

for child in module.name_cells():
for child in module.name_cells().items():
fn_recursive_feed_forward(child, chunk_size, dim)

for module in self.name_cells():
for module in self.name_cells().items():
fn_recursive_feed_forward(module, chunk_size, dim)

def disable_forward_chunking(self):
def fn_recursive_feed_forward(module: nn.Cell, chunk_size: int, dim: int):
if hasattr(module, "set_chunk_feed_forward"):
module.set_chunk_feed_forward(chunk_size=chunk_size, dim=dim)

for child in module.name_cells():
for child in module.name_cells().items():
fn_recursive_feed_forward(child, chunk_size, dim)

for module in self.name_cells():
for module in self.name_cells().items():
fn_recursive_feed_forward(module, None, 0)

# Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.set_default_attn_processor
Expand Down
16 changes: 8 additions & 8 deletions mindone/diffusers/models/unets/unet_i2vgen_xl.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,12 @@ def fn_recursive_add_processors(name: str, module: nn.Cell, processors: Dict[str
if hasattr(module, "get_processor"):
processors[f"{name}.processor"] = module.get_processor()

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_add_processors(f"{name}.{sub_name}", child, processors)

return processors

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_add_processors(name, module, processors)

return processors
Expand Down Expand Up @@ -372,10 +372,10 @@ def fn_recursive_attn_processor(name: str, module: nn.Cell, processor):
else:
module.set_processor(processor.pop(f"{name}.processor"))

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_attn_processor(f"{name}.{sub_name}", child, processor)

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_attn_processor(name, module, processor)

# Copied from diffusers.models.unets.unet_3d_condition.UNet3DConditionModel.enable_forward_chunking
Expand All @@ -402,10 +402,10 @@ def fn_recursive_feed_forward(module: nn.Cell, chunk_size: int, dim: int):
if hasattr(module, "set_chunk_feed_forward"):
module.set_chunk_feed_forward(chunk_size=chunk_size, dim=dim)

for child in module.name_cells():
for child in module.name_cells().items():
fn_recursive_feed_forward(child, chunk_size, dim)

for module in self.name_cells():
for module in self.name_cells().items():
fn_recursive_feed_forward(module, chunk_size, dim)

# Copied from diffusers.models.unets.unet_3d_condition.UNet3DConditionModel.disable_forward_chunking
Expand All @@ -414,10 +414,10 @@ def fn_recursive_feed_forward(module: nn.Cell, chunk_size: int, dim: int):
if hasattr(module, "set_chunk_feed_forward"):
module.set_chunk_feed_forward(chunk_size=chunk_size, dim=dim)

for child in module.name_cells():
for child in module.name_cells().items():
fn_recursive_feed_forward(child, chunk_size, dim)

for module in self.name_cells():
for module in self.name_cells().items():
fn_recursive_feed_forward(module, None, 0)

# Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.set_default_attn_processor
Expand Down
8 changes: 4 additions & 4 deletions mindone/diffusers/models/unets/unet_kandinsky3.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ def fn_recursive_add_processors(name: str, module: nn.Cell, processors: Dict[str
if hasattr(module, "get_processor"):
processors[f"{name}.processor"] = module.get_processor()

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_add_processors(f"{name}.{sub_name}", child, processors)

return processors

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_add_processors(name, module, processors)

return processors
Expand Down Expand Up @@ -192,10 +192,10 @@ def fn_recursive_attn_processor(name: str, module: nn.Cell, processor):
else:
module.set_processor(processor.pop(f"{name}.processor"))

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_attn_processor(f"{name}.{sub_name}", child, processor)

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_attn_processor(name, module, processor)

def set_default_attn_processor(self):
Expand Down
16 changes: 8 additions & 8 deletions mindone/diffusers/models/unets/unet_motion_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,12 +573,12 @@ def fn_recursive_add_processors(name: str, module: nn.Cell, processors: Dict[str
if hasattr(module, "get_processor"):
processors[f"{name}.processor"] = module.get_processor()

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_add_processors(f"{name}.{sub_name}", child, processors)

return processors

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_add_processors(name, module, processors)

return processors
Expand Down Expand Up @@ -609,10 +609,10 @@ def fn_recursive_attn_processor(name: str, module: nn.Cell, processor):
else:
module.set_processor(processor.pop(f"{name}.processor"))

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_attn_processor(f"{name}.{sub_name}", child, processor)

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_attn_processor(name, module, processor)

# Copied from diffusers.models.unets.unet_3d_condition.UNet3DConditionModel.enable_forward_chunking
Expand All @@ -639,10 +639,10 @@ def fn_recursive_feed_forward(module: nn.Cell, chunk_size: int, dim: int):
if hasattr(module, "set_chunk_feed_forward"):
module.set_chunk_feed_forward(chunk_size=chunk_size, dim=dim)

for child in module.name_cells():
for child in module.name_cells().items():
fn_recursive_feed_forward(child, chunk_size, dim)

for module in self.name_cells():
for module in self.name_cells().items():
fn_recursive_feed_forward(module, chunk_size, dim)

# Copied from diffusers.models.unets.unet_3d_condition.UNet3DConditionModel.disable_forward_chunking
Expand All @@ -651,10 +651,10 @@ def fn_recursive_feed_forward(module: nn.Cell, chunk_size: int, dim: int):
if hasattr(module, "set_chunk_feed_forward"):
module.set_chunk_feed_forward(chunk_size=chunk_size, dim=dim)

for child in module.name_cells():
for child in module.name_cells().items():
fn_recursive_feed_forward(child, chunk_size, dim)

for module in self.name_cells():
for module in self.name_cells().items():
fn_recursive_feed_forward(module, None, 0)

# Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.set_default_attn_processor
Expand Down
12 changes: 6 additions & 6 deletions mindone/diffusers/models/unets/unet_spatio_temporal_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ def fn_recursive_add_processors(name: str, module: nn.Cell, processors: Dict[str
if hasattr(module, "get_processor"):
processors[f"{name}.processor"] = module.get_processor()

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_add_processors(f"{name}.{sub_name}", child, processors)

return processors

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_add_processors(name, module, processors)

return processors
Expand Down Expand Up @@ -308,10 +308,10 @@ def fn_recursive_attn_processor(name: str, module: nn.Cell, processor):
else:
module.set_processor(processor.pop(f"{name}.processor"))

for sub_name, child in module.name_cells():
for sub_name, child in module.name_cells().items():
fn_recursive_attn_processor(f"{name}.{sub_name}", child, processor)

for name, module in self.name_cells():
for name, module in self.name_cells().items():
fn_recursive_attn_processor(name, module, processor)

def set_default_attn_processor(self):
Expand Down Expand Up @@ -355,10 +355,10 @@ def fn_recursive_feed_forward(module: nn.Cell, chunk_size: int, dim: int):
if hasattr(module, "set_chunk_feed_forward"):
module.set_chunk_feed_forward(chunk_size=chunk_size, dim=dim)

for child in module.name_cells():
for child in module.name_cells().items():
fn_recursive_feed_forward(child, chunk_size, dim)

for module in self.name_cells():
for module in self.name_cells().items():
fn_recursive_feed_forward(module, chunk_size, dim)

def construct(
Expand Down
Loading

0 comments on commit 29bdbb9

Please sign in to comment.