Home | History | Annotate | Download | only in tfprof
      1 # Copyright 2016 The TensorFlow Authors. All Rights Reserved.
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #     http://www.apache.org/licenses/LICENSE-2.0
      8 #
      9 # Unless required by applicable law or agreed to in writing, software
     10 # distributed under the License is distributed on an "AS IS" BASIS,
     11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 # ==============================================================================
     15 """Model Analyzer.
     16 
     17 Analyze model, including shape, params, time, memory, structure, etc.
     18 """
     19 from __future__ import absolute_import
     20 from __future__ import division
     21 from __future__ import print_function
     22 
     23 
     24 # Import the names here for existing users.
     25 # pylint: disable=unused-import
     26 from tensorflow.python.profiler import tfprof_logger
     27 from tensorflow.python.profiler.model_analyzer import advise as _advise
     28 from tensorflow.python.profiler.model_analyzer import ALL_ADVICE
     29 from tensorflow.python.profiler.model_analyzer import profile as _profile
     30 from tensorflow.python.profiler.model_analyzer import Profiler
     31 from tensorflow.python.profiler.profile_context import ProfileContext
     32 from tensorflow.python.util.deprecation import deprecated
     33 
     34 _DEFAULT_PROFILE_OPTIONS = 0
     35 _DEFAULT_ADVISE_OPTIONS = 0
     36 
     37 # pylint: disable=bad-whitespace
     38 # pylint: disable=bad-continuation
     39 # options examples for profiling API.
     40 #
     41 # Show the parameter statistics of trainable variables.
     42 TRAINABLE_VARS_PARAMS_STAT_OPTIONS = {
     43     'max_depth': 10000,
     44     'min_bytes': 0,
     45     'min_micros': 0,
     46     'min_params': 0,
     47     'min_float_ops': 0,
     48     'order_by': 'name',
     49     'account_type_regexes': [tfprof_logger.TRAINABLE_VARIABLES],
     50     'start_name_regexes': ['.*'],
     51     'trim_name_regexes': [],
     52     'show_name_regexes': ['.*'],
     53     'hide_name_regexes': [],
     54     'account_displayed_op_only': True,
     55     'select': ['params'],
     56     'output': 'stdout',
     57     'dump_to_file': ''  # Deprecated, use 'output': 'file:outfile=<name>'
     58 }
     59 
     60 # Show the number float operations.
     61 FLOAT_OPS_OPTIONS = {
     62     'max_depth': 10000,
     63     'min_bytes': 0,
     64     'min_micros': 0,
     65     'min_params': 0,
     66     'min_float_ops': 1,
     67     'order_by': 'float_ops',
     68     'account_type_regexes': ['.*'],
     69     'start_name_regexes': ['.*'],
     70     'trim_name_regexes': [],
     71     'show_name_regexes': ['.*'],
     72     'hide_name_regexes': [],
     73     'account_displayed_op_only': True,
     74     'select': ['float_ops'],
     75     'output': 'stdout',
     76     'dump_to_file': ''  # Deprecated, use 'output': 'file:outfile=<name>'
     77 }
     78 
     79 
     80 # Show the timing stats and memory demands.
     81 PRINT_ALL_TIMING_MEMORY = {
     82     'max_depth': 10000,
     83     'min_bytes': 1,  # Only >=1
     84     'min_micros': 1,  # Only >=1
     85     'min_params': 0,
     86     'min_float_ops': 0,
     87     'order_by': 'name',
     88     'account_type_regexes': ['.*'],
     89     'start_name_regexes': ['.*'],
     90     'trim_name_regexes': [],
     91     'show_name_regexes': ['.*'],
     92     'hide_name_regexes': [],
     93     'account_displayed_op_only': True,
     94     'select': ['micros', 'bytes'],
     95     'output': 'stdout',
     96     'dump_to_file': ''  # Deprecated, use 'output': 'file:outfile=<name>'
     97 }
     98 
     99 # pylint: enable=bad-whitespace
    100 # pylint: enable=bad-continuation
    101 
    102 
    103 @deprecated('2018-01-01',
    104             'Use `tf.profiler.advise(graph, run_meta, options)`. See README.md')
    105 def advise(graph, run_meta=None, tfprof_options=_DEFAULT_ADVISE_OPTIONS):
    106   return _advise(graph, run_meta, tfprof_options)
    107 
    108 
    109 @deprecated('2018-01-01',
    110             'Use `tf.profiler.profile(graph, run_meta, op_log, cmd, options)`. '
    111             'Build `options` with `tf.profiler.ProfileOptionBuilder`. '
    112             'See README.md for details')
    113 def print_model_analysis(graph,
    114                          run_meta=None,
    115                          op_log=None,
    116                          tfprof_cmd='scope',
    117                          tfprof_options=_DEFAULT_PROFILE_OPTIONS):
    118   return _profile(graph, run_meta, op_log, tfprof_cmd, tfprof_options)
    119