class_docstr: Openai transformer, as per https://blog.openai.com/language-unsupervised/.
  Default parameters are the ones for their pretrained model.
  
  Parameters
  ----------
  vocab_size: ``int`` (optional, default: 40990)
      The size of the vocabulary, including the positional encodings.
  n_ctx: ``int`` (optional, default: 512)
      The number of positional encodings.
  embedding_dim: ``int`` (optional, default: 768)
      The dimension of the output embeddings.
  num_heads: ``int`` (optional, default: 12)
      How many "heads" the attention has.
  num_layers: ``int`` (optional, default: 12)
      How many layers of "blocks" the transformer has.
  embedding_dropout_probability: ``float`` (optional, default: 0.1)
      Dropout for the embedding.
  attention_dropout_probability: ``float`` (optional, default: 0.1)
      Dropout for attention.
  residual_dropout_probability: ``float`` (optional, default: 0.1)
      Dropout for residual
  activation_function: ``str`` (optional, default: ``'gelu'``)
      Activation function for the multi-layer perceptron.
  model_path: ``str`` (optional, default: ``None``)
      A tar.gz file containing serialized model weights. If supplied,
      the weights will be loaded from that file.
  requires_grad: ``bool`` (optional, default: ``False``)
      If true, the transformer will be fine-tuneable.
class_docstr_tok: ["Openai","transformer",",","as","per","https",":","\/\/blog.openai.com\/language-unsupervised\/",".","Default","parameters","are","the","ones","for","their","pretrained","model",".","Parameters","--","--","--","--","--","vocab_size",":","``","int","``","(","optional",",","default",":","40990",")","The","size","of","the","vocabulary",",","including","the","positional","encodings",".","n_ctx",":","``","int","``","(","optional",",","default",":","512",")","The","number","of","positional","encodings",".","embedding_dim",":","``","int","``","(","optional",",","default",":","768",")","The","dimension","of","the","output","embeddings",".","num_heads",":","``","int","``","(","optional",",","default",":","12",")","How","many","``","heads","''","the","attention","has",".","num_layers",":","``","int","``","(","optional",",","default",":","12",")","How","many","layers","of","``","blocks","''","the","transformer","has",".","embedding_dropout_probability",":","``","float","``","(","optional",",","default",":","0.1",")","Dropout","for","the","embedding",".","attention_dropout_probability",":","``","float","``","(","optional",",","default",":","0.1",")","Dropout","for","attention",".","residual_dropout_probability",":","``","float","``","(","optional",",","default",":","0.1",")","Dropout","for","residual","activation_function",":","``","str","``","(","optional",",","default",":","``","'gelu","'","``",")","Activation","function","for","the","multi-layer","perceptron",".","model_path",":","``","str","``","(","optional",",","default",":","``","None","``",")","A","tar.gz","file","containing","serialized","model","weights",".","If","supplied",",","the","weights","will","be","loaded","from","that","file",".","requires_grad",":","``","bool","``","(","optional",",","default",":","``","False","``",")","If","true",",","the","transformer","will","be","fine-tuneable","."]
code: def dump_weights(self, output_dir, num_pieces=10):
      output_path.mkdir(
          exist_ok=True, parents=True
      )  # pylint: disable=no-member
  
      named_parameters = list(self.named_parameters())
  
      # embedding weights get special treatment
      _, array = named_parameters[0]
      num_bpe = self.vocab_size - self.n_ctx
      byte_pair_embeddings = array[:num_bpe]
      positional_embeddings = array[num_bpe:]
  
      arrays = [
          positional_embeddings.numpy().ravel(),
          byte_pair_embeddings.numpy().ravel(),
      ]
      shapes = [positional_embeddings.shape, byte_pair_embeddings.shape]
      names = ["model/we:0"]
  
      for param_name, tensor in named_parameters[1:]:
          param_name = "h{param_name}"  # 'h0.attn.c_attn.w'
          parts = param_name.split(".")  # ['h0', 'attn', 'c_attn', 'w']
          name = (
              "model/" + "/".join(parts) + ":0"
          )  # 'model/h0/attn/c_attn/w:0'
          array = tensor.numpy().ravel()
  
          arrays.append(array)
          shapes.append(list(tensor.shape))
          names.append(name)
  
      # write out the arrays
      big_array = np.concatenate(arrays)
      total_size = len(big_array)
      batch_size = math.ceil(total_size / num_pieces)
  
      for i in range(num_pieces):
          filename = output_path / "params_{i}.npy"
          start = i * batch_size
          end = start + batch_size
          subarray = big_array[start:end]
  
          np.save(filename, subarray)
  
      # write out the shapes
      with open(output_path / "params_shapes.json", "w") as shapes_file:
          json.dump(shapes, shapes_file)
  
imports: from __future__ import with_statement
  from __future__ import division
  from __future__ import absolute_import
  import copy
  import io
  import json
  import logging
  import math
  import re
  import tarfile
  import numpy
  import torch
  from torch.nn import Parameter
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.file_utils import cached_path
  from allennlp.common.from_params import FromParams
  from io import open
label_desc: Use image node_id 4 for calling the OpenaiTransformer obj's underlying member method code with example usage: obj.dump_weights(output_dir, num_pieces) without return types