---
title: NPUStrategy构造函数
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/TensorFlowCommercial/latest/migration/tfmigr1/tfmigr1_tfadapi_0050.html
sourcePath: /source/zh/TensorFlowCommercial/900/migration/tfmigr1/tfmigr1_tfadapi_0050.html
indexId: 38a06f6c8e6ce201bbb6a4bafb92fe959a9365d3fe1e0aceec5086f3c76692e479
---
# NPUStrategy构造函数

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| Atlas 350 加速卡 | √ |
| Atlas A3 训练系列产品 / Atlas A3 推理系列产品 | √ |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | √ |
| Atlas 200I/500 A2 推理产品 | ☓ |
| Atlas 推理系列产品 | ☓ |
| Atlas 训练系列产品 | √ |


#### 功能说明

NPUStrategy类的构造函数。NPUStrategy继承了tf.distribute.Strategy类，可以调用基类的原生接口，用于在NPU环境中实现分布式训练。


#### 函数原型

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


#### 参数说明

| 参数名 | 输入/输出 | 描述 |
| --- | --- | --- |
| device | 输入 | 预留参数，当前仅支持配置为默认值"/cpu:0"，推荐不配置。 |


#### 返回值

返回NPUStrategy类对象。


#### 调用示例

构建NPUStrategy实例，在NPU环境实现分布式训练：

```
from npu_bridge.npu_init import *
strategy = npu_strategy.NPUStrategy()
#使用strategy实现分布式训练。使用方式与tf.distribute.Strategy相同
```
