class_docstr: Inference model implementation for Mixtral models.
class_docstr_tok: ["Inference","model","implementation","for","Mixtral","models","."]
docstr: Executes one (slightly offset) layer of the transformer. This implementation does a peak-ahead
  optimization to fuse the layer norm of the next layer into the current layer.
  
  Arguments:
      layer_idx (int): The index of the layer to execute.
      residual (torch.Tensor): The residual tensor from the previous layer.
      hidden_states (torch.Tensor): The hidden states from the previous layer. This is the
          hidden states after pre normalization.
      ragged_batch_info (RaggedBatchWrapper): The batch metadata.
docstr_tok: ["Executes","one","(","slightly","offset",")","layer","of","the","transformer",".","This","implementation","does","a","peak-ahead","optimization","to","fuse","the","layer","norm","of","the","next","layer","into","the","current","layer",".","Arguments",":","layer_idx","(","int",")",":","The","index","of","the","layer","to","execute",".","residual","(","torch.Tensor",")",":","The","residual","tensor","from","the","previous","layer",".","hidden_states","(","torch.Tensor",")",":","The","hidden","states","from","the","previous","layer",".","This","is","the","hidden","states","after","pre","normalization",".","ragged_batch_info","(","RaggedBatchWrapper",")",":","The","batch","metadata","."]
code: def _forward_transformer(
      self,
      layer_idx: int,
      residual: torch.Tensor,
      hidden_states: torch.Tensor,
      ragged_batch_info: RaggedBatchWrapper,
  ) -> Tuple[torch.Tensor, torch.Tensor]:
      """
      Executes one (slightly offset) layer of the transformer. This implementation does a peak-ahead
      optimization to fuse the layer norm of the next layer into the current layer.
  
      Arguments:
          layer_idx (int): The index of the layer to execute.
          residual (torch.Tensor): The residual tensor from the previous layer.
          hidden_states (torch.Tensor): The hidden states from the previous layer. This is the
              hidden states after pre normalization.
          ragged_batch_info (RaggedBatchWrapper): The batch metadata.
      """
      # TODO(cmikeh2): Distribute ragged_batch_info to all modules
  
      cur_params = self._transformer[layer_idx]
      kv_cache = self.state_manager.get_cache(layer_idx)
  
      hidden_states = self.qkv(hidden_states, cur_params.qkv_w)
      hidden_states = self.attn(
          hidden_states, kv_cache, ragged_batch_info
      )
      hidden_states = self.attn_out(
          hidden_states, cur_params.attn_out_w
      )
  
      if self.tp_size > 1:
          dist.all_reduce(hidden_states, group=self._base_mp_group)
  
      residual, hidden_states = self.norm(
          residual, hidden_states, cur_params.mlp_norm_gamma
      )
  
      hidden_states = self.moe(
          hidden_states,
          ragged_batch_info,
          cur_params.moe_gate,
          cur_params.moe_mlp_1,
          cur_params.moe_mlp_2,
      )
  
      if self.tp_size > 1:
          dist.all_reduce(hidden_states, group=self._base_mp_group)
  
      if layer_idx != self.num_layers - 1:
          next_params = self._transformer[layer_idx + 1]
          residual, hidden_states = self.norm(
              residual, hidden_states, next_params.attn_norm_gamma
          )
      else:
          # On last layer, we just need to perform the residual add. Adding into the residual
          # here is safe.
          residual.add_(hidden_states)
  
      return residual, hidden_states
  
imports: from typing import Iterable, Optional, Tuple
  import torch
  import deepspeed.comm
  from ...allocator import empty_from
  from ...config_v2 import RaggedInferenceEngineConfig
  from ...inference_utils import ActivationType, DtypeEnum
  from ...model_implementations import *
  from ...modules.configs import *
  from ...modules.interfaces import *
  from ...modules import heuristics
  from ...ragged import RaggedBatchWrapper
  from ..inference_model_base import DSModelImplementationConfig, MPType
  from .container import MixtralNonTransformerContainer, MixtralTransformerContainer
label_desc: Use image node_id 19 for calling the MixtralInferenceModel obj's underlying member method code with example usage: obj._forward_transformer(layer_idx, residual, hidden_states, ragged_batch_info) and returns: residual,  hidden_states