class_docstr: Transformer class.
class_docstr_tok: ["Transformer","class","."]
docstr: Compute the number of transformer layers resident on the current rank.
code: def get_num_layers(self, num_layers):
      """Compute the number of transformer layers resident on the current rank."""
      if parallel_state.get_pipeline_model_parallel_world_size() > 1:
          if self.model_type == ModelType.encoder_and_decoder:
              assert (
                  parallel_state.get_pipeline_model_parallel_split_rank()
                  is not None
              )
              num_ranks_in_encoder = (
                  parallel_state.get_pipeline_model_parallel_split_rank()
              )
              num_ranks_in_decoder = (
                  parallel_state.get_pipeline_model_parallel_world_size()
                  - num_ranks_in_encoder
              )
              if self.layer_type == LayerType.encoder:
                  assert (
                      num_layers % num_ranks_in_encoder == 0
                  ), "num_layers must be divisible by number of ranks given to encoder"
              elif self.layer_type == LayerType.decoder:
                  assert (
                      num_layers % num_ranks_in_decoder == 0
                  ), "num_layers must be divisible by number of ranks given to decoder"
              else:
                  raise ValueError(
                      f"Unknown layer type {self.layer_type}"
                  )
  
              if parallel_state.is_pipeline_stage_before_split():
                  num_layers = num_layers // num_ranks_in_encoder
              else:
                  num_layers = num_layers // num_ranks_in_decoder
          elif self.model_type == ModelType.encoder_or_decoder:
              assert (
                  num_layers
                  % parallel_state.get_pipeline_model_parallel_world_size()
                  == 0
              ), "num_layers must be divisible by pipeline_model_parallel_size"
              num_layers = (
                  num_layers
                  // parallel_state.get_pipeline_model_parallel_world_size()
              )
  
      return num_layers
  
imports: from contextlib import nullcontext
  from typing import Any, Callable, Optional
  import torch
  import torch.nn
  from einops import rearrange
  from nemo.collections.common.parts.adapter_modules import LinearAdapterConfig
  from nemo.collections.nlp.modules.common.megatron.adapters.parallel_adapters import AdapterName, ParallelLinearAdapterConfig, ParallelLinearAdapterWeightTyingConfig
  from nemo.collections.nlp.modules.common.megatron.attention import ParallelAttention, ParallelChunkedCrossAttention
  from nemo.collections.nlp.modules.common.megatron.fused_bias_dropout_add import bias_dropout_add, bias_dropout_add_fused_inference, bias_dropout_add_fused_train, dropout_add
  from nemo.collections.nlp.modules.common.megatron.fused_layer_norm import get_layer_norm
  from nemo.collections.nlp.modules.common.megatron.layer_norm_1p import LayerNorm1P, LPLayerNorm
  from nemo.collections.nlp.modules.common.megatron.layer_type import LayerType
  from nemo.collections.nlp.modules.common.megatron.mlp import ParallelMLP, SwitchMLP
  from nemo.collections.nlp.modules.common.megatron.module import MegatronModule
  from nemo.collections.nlp.modules.common.megatron.utils import ApexGuardDefaults
  from nemo.collections.nlp.parts import utils_funcs
  from nemo.core import adapter_mixins
  from nemo.utils import logging
label_desc: Use image node_id 3 for calling the ParallelTransformer obj's underlying member method code with example usage: obj.get_num_layers(num_layers) and returns: num_layers