NPUStrategy Constructor

Applicability

Product

Supported

Atlas A3 training products/Atlas A3 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas 200I/500 A2 inference products

Atlas inference products

Atlas training products

Description

Constructs an object of class NPUStrategy. NPUStrategy inherits the tf.distribute.Strategy class and can call the native APIs of the base class to implement distributed training in the NPU environment.

Prototype

1
2
class NPUStrategy(distribute_lib.StrategyV1):
    def __init__(self, device="/cpu:0")

Parameters

Parameter

Input/Output

Description

device

Input

Reserved parameter. Currently, only the default value "/cpu:0" is supported. You are advised to leave it unconfigured.

Returns

An object of the NPUStrategy class

Example

Build an instance of NPUStrategy to implement distributed training with NPU environments.

1
2
3
4
5
from npu_bridge.npu_init import *
...
strategy = npu_strategy.NPUStrategy()
# Use strategy to implement distributed training. The usage is the same as that of tf.distribute.Strategy.
...