docstr: Base class for model layers. Layer is an abstraction that allows to
  provide model description in terms of meta-operators, where each of the
  meta-operators can have different implementations for training,
  evaluation and prediction, that are instantiated later. As an example
  SampledSoftmax can do something related to sampling depending on
  supervision during the training and just apply softmax if it's used for
  prediction/evaluation.
  
  All inputs/outputs from layers are represented as a record (instance of
  schema bounded to blobs) and are accessible through input_record and
  output_schema. If Layer needs to have only a subset of inputs/provides
  subset of outputs during the inference - it should provide
  predict_input_record and predict_output_schema correspondingly (those
  records are expected to be a subset of input_record/output_schema).
  
  Each layer has a list of Tags associated with it, that depends on
  current context and arguments. It's possible to use those tags during
  the instantiation time.
docstr_tok: ["Base","class","for","model","layers",".","Layer","is","an","abstraction","that","allows","to","provide","model","description","in","terms","of","meta-operators",",","where","each","of","the","meta-operators","can","have","different","implementations","for","training",",","evaluation","and","prediction",",","that","are","instantiated","later",".","As","an","example","SampledSoftmax","can","do","something","related","to","sampling","depending","on","supervision","during","the","training","and","just","apply","softmax","if","it","'s","used","for","prediction\/evaluation",".","All","inputs\/outputs","from","layers","are","represented","as","a","record","(","instance","of","schema","bounded","to","blobs",")","and","are","accessible","through","input_record","and","output_schema",".","If","Layer","needs","to","have","only","a","subset","of","inputs\/provides","subset","of","outputs","during","the","inference","-","it","should","provide","predict_input_record","and","predict_output_schema","correspondingly","(","those","records","are","expected","to","be","a","subset","of","input_record\/output_schema",")",".","Each","layer","has","a","list","of","Tags","associated","with","it",",","that","depends","on","current","context","and","arguments",".","It","'s","possible","to","use","those","tags","during","the","instantiation","time","."]
code: def __init__(
      self,
      model,
      prefix,
      input_record,
      predict_input_record_fields=None,
      tags=None,
      **kwargs,
  ):
      """
      Base class for model layers. Layer is an abstraction that allows to
      provide model description in terms of meta-operators, where each of the
      meta-operators can have different implementations for training,
      evaluation and prediction, that are instantiated later. As an example
      SampledSoftmax can do something related to sampling depending on
      supervision during the training and just apply softmax if it's used for
      prediction/evaluation.
  
      All inputs/outputs from layers are represented as a record (instance of
      schema bounded to blobs) and are accessible through input_record and
      output_schema. If Layer needs to have only a subset of inputs/provides
      subset of outputs during the inference - it should provide
      predict_input_record and predict_output_schema correspondingly (those
      records are expected to be a subset of input_record/output_schema).
  
      Each layer has a list of Tags associated with it, that depends on
      current context and arguments. It's possible to use those tags during
      the instantiation time.
  
      """
      self.name = model.next_layer_name(prefix)
      self.model = model
      self.kwargs = kwargs
      self._input_record = input_record
      if predict_input_record_fields:
          if not isinstance(predict_input_record_fields, list):
              predict_input_record_fields = [
                  predict_input_record_fields
              ]
          self._predict_input_record = self._input_record[
              predict_input_record_fields
          ]
      else:
          self._predict_input_record = None
  
      self.request_only = True
      if len(input_record.all_scalars()) == 0:
          self.request_only = False
      for scalar in input_record.all_scalars():
          if not is_request_only_scalar(scalar):
              self.request_only = False
              break
  
      self.precomputation_request_only = False
      self.precomputation_object_only = False
  
      self._output_schema = None
      self._predict_output_schema = None
      self.eval_output_schema = None
      self.tags = set(tags or [])
      self.tags.update(TagContext.current().tags)
      self.params = []
      self._export_output_for_metrics = False
      self._export_params_for_metrics = False
  
imports: import logging
  from collections import namedtuple
  import numpy
  from caffe2.proto import caffe2_pb2
  from caffe2.python import core, schema, scope, utils, workspace
  from caffe2.python.layers.tags import TagContext
label_desc: Use image node_id 1 to create a new ModelLayer object  with example: obj = ModelLayer(model, prefix, input_record, predict_input_record_fields, tags)