disable_autofuse

Applicability

Product

Supported (√/x)

Atlas 350 Accelerator Card

☓

Atlas A3 training product/Atlas A3 inference product

☓

Atlas A2 training product/Atlas A2 inference product

√

Atlas 200I/500 A2 inference product

☓

Atlas inference product

☓

Atlas training product

☓

Description

When a TensorFlow network runs on the CANN platform, multiple operators are automatically fused based on the graph structure to obtain better performance. If you do not want to perform automatic fusion on some operators, you can use this API to mark them.

Prototype

1
def disable_autofuse()

Parameters

None

Returns

None

Restrictions

The disable_autofuse API needs to be called using the with statement. Only operators in the corresponding scope are not automatically fused.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import tensorflow as tf
from npu_bridge.npu_init import *

a = tf.placeholder(tf.float32, (5, 1))
b = tf.constant([1, 2, 3, 4, 5], dtype=tf.float32, shape=(5, 1))
add_0 = tf.add(a, b)
mul_0 = tf.multiply(add_0, b)

with disable_scope():
    # Operators in this scope are not automatically fused.
    abs_0 = tf.abs(mul_0)
    div_0 = tf.divide(a, abs_0)

with tf.Session() as sess:
    result = sess.run(div_0, feed_dict={a: [[1], [2], [3], [4], [5]]})
    print(result)