class_docstr: A PyTorch RoBERTa implementation
class_docstr_tok: ["A","PyTorch","RoBERTa","implementation"]
code: def _prune_transformer_layers_and_heads(self, config: Config):
      if config.transformer_layer_to_keep is None:
          config.transformer_layer_to_keep = config.num_encoder_layers
  
      if config.transformer_layer_to_keep != config.num_encoder_layers:
          logger.info(
              f"prune the layers to {config.transformer_layer_to_keep}"
          )
          self.encoder.transformer.layers = (
              self.encoder.transformer.layers[
                  0 : config.transformer_layer_to_keep
              ]
          )
  
      if (
          config.attention_heads_to_keep_per_layer is not None
          or config.attention_heads_to_keep_per_layer_list is not None
      ):
          attention_heads_to_keep_per_layer_list = (
              config.attention_heads_to_keep_per_layer_list
              if config.attention_heads_to_keep_per_layer_list
              is not None
              else [config.attention_heads_to_keep_per_layer]
              * config.transformer_layer_to_keep
          )
  
          assert (
              len(attention_heads_to_keep_per_layer_list)
              == config.transformer_layer_to_keep
          )
          heads_to_prune = {
              i: list(
                  range(
                      config.num_attention_heads
                      - attention_heads_to_keep_per_layer_list[i]
                  )
              )
              for i in range(config.transformer_layer_to_keep)
          }
          for layer_index, heads in heads_to_prune.items():
              logger.info(
                  f"prune layer {layer_index} heads by {len(heads)}"
              )
              if (
                  config.use_linformer_encoder
                  or config.use_selfie_encoder
              ):
                  self.encoder.transformer.layers[
                      layer_index
                  ].attention.prune_multi_linear_heads(heads=heads)
              else:
                  self.encoder.transformer.layers[
                      layer_index
                  ].attention.prune_multi_heads(heads=heads)
  
imports: import logging
  from typing import Dict, List, Optional, Tuple
  import torch
  from pytext import resources
  from pytext.common.constants import Stage, TORCH_VERSION
  from pytext.config import ConfigBase
  from pytext.data.roberta_tensorizer import RoBERTaTensorizer, RoBERTaTokenLevelTensorizer
  from pytext.data.tensorizers import FloatListTensorizer, LabelTensorizer, NumericLabelTensorizer, Tensorizer
  from pytext.models.bert_classification_models import NewBertModel
  from pytext.models.bert_regression_model import NewBertRegressionModel
  from pytext.models.decoders.mlp_decoder import MLPDecoder
  from pytext.models.model import BaseModel
  from pytext.models.module import create_module, Module
  from pytext.models.output_layers import WordTaggingOutputLayer
  from pytext.models.representations.transformer import MultiheadLinearAttention, PassthroughEncoder, PassthroughTransformer, PostEncoder, QuantizedMultiheadLinearAttention, SELFIETransformer, SentenceEncoder
  from pytext.models.representations.transformer_sentence_encoder_base import PoolingMethod, TransformerSentenceEncoderBase
  from pytext.models.utils import normalize_embeddings
  from pytext.torchscript.module import ScriptPyTextEmbeddingModuleIndex, ScriptPyTextModule, ScriptPyTextModuleWithDense
  from pytext.utils.file_io import PathManager
  from pytext.utils.usage import log_class_usage
  from pytorch.text.fb.nn.modules.multihead_attention import MultiheadSelfAttention
  from pytorch.text.fb.nn.modules.transformer import DEFAULT_MAX_SEQUENCE_LENGTH, Transformer, TransformerLayer
  from torch import nn
  from torch.serialization import default_restore_location
  from .r3f_models import R3FConfigOptions, R3FPyTextMixin
label_desc: Use image node_id 2 for calling the RoBERTaEncoder obj's underlying member method code with example usage: obj._prune_transformer_layers_and_heads(config) without return types