mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-09-07 18:37:02 +08:00
Switch genmo model to native RMSNorm.
This commit is contained in:
parent
7689917113
commit
923834828a
@ -13,7 +13,6 @@ from comfy.ldm.modules.attention import optimized_attention
|
|||||||
from .layers import (
|
from .layers import (
|
||||||
FeedForward,
|
FeedForward,
|
||||||
PatchEmbed,
|
PatchEmbed,
|
||||||
RMSNorm,
|
|
||||||
TimestepEmbedder,
|
TimestepEmbedder,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -90,10 +89,10 @@ class AsymmetricAttention(nn.Module):
|
|||||||
|
|
||||||
# Query and key normalization for stability.
|
# Query and key normalization for stability.
|
||||||
assert qk_norm
|
assert qk_norm
|
||||||
self.q_norm_x = RMSNorm(self.head_dim, device=device, dtype=dtype)
|
self.q_norm_x = operations.RMSNorm(self.head_dim, eps=1e-5, device=device, dtype=dtype)
|
||||||
self.k_norm_x = RMSNorm(self.head_dim, device=device, dtype=dtype)
|
self.k_norm_x = operations.RMSNorm(self.head_dim, eps=1e-5, device=device, dtype=dtype)
|
||||||
self.q_norm_y = RMSNorm(self.head_dim, device=device, dtype=dtype)
|
self.q_norm_y = operations.RMSNorm(self.head_dim, eps=1e-5, device=device, dtype=dtype)
|
||||||
self.k_norm_y = RMSNorm(self.head_dim, device=device, dtype=dtype)
|
self.k_norm_y = operations.RMSNorm(self.head_dim, eps=1e-5, device=device, dtype=dtype)
|
||||||
|
|
||||||
# Output layers. y features go back down from dim_x -> dim_y.
|
# Output layers. y features go back down from dim_x -> dim_y.
|
||||||
self.proj_x = operations.Linear(dim_x, dim_x, bias=out_bias, device=device, dtype=dtype)
|
self.proj_x = operations.Linear(dim_x, dim_x, bias=out_bias, device=device, dtype=dtype)
|
||||||
|
|||||||
@ -151,14 +151,3 @@ class PatchEmbed(nn.Module):
|
|||||||
|
|
||||||
x = self.norm(x)
|
x = self.norm(x)
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
|
||||||
class RMSNorm(torch.nn.Module):
|
|
||||||
def __init__(self, hidden_size, eps=1e-5, device=None, dtype=None):
|
|
||||||
super().__init__()
|
|
||||||
self.eps = eps
|
|
||||||
self.weight = torch.nn.Parameter(torch.empty(hidden_size, device=device, dtype=dtype))
|
|
||||||
self.register_parameter("bias", None)
|
|
||||||
|
|
||||||
def forward(self, x):
|
|
||||||
return comfy.ldm.common_dit.rms_norm(x, self.weight, self.eps)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user