The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
Change cosmos and hydit models to use the native RMSNorm. (#7934)
comfyanonymous9187a0948351
diff --git a/comfy/ldm/cosmos/blocks.py b/comfy/ldm/cosmos/blocks.pyindex 84fd6d839..a12f892d2 100644--- a/comfy/ldm/cosmos/blocks.py+++ b/comfy/ldm/cosmos/blocks.py@@ -23,7 +23,6 @@ from einops import rearrange, repeatfrom einops.layers.torch import Rearrangefrom torch import nn-from comfy.ldm.modules.diffusionmodules.mmdit import RMSNormfrom comfy.ldm.modules.attention import optimized_attention@@ -37,11 +36,11 @@ def apply_rotary_pos_emb(return t_out-def get_normalization(name: str, channels: int, weight_args={}):+def get_normalization(name: str, channels: int, weight_args={}, operations=None):if name == "I":return nn.Identity()elif name == "R":- return RMSNorm(channels, elementwise_affine=True, eps=1e-6, **weight_args)+ return operations.RMSNorm(channels, elementwise_affine=True, eps=1e-6, **weight_args)else:raise ValueError(f"Normalization {name} not found")@@ -120,15 +119,15 @@ class Attention(nn.Module):self.to_q = nn.Sequential(operations.Linear(query_dim, inner_dim, bias=qkv_bias, **weight_args),- get_normalization(qkv_norm[0], norm_dim),+ get_normalization(qkv_norm[0], norm_dim, weight_args=weight_args, operations=operations),)self.to_k = nn.Sequential(operations.Linear(context_dim, inner_dim, bias=qkv_bias, **weight_args),- get_normalization(qkv_norm[1], norm_dim),+ get_normalization(qkv_norm[1], norm_dim, weight_args=weight_args, operations=operations),)self.to_v = nn.Sequential(operations.Linear(context_dim, inner_dim, bias=qkv_bias, **weight_args),- get_normalization(qkv_norm[2], norm_dim),+ get_normalization(qkv_norm[2], norm_dim, weight_args=weight_args, operations=operations),)self.to_out = nn.Sequential(diff --git a/comfy/ldm/cosmos/model.py b/comfy/ldm/cosmos/model.pyindex 06d0baef3..4836e0b69 100644--- a/comfy/ldm/cosmos/model.py+++ b/comfy/ldm/cosmos/model.py@@ -27,8 +27,6 @@ from torchvision import transformsfrom enum import Enumimport logging-from comfy.ldm.modules.diffusionmodules.mmdit import RMSNorm-from .blocks import (FinalLayer,GeneralDITTransformerBlock,@@ -195,7 +193,7 @@ class GeneralDIT(nn.Module):if self.affline_emb_norm:logging.debug("Building affine embedding normalization layer")- self.affline_norm = RMSNorm(model_channels, elementwise_affine=True, eps=1e-6)+ self.affline_norm = operations.RMSNorm(model_channels, elementwise_affine=True, eps=1e-6, device=device, dtype=dtype)else:self.affline_norm = nn.Identity()diff --git a/comfy/ldm/hydit/models.py b/comfy/ldm/hydit/models.pyindex 359f6a965..5ba2b76e0 100644--- a/comfy/ldm/hydit/models.py+++ b/comfy/ldm/hydit/models.py@@ -3,7 +3,7 @@ import torchimport torch.nn as nnimport comfy.ops-from comfy.ldm.modules.diffusionmodules.mmdit import Mlp, TimestepEmbedder, PatchEmbed, RMSNorm+from comfy.ldm.modules.diffusionmodules.mmdit import Mlp, TimestepEmbedder, PatchEmbedfrom comfy.ldm.modules.diffusionmodules.util import timestep_embeddingfrom torch.utils import checkpoint@@ -51,7 +51,7 @@ class HunYuanDiTBlock(nn.Module):if norm_type == "layer":norm_layer = operations.LayerNormelif norm_type == "rms":- norm_layer = RMSNorm+ norm_layer = operations.RMSNormelse:raise ValueError(f"Unknown norm_type: {norm_type}")