<p dir="auto"><strong>System information</strong></p>
<ul dir="auto">
<li>Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes</li>
<li>OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 16.04</li>
<li>TensorFlow installed from (source or binary): Binary</li>
<li>TensorFlow version (use command below): v1.11.0-rc2-4-gc19e29306c 1.11.0</li>
<li>Python version: 3.6.5</li>
<li>CUDA/cuDNN version: N/A</li>
<li>GPU model and memory: N/A</li>
</ul>
<p dir="auto"><strong>Describe the current behavior</strong><br>
FLOPS is always 0 when specifying batch dimension</p>
<p dir="auto"><strong>Describe the expected behavior</strong><br>
FLOPS should be linear in batch dimension</p>
<p dir="auto"><strong>Code to reproduce the issue</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import tensorflow as tf
g = tf.Graph()
with g.as_default():
    b, m, p, q = 2, 25, 16, 9
    A = tf.Variable(tf.zeros([b, m, p]))
    B = tf.Variable(tf.zeros([b, p, q]))
    C = tf.matmul(A,B)

    flops = tf.profiler.profile(g, options = tf.profiler.ProfileOptionBuilder.float_operation())
    print('FLOP should be', b * m * q * 2 * p)
    print('Calculated FLOP', flops.total_float_ops)"><pre class="notranslate"><code class="notranslate">import tensorflow as tf
g = tf.Graph()
with g.as_default():
    b, m, p, q = 2, 25, 16, 9
    A = tf.Variable(tf.zeros([b, m, p]))
    B = tf.Variable(tf.zeros([b, p, q]))
    C = tf.matmul(A,B)

    flops = tf.profiler.profile(g, options = tf.profiler.ProfileOptionBuilder.float_operation())
    print('FLOP should be', b * m * q * 2 * p)
    print('Calculated FLOP', flops.total_float_ops)
</code></pre></div>
<p dir="auto"><strong>Other info / logs</strong><br>
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.</p>
<h3 dir="auto">System information</h3>
<ul dir="auto">
<li><strong>Have I written custom code (as opposed to using a stock example script provided in TensorFlow)</strong>:yes</li>
<li><strong>OS Platform and Distribution (e.g., Linux Ubuntu 16.04)</strong>:N/A</li>
<li><strong>Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device</strong>:N/A</li>
<li><strong>TensorFlow installed from (source or binary)</strong>:binary</li>
<li><strong>TensorFlow version (use command below)</strong>:v1.10.0-0-g656e7a2b34 1.10.0</li>
<li><strong>Python version</strong>:3.7</li>
<li><strong>Bazel version (if compiling from source)</strong>:N/A</li>
<li><strong>GCC/Compiler version (if compiling from source)</strong>:N/A</li>
<li><strong>CUDA/cuDNN version</strong>:N/A</li>
<li><strong>GPU model and memory</strong>:N/A</li>
<li><strong>Exact command to reproduce</strong>:see below</li>
</ul>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import tensorflow as tf
a = tf.random_normal([1, 100, 100])
b = tf.random_normal([1, 100, 100])
c = tf.matmul(a, b)
tf.profiler.profile(
            tf.get_default_graph(),
            cmd='op',
            options=tf.profiler.ProfileOptionBuilder.float_operation())"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">tensorflow</span> <span class="pl-k">as</span> <span class="pl-s1">tf</span>
<span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">random_normal</span>([<span class="pl-c1">1</span>, <span class="pl-c1">100</span>, <span class="pl-c1">100</span>])
<span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">random_normal</span>([<span class="pl-c1">1</span>, <span class="pl-c1">100</span>, <span class="pl-c1">100</span>])
<span class="pl-s1">c</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">matmul</span>(<span class="pl-s1">a</span>, <span class="pl-s1">b</span>)
<span class="pl-s1">tf</span>.<span class="pl-s1">profiler</span>.<span class="pl-en">profile</span>(
            <span class="pl-s1">tf</span>.<span class="pl-en">get_default_graph</span>(),
            <span class="pl-s1">cmd</span><span class="pl-c1">=</span><span class="pl-s">'op'</span>,
            <span class="pl-s1">options</span><span class="pl-c1">=</span><span class="pl-s1">tf</span>.<span class="pl-s1">profiler</span>.<span class="pl-v">ProfileOptionBuilder</span>.<span class="pl-en">float_operation</span>())</pre></div>
<p dir="auto">The outputs are correct (2M flops) if <code class="notranslate">a</code> and <code class="notranslate">b</code> have shape <code class="notranslate">[100, 100]</code>.<br>
But with 3D inputs, it outputs no flops for matmul.</p>
<p dir="auto">The reason is that for 3D inputs it uses the "BatchMatMul" op which does not have flop statistics implemented.</p>