|
31 | 31 | class MuseGlimmerScaleFreeRMSNorm(nn.Module): |
32 | 32 | """RMSNorm with no learned scale, evaluated in float32.""" |
33 | 33 |
|
34 | | - def __init__(self, eps: float): |
| 34 | + def __init__(self, normalized_size: int, eps: float): |
35 | 35 | super().__init__() |
| 36 | + # ONNX RMSNormalization requires a 1-D scale matching the normalized |
| 37 | + # axis. A scalar happens to work on CPU but is invalid for CUDA kernels. |
| 38 | + self._scale = [1.0] * normalized_size |
36 | 39 | self._eps = eps |
37 | 40 |
|
38 | 41 | def forward(self, op: OpBuilder, hidden_states: ir.Value): |
39 | 42 | hidden_f32 = op.Cast(hidden_states, to=ir.DataType.FLOAT) |
40 | 43 | normalized = op.RMSNormalization( |
41 | 44 | hidden_f32, |
42 | | - 1.0, |
| 45 | + op.Constant(value_floats=self._scale), |
43 | 46 | epsilon=self._eps, |
44 | 47 | stash_type=1, |
45 | 48 | axis=-1, |
@@ -106,7 +109,7 @@ def __init__(self, config: ArchitectureConfig): |
106 | 109 | config.num_attention_heads * config.head_dim, |
107 | 110 | bias=False, |
108 | 111 | ) |
109 | | - self.qk_norm = MuseGlimmerScaleFreeRMSNorm(config.rms_norm_eps) |
| 112 | + self.qk_norm = MuseGlimmerScaleFreeRMSNorm(config.head_dim, config.rms_norm_eps) |
110 | 113 |
|
111 | 114 | def forward( |
112 | 115 | self, |
@@ -261,7 +264,7 @@ def __init__(self, config: ArchitectureConfig): |
261 | 264 | config.hidden_size, |
262 | 265 | config.pad_token_id, |
263 | 266 | ) |
264 | | - self.embed_norm = MuseGlimmerScaleFreeRMSNorm(config.rms_norm_eps) |
| 267 | + self.embed_norm = MuseGlimmerScaleFreeRMSNorm(config.hidden_size, config.rms_norm_eps) |
265 | 268 | self.layers = nn.ModuleList( |
266 | 269 | [MuseGlimmerTextDecoderLayer(config) for _ in range(config.num_hidden_layers)] |
267 | 270 | ) |
@@ -462,7 +465,9 @@ def __init__(self, config: ArchitectureConfig): |
462 | 465 | config.hidden_size, |
463 | 466 | bias=False, |
464 | 467 | ) |
465 | | - self.perception_emb_norm = MuseGlimmerScaleFreeRMSNorm(config.rms_norm_eps) |
| 468 | + self.perception_emb_norm = MuseGlimmerScaleFreeRMSNorm( |
| 469 | + config.hidden_size, config.rms_norm_eps |
| 470 | + ) |
466 | 471 |
|
467 | 472 | def forward( |
468 | 473 | self, |
@@ -490,7 +495,7 @@ def __init__(self, config: ArchitectureConfig): |
490 | 495 | config.hidden_size, |
491 | 496 | config.pad_token_id, |
492 | 497 | ) |
493 | | - self.embed_norm = MuseGlimmerScaleFreeRMSNorm(config.rms_norm_eps) |
| 498 | + self.embed_norm = MuseGlimmerScaleFreeRMSNorm(config.hidden_size, config.rms_norm_eps) |
494 | 499 | self._hidden_size = config.hidden_size |
495 | 500 | self._image_token_id = config.image_token_id or 200092 |
496 | 501 | self._video_token_id = getattr(config, "video_token_id", 200091) |
|
0 commit comments