r"""Pass the input through the encoder layer. Args: hidden_states: the sequence to the encoder layer (required). residual: hidden_states = Mixer(LN(residual))
(
self, hidden_states: Tensor, residual: Optional[Tensor] = None, inference_params=None
)
| 362 | ), "Only LayerNorm and RMSNorm are supported for fused_add_norm" |
| 363 | |
| 364 | def forward( |
| 365 | self, hidden_states: Tensor, residual: Optional[Tensor] = None, inference_params=None |
| 366 | ): |
| 367 | r"""Pass the input through the encoder layer. |
| 368 | |
| 369 | Args: |
| 370 | hidden_states: the sequence to the encoder layer (required). |
| 371 | residual: hidden_states = Mixer(LN(residual)) |
| 372 | """ |
| 373 | if not self.fused_add_norm: |
| 374 | residual = (hidden_states + residual) if residual is not None else hidden_states |
| 375 | hidden_states = self.norm(residual.to(dtype=self.norm.weight.dtype)) |
| 376 | if self.residual_in_fp32: |
| 377 | residual = residual.to(torch.float32) |
| 378 | else: |
| 379 | fused_add_norm_fn = rms_norm_fn if isinstance(self.norm, RMSNorm) else layer_norm_fn |
| 380 | hidden_states, residual = fused_add_norm_fn( |
| 381 | hidden_states, |
| 382 | self.norm.weight, |
| 383 | self.norm.bias, |
| 384 | residual=residual, |
| 385 | prenorm=True, |
| 386 | residual_in_fp32=self.residual_in_fp32, |
| 387 | eps=self.norm.eps, |
| 388 | ) |
| 389 | hidden_states = self.mixer(hidden_states, inference_params=inference_params) |
| 390 | return hidden_states, residual |
| 391 | |
| 392 | def allocate_inference_cache(self, batch_size, max_seqlen, dtype=None, **kwargs): |
| 393 | return self.mixer.allocate_inference_cache(batch_size, max_seqlen, dtype=dtype, **kwargs) |
nothing calls this directly
no outgoing calls
no test coverage detected