Esempio n. 1
0
    def profile_operations(self, options):
        """Profile the statistics of the Operation types (e.g. MatMul, Conv2D).

    Args:
      options: A dict of options. See core/profiler/g3doc/options.md.
    Returns:
      a MultiGraphNodeProto that records the results.
    """
        opts = _build_options(options)
        tfprof_node = tfprof_output_pb2.MultiGraphNodeProto()
        tfprof_node.ParseFromString(
            print_mdl.Profile('op'.encode('utf-8'), opts.SerializeToString()))
        return tfprof_node
  def extract_data(self):
#     def parse(stats_str):
#       stats = tfprof_output_pb2.GraphNodeProto()
#       stats.ParseFromString( stats_str )
#       return stats

    if hasattr(self, '_scope_all_stats_str'):
      self._scope_all_stats = tfprof_output_pb2.GraphNodeProto()
      self._scope_all_stats.ParseFromString( self._scope_all_stats_str )
      
    if hasattr(self, '_op_all_stats_str'):
      self._op_all_stats = tfprof_output_pb2.MultiGraphNodeProto()
      self._op_all_stats.ParseFromString( self._op_all_stats_str )
Esempio n. 3
0
  def profile_operations(self, options):
    """Profile the statistics of the Operation types (e.g. MatMul, Conv2D).

    Args:
      options: A dict of options. See core/profiler/g3doc/options.md.
    Returns:
      a MultiGraphNodeProto that records the results.
    """
    opts = _build_options(options)
    tfprof_node = tfprof_output_pb2.MultiGraphNodeProto()
    try:
      tfprof_node.ParseFromString(
          print_mdl.Profile('op'.encode('utf-8'), opts.SerializeToString()))
    except message.DecodeError as e:
      sys.stderr.write('Cannot parse returned proto: %s.\n' % e)
    return tfprof_node
Esempio n. 4
0
  def profile_python(self, options):
    """Profile the statistics of the Python codes.

      By default, it shows the call stack from root. To avoid
      redundant output, you may use options to filter as below
        options['show_name_regexes'] = ['.*my_code.py.*']

    Args:
      options: A dict of options. See core/profiler/g3doc/options.md.
    Returns:
      a MultiGraphNodeProto that records the results.
    """
    opts = _build_options(options)
    tfprof_node = tfprof_output_pb2.MultiGraphNodeProto()
    tfprof_node.ParseFromString(
        print_mdl.Profile('code'.encode('utf-8'), opts.SerializeToString()))
    return tfprof_node
Esempio n. 5
0
def profile(graph=None,
            run_meta=None,
            op_log=None,
            cmd='scope',
            options=_DEFAULT_PROFILE_OPTIONS):
    """Profile model.

    Tutorials and examples can be found in:
    https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/README.md

  Args:
    graph: tf.Graph. If None and eager execution is not enabled, use
        default graph.
    run_meta: optional tensorflow.RunMetadata proto. It is necessary to
        to support run time information profiling, such as time and memory.
    op_log: tensorflow.tfprof.OpLogProto proto. User can assign "types" to
        graph nodes with op_log. "types" allow user to flexibly group and
        account profiles using options['accounted_type_regexes'].
    cmd: string. Either 'op', 'scope', 'graph' or 'code'.
        'op' view organizes profile using operation type. (e.g. MatMul)
        'scope' view organizes profile using graph node name scope.
        'graph' view organizes profile using graph node inputs/outputs.
        'code' view organizes profile using Python call stack.
    options: A dict of options. See core/profiler/g3doc/options.md.
  Returns:
    If cmd is 'scope' or 'graph', returns GraphNodeProto proto.
    If cmd is 'op' or 'code', returns MultiGraphNodeProto proto.
    Side effect: stdout/file/timeline.json depending on options['output']
  """
    if not graph and not context.executing_eagerly():
        graph = ops.get_default_graph()

    if options == _DEFAULT_PROFILE_OPTIONS:
        options = (option_builder.ProfileOptionBuilder.
                   trainable_variables_parameter())
    # pylint: disable=protected-access
    op_log = tfprof_logger.merge_default_with_oplog(graph,
                                                    op_log,
                                                    run_meta,
                                                    add_trace=cmd == 'code')
    # pylint: enable=protected-access

    opts = _build_options(options)

    run_meta_str = run_meta.SerializeToString() if run_meta else b''

    graph_str = _graph_string(graph)

    if cmd == 'code' or cmd == 'op':
        tfprof_node = tfprof_output_pb2.MultiGraphNodeProto()
        ret = print_mdl.PrintModelAnalysis(graph_str, run_meta_str,
                                           op_log.SerializeToString(),
                                           cmd.encode('utf-8'),
                                           opts.SerializeToString())
        try:
            tfprof_node.ParseFromString(ret)
        except message.DecodeError as e:
            sys.stderr.write('Cannot parse returned proto: %s.\n' % e)

    elif cmd == 'graph' or cmd == 'scope':
        tfprof_node = tfprof_output_pb2.GraphNodeProto()
        ret = print_mdl.PrintModelAnalysis(graph_str, run_meta_str,
                                           op_log.SerializeToString(),
                                           cmd.encode('utf-8'),
                                           opts.SerializeToString())
        try:
            tfprof_node.ParseFromString(ret)
        except message.DecodeError as e:
            sys.stderr.write('Cannot parse returned proto: %s.\n' % e)
    else:
        raise errors.InvalidArgumentError(None, None,
                                          'unknown cmd: %s\n' % cmd)

    return tfprof_node
Esempio n. 6
0
def profile(graph,
            run_meta=None,
            op_log=None,
            cmd='scope',
            options=_DEFAULT_PROFILE_OPTIONS):
    """Print model statistics.

    https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/README.md

  Args:
    graph: tf.Graph.
    run_meta: tensorflow::RunMetadata proto. When provided, also shows valid
              timing and memory information when 'select' option contains
              'micros' and 'bytes'.
    op_log: tensorflow::tfprof::OpLogProto proto. users can use this proto to
            group together ops and use a op_type to select the group.
    cmd: string. Either 'op', 'scope', 'graph', 'code'.
         'op' view organize outputs using operation type. (e.g. MatMul)
         'scope' view organize outputs using graph node name scope.
         'graph' view organize outputs using graph node inputs/outputs.
         'code' view organize outputs using Python call stack.
    options: A dict of options. See core/profiler/g3doc/options.md.
  Returns:
    If cmd is 'scope' or 'graph', returns GraphNodeProto proto.
    If cmd is 'op' or 'code', returns MultiGraphNodeProto proto.
    Side effect: stdout/file/timeline.json depending on options['output']
  """
    if options == _DEFAULT_PROFILE_OPTIONS:
        options = (option_builder.ProfileOptionBuilder.
                   trainable_variables_parameter())

    # pylint: disable=protected-access
    op_log = tfprof_logger._merge_default_with_oplog(graph,
                                                     op_log,
                                                     run_meta,
                                                     add_trace=cmd == 'code')
    # pylint: enable=protected-access

    opts = _build_options(options)

    run_meta_str = run_meta.SerializeToString() if run_meta else b''

    if cmd == 'code' or cmd == 'op':
        tfprof_node = tfprof_output_pb2.MultiGraphNodeProto()
        tfprof_node.ParseFromString(
            print_mdl.PrintModelAnalysis(
                graph.as_graph_def(add_shapes=True).SerializeToString(),
                run_meta_str, op_log.SerializeToString(), cmd.encode('utf-8'),
                opts.SerializeToString()))
    elif cmd == 'graph' or cmd == 'scope':
        tfprof_node = tfprof_output_pb2.GraphNodeProto()
        tfprof_node.ParseFromString(
            print_mdl.PrintModelAnalysis(
                graph.as_graph_def(add_shapes=True).SerializeToString(),
                run_meta_str, op_log.SerializeToString(), cmd.encode('utf-8'),
                opts.SerializeToString()))
    else:
        raise errors.InvalidArgumentError(None, None,
                                          'unknown cmd: %s\n' % cmd)

    return tfprof_node