diff --git "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225.md" "b/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225.md" deleted file mode 100644 index b2c94fdbf2bd3ab187a2d717a8d16a32b34b2dc2..0000000000000000000000000000000000000000 --- "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225.md" +++ /dev/null @@ -1,8229 +0,0 @@ -# PyTorch API支持清单 -- [Tensors](#Tensorsmd) -- [Generators](#Generatorsmd) -- [Random sampling](#Random-samplingmd) -- [Serialization](#Serializationmd) -- [Math operations](#Math-operationsmd) -- [Utilities](#Utilitiesmd) -- [Other](#Othermd) -- [torch.Tensor](#torch-Tensormd) -- [Layers \(torch.nn\)](#Layers-torch-nnmd) -- [Functions\(torch.nn.functional\)](#Functionstorch-nn-functionalmd) -- [torch.distributed](#torch-distributedmd) -- [NPU和CUDA功能对齐](#NPU和CUDA功能对齐md) -

Tensors

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

序号

-

API名称

-

是否支持(PyTorch1.5.0)

-

1

-

torch.is_tensor

-

-

2

-

torch.is_storage

-

-

3

-

torch.is_complex

-

-

4

-

torch.is_floating_point

-

-

5

-

torch.set_default_dtype

-

-

6

-

torch.get_default_dtype

-

-

7

-

torch.set_default_tensor_type

-

-

8

-

torch.numel

-

-

9

-

torch.set_printoptions

-

-

10

-

torch.set_flush_denormal

-

-

11

-

torch.tensor

-

-

12

-

torch.sparse_coo_tensor

-

-

13

-

torch.as_tensor

-

-

14

-

torch.as_strided

-

-

15

-

torch.from_numpy

-

-

16

-

torch.zeros

-

-

17

-

torch.zeros_like

-

-

18

-

torch.ones

-

-

19

-

torch.ones_like

-

-

20

-

torch.arange

-

-

21

-

torch.range

-

-

22

-

torch.linspace

-

-

23

-

torch.logspace

-

-

24

-

torch.eye

-

-

25

-

torch.empty

-

-

26

-

torch.empty_like

-

-

27

-

torch.empty_strided

-

-

28

-

torch.full

-

-

29

-

torch.full_like

-

-

30

-

torch.quantize_per_tensor

-

-

31

-

torch.quantize_per_channel

-

-

32

-

torch.cat

-

-

33

-

torch.chunk

-

-

34

-

torch.gather

-

-

35

-

torch.index_select

-

-

36

-

torch.masked_select

-

-

37

-

torch.narrow

-

-

38

-

torch.nonzero

-

-

39

-

torch.reshape

-

-

40

-

torch.split

-

-

41

-

torch.squeeze

-

-

42

-

torch.stack

-

-

43

-

torch.t

-

-

44

-

torch.take

-

-

45

-

torch.transpose

-

-

46

-

torch.unbind

-

-

47

-

torch.unsqueeze

-

-

48

-

torch.where

-

-
- -

Generators

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

序号

-

API名称

-

是否支持(PyTorch1.5.0)

-

1

-

torch._C.Generator

-

-

2

-

torch._C.Generator.device

-

-

3

-

torch._C.Generator.get_state

-

-

4

-

torch._C.Generator.initial_seed

-

-

5

-

torch._C.Generator.manual_seed

-

-

6

-

torch._C.Generator.seed

-

-

7

-

torch._C.Generator.set_state

-

-
- -

Random sampling

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

序号

-

API名称

-

是否支持(PyTorch1.5.0)

-

1

-

torch.seed

-

-

2

-

torch.manual_seed

-

-

3

-

torch.initial_seed

-

-

4

-

torch.get_rng_state

-

-

5

-

torch.set_rng_state

-

-

6

-

torch.torch.default_generator

-

-

7

-

torch.bernoulli

-

-

8

-

torch.multinomial

-

-

9

-

torch.normal

-

-

10

-

torch.poisson

-

-

11

-

torch.rand

-

-

12

-

torch.rand_like

-

-

13

-

torch.randint

-

-

14

-

torch.randint_like

-

-

15

-

torch.randn

-

-

16

-

torch.randn_like

-

-

17

-

torch.randperm

-

-

18

-

torch.Tensor.bernoulli_()

-

-

19

-

torch.Tensor.bernoulli_()

-

-

20

-

torch.Tensor.exponential_()

-

-

21

-

torch.Tensor.geometric_()

-

-

22

-

torch.Tensor.log_normal_()

-

-

23

-

torch.Tensor.normal_()

-

-

24

-

torch.Tensor.random_()

-

-

25

-

torch.Tensor.uniform_()

-

-

26

-

torch.quasirandom.SobolEngine

-

-

27

-

torch.quasirandom.SobolEngine.draw

-

-

28

-

torch.quasirandom.SobolEngine.fast_forward

-

-

29

-

torch.quasirandom.SobolEngine.reset

-

-
- -

Serialization

- - - - - - - - - - - - - - - - -

序号

-

API名称

-

是否支持(PyTorch1.5.0)

-

1

-

torch.save

-

-

2

-

torch.load

-

-
- -

Math operations

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

序号

-

API名称

-

是否支持(PyTorch1.5.0)

-

1

-

torch.abs

-

-

2

-

torch.acos

-

-

3

-

torch.add

-

-

4

-

torch.addcdiv

-

-

5

-

torch.addcmul

-

-

6

-

torch.angle

-

-

7

-

torch.asin

-

-

8

-

torch.atan

-

-

9

-

torch.atan2

-

-

10

-

torch.bitwise_not

-

-

11

-

torch.bitwise_and

-

-

12

-

torch.bitwise_or

-

-

13

-

torch.bitwise_xor

-

-

14

-

torch.ceil

-

-

15

-

torch.clamp

-

-

16

-

torch.conj

-

-

17

-

torch.cos

-

-

18

-

torch.cosh

-

-

19

-

torch.div

-

-

20

-

torch.digamma

-

-

21

-

torch.erf

-

-

22

-

torch.erfc

-

-

23

-

torch.erfinv

-

-

24

-

torch.exp

-

-

25

-

torch.expm1

-

-

26

-

torch.floor

-

-

27

-

torch.floor_divide

-

-

28

-

torch.fmod

-

-

29

-

torch.frac

-

-

30

-

torch.imag

-

-

31

-

torch.lerp

-

-

32

-

torch.lgamma

-

-

33

-

torch.log

-

-

34

-

torch.log10

-

-

35

-

torch.log1p

-

-

36

-

torch.log2

-

-

37

-

torch.logical_and

-

-

38

-

torch.logical_not

-

-

39

-

torch.logical_or

-

-

40

-

torch.logical_xor

-

-

41

-

torch.mul

-

-

42

-

torch.mvlgamma

-

-

43

-

torch.neg

-

-

44

-

torch.polygamma

-

-

45

-

torch.pow

-

-

46

-

torch.real

-

-

47

-

torch.reciprocal

-

-

48

-

torch.remainder

-

-

49

-

torch.round

-

-

50

-

torch.rsqrt

-

-

51

-

torch.sigmoid

-

-

52

-

torch.sign

-

-

53

-

torch.sin

-

-

54

-

torch.sinh

-

-

55

-

torch.sqrt

-

-

56

-

torch.square

-

-

57

-

torch.tan

-

-

58

-

torch.tanh

-

-

59

-

torch.true_divide

-

-

60

-

torch.trunc

-

-

61

-

torch.argmax

-

-

62

-

torch.argmin

-

-

63

-

torch.dist

-

-

64

-

torch.logsumexp

-

-

65

-

torch.mean

-

-

66

-

torch.median

-

-

67

-

torch.mode

-

-

68

-

torch.norm

-

-

69

-

torch.prod

-

-

70

-

torch.std

-

-

71

-

torch.std_mean

-

-

72

-

torch.sum

-

-

73

-

torch.unique

-

-

74

-

torch.unique_consecutive

-

-

75

-

torch.var

-

-

76

-

torch.var_mean

-

-

77

-

torch.allclose

-

-

78

-

torch.argsort

-

-

79

-

torch.eq

-

-

80

-

torch.equal

-

-

81

-

torch.ge

-

-

82

-

torch.gt

-

-

83

-

torch.isfinite

-

-

84

-

torch.isinf

-

-

85

-

torch.isnan

-

-

86

-

torch.kthvalue

-

-

87

-

torch.le

-

-

88

-

torch.lt

-

-

89

-

torch.max

-

-

90

-

torch.min

-

-

91

-

torch.ne

-

-

92

-

torch.sort

-

-

93

-

torch.topk

-

-

94

-

torch.fft

-

-

95

-

torch.ifft

-

-

96

-

torch.rfft

-

-

97

-

torch.irfft

-

-

98

-

torch.stft

-

-

99

-

torch.bartlett_window

-

-

100

-

torch.blackman_window

-

-

101

-

torch.hamming_window

-

-

102

-

torch.hann_window

-

-

103

-

torch.bincount

-

-

104

-

torch.broadcast_tensors

-

-

105

-

torch.cartesian_prod

-

-

106

-

torch.cdist

-

-

107

-

torch.combinations

-

-

108

-

torch.cross

-

-

109

-

torch.cummax

-

-

110

-

torch.cummin

-

-

111

-

torch.cumprod

-

-

112

-

torch.cumsum

-

-

113

-

torch.diag

-

-

114

-

torch.diag_embed

-

-

115

-

torch.diagflat

-

-

116

-

torch.diagonal

-

-

117

-

torch.einsum

-

-

118

-

torch.flatten

-

-

119

-

torch.flip

-

-

120

-

torch.rot90

-

-

121

-

torch.histc

-

-

122

-

torch.meshgrid

-

-

123

-

torch.renorm

-

-

124

-

torch.repeat_interleave

-

-

125

-

torch.roll

-

-

126

-

torch.tensordot

-

-

127

-

torch.trace

-

-

128

-

torch.tril

-

-

129

-

torch.tril_indices

-

-

130

-

torch.triu

-

-

131

-

torch.triu_indices

-

-

132

-

torch.addbmm

-

-

133

-

torch.addmm

-

-

134

-

torch.addmv

-

-

135

-

torch.addr

-

-

136

-

torch.baddbmm

-

-

137

-

torch.bmm

-

-

138

-

torch.chain_matmul

-

-

139

-

torch.cholesky

-

-

140

-

torch.cholesky_inverse

-

-

141

-

torch.cholesky_solve

-

-

142

-

torch.dot

-

-

143

-

torch.eig

-

-

144

-

torch.geqrf

-

-

145

-

torch.ger

-

-

146

-

torch.inverse

-

-

147

-

torch.det

-

-

148

-

torch.logdet

-

-

149

-

torch.slogdet

-

-

150

-

torch.lstsq

-

-

151

-

torch.lu

-

-

152

-

torch.lu_solve

-

-

153

-

torch.lu_unpack

-

-

154

-

torch.matmul

-

-

155

-

torch.matrix_power

-

-

156

-

torch.matrix_rank

-

-

157

-

torch.mm

-

-

158

-

torch.mv

-

-

159

-

torch.orgqr

-

-

160

-

torch.ormqr

-

-

161

-

torch.pinverse

-

-

162

-

torch.qr

-

-

163

-

torch.solve

-

-

164

-

torch.svd

-

-

165

-

torch.svd_lowrank

-

-

166

-

torch.pca_lowrank

-

-

167

-

torch.symeig

-

-

168

-

torch.lobpcg

-

-

169

-

torch.trapz

-

-

170

-

torch.triangular_solve

-

-
- -

Utilities

- - - - - - - - - - - - - - - - - - - - - - - - -

序号

-

API名称

-

是否支持(PyTorch1.5.0)

-

1

-

torch.compiled_with_cxx11_abi

-

-

2

-

torch.result_type

-

-

3

-

torch.can_cast

-

-

4

-

torch.promote_types

-

-
- -

Other

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

序号

-

API名称

-

是否支持(PyTorch1.5.0)

-

1

-

torch.no_grad

-

-

2

-

torch.enable_grad

-

-

3

-

torch.set_grad_enabled

-

-

4

-

torch.get_num_threads

-

-

5

-

torch.set_num_threads

-

-

6

-

torch.get_num_interop_threads

-

-

7

-

torch.set_num_interop_threads

-

-
- -

torch.Tensor

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

序号

-

API名称

-

是否支持(PyTorch1.5.0)

-

1

-

torch.Tensor

-

-

2

-

torch.Tensor.new_tensor

-

-

3

-

torch.Tensor.new_full

-

-

4

-

torch.Tensor.new_empty

-

-

5

-

torch.Tensor.new_ones

-

-

6

-

torch.Tensor.new_zeros

-

-

7

-

torch.Tensor.is_cuda

-

-

8

-

torch.Tensor.is_quantized

-

-

9

-

torch.Tensor.device

-

-

10

-

torch.Tensor.ndim

-

-

11

-

torch.Tensor.T

-

-

12

-

torch.Tensor.abs

-

-

13

-

torch.Tensor.abs_

-

-

14

-

torch.Tensor.acos

-

-

15

-

torch.Tensor.acos_

-

-

16

-

torch.Tensor.add

-

-

17

-

torch.Tensor.add_

-

-

18

-

torch.Tensor.addbmm

-

-

19

-

torch.Tensor.addbmm_

-

-

20

-

torch.Tensor.addcdiv

-

-

21

-

torch.Tensor.addcdiv_

-

-

22

-

torch.Tensor.addcmul

-

-

23

-

torch.Tensor.addcmul_

-

-

24

-

torch.Tensor.addmm

-

-

25

-

torch.Tensor.addmm_

-

-

26

-

torch.Tensor.addmv

-

-

27

-

torch.Tensor.addmv_

-

-

28

-

torch.Tensor.addr

-

-

29

-

torch.Tensor.addr_

-

-

30

-

torch.Tensor.allclose

-

-

31

-

torch.Tensor.angle

-

-

32

-

torch.Tensor.apply_

-

-

33

-

torch.Tensor.argmax

-

-

34

-

torch.Tensor.argmin

-

-

35

-

torch.Tensor.argsort

-

-

36

-

torch.Tensor.asin

-

-

37

-

torch.Tensor.asin_

-

-

38

-

torch.Tensor.as_strided

-

-

39

-

torch.Tensor.atan

-

-

40

-

torch.Tensor.atan2

-

-

41

-

torch.Tensor.atan2_

-

-

42

-

torch.Tensor.atan_

-

-

43

-

torch.Tensor.baddbmm

-

-

44

-

torch.Tensor.baddbmm_

-

-

45

-

torch.Tensor.bernoulli

-

-

46

-

torch.Tensor.bernoulli_

-

-

47

-

torch.Tensor.bfloat16

-

-

48

-

torch.Tensor.bincount

-

-

49

-

torch.Tensor.bitwise_not

-

-

50

-

torch.Tensor.bitwise_not_

-

-

51

-

torch.Tensor.bitwise_and

-

-

52

-

torch.Tensor.bitwise_and_

-

-

53

-

torch.Tensor.bitwise_or

-

-

54

-

torch.Tensor.bitwise_or_

-

-

55

-

torch.Tensor.bitwise_xor

-

-

56

-

torch.Tensor.bitwise_xor_

-

-

57

-

torch.Tensor.bmm

-

-

58

-

torch.Tensor.bool

-

-

59

-

torch.Tensor.byte

-

-

60

-

torch.Tensor.cauchy_

-

-

61

-

torch.Tensor.ceil

-

-

62

-

torch.Tensor.ceil_

-

-

63

-

torch.Tensor.char

-

-

64

-

torch.Tensor.cholesky

-

-

65

-

torch.Tensor.cholesky_inverse

-

-

66

-

torch.Tensor.cholesky_solve

-

-

67

-

torch.Tensor.chunk

-

-

68

-

torch.Tensor.clamp

-

-

69

-

torch.Tensor.clamp_

-

-

70

-

torch.Tensor.clone

-

-

71

-

torch.Tensor.contiguous

-

-

72

-

torch.Tensor.copy_

-

-

73

-

torch.Tensor.conj

-

-

74

-

torch.Tensor.cos

-

-

75

-

torch.Tensor.cos_

-

-

76

-

torch.Tensor.cosh

-

-

77

-

torch.Tensor.cosh_

-

-

78

-

torch.Tensor.cpu

-

-

79

-

torch.Tensor.cross

-

-

80

-

torch.Tensor.cuda

-

-

81

-

torch.Tensor.cummax

-

-

82

-

torch.Tensor.cummin

-

-

83

-

torch.Tensor.cumprod

-

-

84

-

torch.Tensor.cumsum

-

-

85

-

torch.Tensor.data_ptr

-

-

86

-

torch.Tensor.dequantize

-

-

87

-

torch.Tensor.det

-

-

88

-

torch.Tensor.dense_dim

-

-

89

-

torch.Tensor.diag

-

-

90

-

torch.Tensor.diag_embed

-

-

91

-

torch.Tensor.diagflat

-

-

92

-

torch.Tensor.diagonal

-

-

93

-

torch.Tensor.fill_diagonal_

-

-

94

-

torch.Tensor.digamma

-

-

95

-

torch.Tensor.digamma_

-

-

96

-

torch.Tensor.dim

-

-

97

-

torch.Tensor.dist

-

-

98

-

torch.Tensor.div

-

-

99

-

torch.Tensor.div_

-

-

100

-

torch.Tensor.dot

-

-

101

-

torch.Tensor.double

-

-

102

-

torch.Tensor.eig

-

-

103

-

torch.Tensor.element_size

-

-

104

-

torch.Tensor.eq

-

-

105

-

torch.Tensor.eq_

-

-

106

-

torch.Tensor.equal

-

-

107

-

torch.Tensor.erf

-

-

108

-

torch.Tensor.erf_

-

-

109

-

torch.Tensor.erfc

-

-

110

-

torch.Tensor.erfc_

-

-

111

-

torch.Tensor.erfinv

-

-

112

-

torch.Tensor.erfinv_

-

-

113

-

torch.Tensor.exp

-

-

114

-

torch.Tensor.exp_

-

-

115

-

torch.Tensor.expm1

-

-

116

-

torch.Tensor.expm1_

-

-

117

-

torch.Tensor.expand

-

-

118

-

torch.Tensor.expand_as

-

-

119

-

torch.Tensor.exponential_

-

-

120

-

torch.Tensor.fft

-

-

121

-

torch.Tensor.fill_

-

-

122

-

torch.Tensor.flatten

-

-

123

-

torch.Tensor.flip

-

-

124

-

torch.Tensor.float

-

-

125

-

torch.Tensor.floor

-

-

126

-

torch.Tensor.floor_

-

-

127

-

torch.Tensor.floor_divide

-

-

128

-

torch.Tensor.floor_divide_

-

-

129

-

torch.Tensor.fmod

-

-

130

-

torch.Tensor.fmod_

-

-

131

-

torch.Tensor.frac

-

-

132

-

torch.Tensor.frac_

-

-

133

-

torch.Tensor.gather

-

-

134

-

torch.Tensor.ge

-

-

135

-

torch.Tensor.ge_

-

-

136

-

torch.Tensor.geometric_

-

-

137

-

torch.Tensor.geqrf

-

-

138

-

torch.Tensor.ger

-

-

139

-

torch.Tensor.get_device

-

-

140

-

torch.Tensor.gt

-

-

141

-

torch.Tensor.gt_

-

-

142

-

torch.Tensor.half

-

-

143

-

torch.Tensor.hardshrink

-

-

144

-

torch.Tensor.histc

-

-

145

-

torch.Tensor.ifft

-

-

146

-

torch.Tensor.index_add_

-

-

147

-

torch.Tensor.index_add

-

-

148

-

torch.Tensor.index_copy_

-

-

149

-

torch.Tensor.index_copy

-

-

150

-

torch.Tensor.index_fill_

-

-

151

-

torch.Tensor.index_fill

-

-

152

-

torch.Tensor.index_put_

-

-

153

-

torch.Tensor.index_put

-

-

154

-

torch.Tensor.index_select

-

-

155

-

torch.Tensor.indices

-

-

156

-

torch.Tensor.int

-

-

157

-

torch.Tensor.int_repr

-

-

158

-

torch.Tensor.inverse

-

-

159

-

torch.Tensor.irfft

-

-

160

-

torch.Tensor.is_contiguous

-

-

161

-

torch.Tensor.is_complex

-

-

162

-

torch.Tensor.is_floating_point

-

-

163

-

torch.Tensor.is_pinned

-

-

164

-

torch.Tensor.is_set_to

-

-

165

-

torch.Tensor.is_shared

-

-

166

-

torch.Tensor.is_signed

-

-

167

-

torch.Tensor.is_sparse

-

-

168

-

torch.Tensor.item

-

-

169

-

torch.Tensor.kthvalue

-

-

170

-

torch.Tensor.le

-

-

171

-

torch.Tensor.le_

-

-

172

-

torch.Tensor.lerp

-

-

173

-

torch.Tensor.lerp_

-

-

174

-

torch.Tensor.lgamma

-

-

175

-

torch.Tensor.lgamma_

-

-

176

-

torch.Tensor.log

-

-

177

-

torch.Tensor.log_

-

-

178

-

torch.Tensor.logdet

-

-

179

-

torch.Tensor.log10

-

-

180

-

torch.Tensor.log10_

-

-

181

-

torch.Tensor.log1p

-

-

182

-

torch.Tensor.log1p_

-

-

183

-

torch.Tensor.log2

-

-

184

-

torch.Tensor.log2_

-

-

185

-

torch.Tensor.log_normal_

-

-

186

-

torch.Tensor.logsumexp

-

-

187

-

torch.Tensor.logical_and

-

-

188

-

torch.Tensor.logical_and_

-

-

189

-

torch.Tensor.logical_not

-

-

190

-

torch.Tensor.logical_not_

-

-

191

-

torch.Tensor.logical_or

-

-

192

-

torch.Tensor.logical_or_

-

-

193

-

torch.Tensor.logical_xor

-

-

194

-

torch.Tensor.logical_xor_

-

-

195

-

torch.Tensor.long

-

-

196

-

torch.Tensor.lstsq

-

-

197

-

torch.Tensor.lt

-

-

198

-

torch.Tensor.lt_

-

-

199

-

torch.Tensor.lu

-

-

200

-

torch.Tensor.lu_solve

-

-

201

-

torch.Tensor.map_

-

-

202

-

torch.Tensor.masked_scatter_

-

-

203

-

torch.Tensor.masked_scatter

-

-

204

-

torch.Tensor.masked_fill_

-

-

205

-

torch.Tensor.masked_fill

-

-

206

-

torch.Tensor.masked_select

-

-

207

-

torch.Tensor.matmul

-

-

208

-

torch.Tensor.matrix_power

-

-

209

-

torch.Tensor.max

-

-

210

-

torch.Tensor.mean

-

-

211

-

torch.Tensor.median

-

-

212

-

torch.Tensor.min

-

-

213

-

torch.Tensor.mm

-

-

214

-

torch.Tensor.mode

-

-

215

-

torch.Tensor.mul

-

-

216

-

torch.Tensor.mul_

-

-

217

-

torch.Tensor.multinomial

-

-

218

-

torch.Tensor.mv

-

-

219

-

torch.Tensor.mvlgamma

-

-

220

-

torch.Tensor.mvlgamma_

-

-

221

-

torch.Tensor.narrow

-

-

222

-

torch.Tensor.narrow_copy

-

-

223

-

torch.Tensor.ndimension

-

-

224

-

torch.Tensor.ne

-

-

225

-

torch.Tensor.ne_

-

-

226

-

torch.Tensor.neg

-

-

227

-

torch.Tensor.neg_

-

-

228

-

torch.Tensor.nelement

-

-

229

-

torch.Tensor.nonzero

-

-

230

-

torch.Tensor.norm

-

-

231

-

torch.Tensor.normal_

-

-

232

-

torch.Tensor.numel

-

-

233

-

torch.Tensor.numpy

-

-

234

-

torch.Tensor.orgqr

-

-

235

-

torch.Tensor.ormqr

-

-

236

-

torch.Tensor.permute

-

-

237

-

torch.Tensor.pin_memory

-

-

238

-

torch.Tensor.pinverse

-

-

239

-

torch.Tensor.polygamma

-

-

240

-

torch.Tensor.polygamma_

-

-

241

-

torch.Tensor.pow

-

-

242

-

torch.Tensor.pow_

-

-

243

-

torch.Tensor.prod

-

-

244

-

torch.Tensor.put_

-

-

245

-

torch.Tensor.qr

-

-

246

-

torch.Tensor.qscheme

-

-

247

-

torch.Tensor.q_scale

-

-

248

-

torch.Tensor.q_zero_point

-

-

249

-

torch.Tensor.q_per_channel_scales

-

-

250

-

torch.Tensor.q_per_channel_zero_points

-

-

251

-

torch.Tensor.q_per_channel_axis

-

-

252

-

torch.Tensor.random_

-

-

253

-

torch.Tensor.reciprocal

-

-

254

-

torch.Tensor.reciprocal_

-

-

255

-

torch.Tensor.record_stream

-

-

256

-

torch.Tensor.remainder

-

-

257

-

torch.Tensor.remainder_

-

-

258

-

torch.Tensor.renorm

-

-

259

-

torch.Tensor.renorm_

-

-

260

-

torch.Tensor.repeat

-

-

261

-

torch.Tensor.repeat_interleave

-

-

262

-

torch.Tensor.requires_grad_

-

-

263

-

torch.Tensor.reshape

-

-

264

-

torch.Tensor.reshape_as

-

-

265

-

torch.Tensor.resize_

-

-

266

-

torch.Tensor.resize_as_

-

-

267

-

torch.Tensor.rfft

-

-

268

-

torch.Tensor.roll

-

-

269

-

torch.Tensor.rot90

-

-

270

-

torch.Tensor.round

-

-

271

-

torch.Tensor.round_

-

-

272

-

torch.Tensor.rsqrt

-

-

273

-

torch.Tensor.rsqrt_

-

-

274

-

torch.Tensor.scatter

-

-

275

-

torch.Tensor.scatter_

-

-

276

-

torch.Tensor.scatter_add_

-

-

277

-

torch.Tensor.scatter_add

-

-

278

-

torch.Tensor.select

-

-

279

-

torch.Tensor.set_

-

-

280

-

torch.Tensor.share_memory_

-

-

281

-

torch.Tensor.short

-

-

282

-

torch.Tensor.sigmoid

-

-

283

-

torch.Tensor.sigmoid_

-

-

284

-

torch.Tensor.sign

-

-

285

-

torch.Tensor.sign_

-

-

286

-

torch.Tensor.sin

-

-

287

-

torch.Tensor.sin_

-

-

288

-

torch.Tensor.sinh

-

-

289

-

torch.Tensor.sinh_

-

-

290

-

torch.Tensor.size

-

-

291

-

torch.Tensor.slogdet

-

-

292

-

torch.Tensor.solve

-

-

293

-

torch.Tensor.sort

-

-

294

-

torch.Tensor.split

-

-

295

-

torch.Tensor.sparse_mask

-

-

296

-

torch.Tensor.sparse_dim

-

-

297

-

torch.Tensor.sqrt

-

-

298

-

torch.Tensor.sqrt_

-

-

299

-

torch.Tensor.square

-

-

300

-

torch.Tensor.square_

-

-

301

-

torch.Tensor.squeeze

-

-

302

-

torch.Tensor.squeeze_

-

-

303

-

torch.Tensor.std

-

-

304

-

torch.Tensor.stft

-

-

305

-

torch.Tensor.storage

-

-

306

-

torch.Tensor.storage_offset

-

-

307

-

torch.Tensor.storage_type

-

-

308

-

torch.Tensor.stride

-

-

309

-

torch.Tensor.sub

-

-

310

-

torch.Tensor.sub_

-

-

311

-

torch.Tensor.sum

-

-

312

-

torch.Tensor.sum_to_size

-

-

313

-

torch.Tensor.svd

-

-

314

-

torch.Tensor.symeig

-

-

315

-

torch.Tensor.t

-

-

316

-

torch.Tensor.t_

-

-

317

-

torch.Tensor.to

-

-

318

-

torch.Tensor.to_mkldnn

-

-

319

-

torch.Tensor.take

-

-

320

-

torch.Tensor.tan

-

-

321

-

torch.Tensor.tan_

-

-

322

-

torch.Tensor.tanh

-

-

323

-

torch.Tensor.tanh_

-

-

324

-

torch.Tensor.tolist

-

-

325

-

torch.Tensor.topk

-

-

326

-

torch.Tensor.to_sparse

-

-

327

-

torch.Tensor.trace

-

-

328

-

torch.Tensor.transpose

-

-

329

-

torch.Tensor.transpose_

-

-

330

-

torch.Tensor.triangular_solve

-

-

331

-

torch.Tensor.tril

-

-

332

-

torch.Tensor.tril_

-

-

333

-

torch.Tensor.triu

-

-

334

-

torch.Tensor.triu_

-

-

335

-

torch.Tensor.true_divide

-

-

336

-

torch.Tensor.true_divide_

-

-

337

-

torch.Tensor.trunc

-

-

338

-

torch.Tensor.trunc_

-

-

339

-

torch.Tensor.type

-

-

340

-

torch.Tensor.type_as

-

-

341

-

torch.Tensor.unbind

-

-

342

-

torch.Tensor.unfold

-

-

343

-

torch.Tensor.uniform_

-

-

344

-

torch.Tensor.unique

-

-

345

-

torch.Tensor.unique_consecutive

-

-

346

-

torch.Tensor.unsqueeze

-

-

347

-

torch.Tensor.unsqueeze_

-

-

348

-

torch.Tensor.values

-

-

349

-

torch.Tensor.var

-

-

350

-

torch.Tensor.view

-

-

351

-

torch.Tensor.view_as

-

-

352

-

torch.Tensor.where

-

-

353

-

torch.Tensor.zero_

-

-

354

-

torch.BoolTensor

-

-

355

-

torch.BoolTensor.all

-

-

356

-

torch.BoolTensor.any

-

-
- -

Layers (torch.nn)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

序号

-

API名称

-

是否支持(PyTorch1.5.0)

-

1

-

torch.nn.Parameter

-

-

2

-

torch.nn.Module

-

-

3

-

torch.nn.Module.add_module

-

-

4

-

torch.nn.Module.apply

-

-

5

-

torch.nn.Module.bfloat16

-

-

6

-

torch.nn.Module.buffers

-

-

7

-

torch.nn.Module.children

-

-

8

-

torch.nn.Module.cpu

-

-

9

-

torch.nn.Module.cuda

-

-

10

-

torch.nn.Module.double

-

-

11

-

torch.nn.Module.dump_patches

-

-

12

-

torch.nn.Module.eval

-

-

13

-

torch.nn.Module.extra_repr

-

-

14

-

torch.nn.Module.float

-

-

15

-

torch.nn.Module.forward

-

-

16

-

torch.nn.Module.half

-

-

17

-

torch.nn.Module.load_state_dict

-

-

18

-

torch.nn.Module.modules

-

-

19

-

torch.nn.Module.named_buffers

-

-

20

-

torch.nn.Module.named_children

-

-

21

-

torch.nn.Module.named_modules

-

-

22

-

torch.nn.Module.named_parameters

-

-

23

-

torch.nn.Module.parameters

-

-

24

-

torch.nn.Module.register_backward_hook

-

-

25

-

torch.nn.Module.register_buffer

-

-

26

-

torch.nn.Module.register_forward_hook

-

-

27

-

torch.nn.Module.register_forward_pre_hook

-

-

28

-

torch.nn.Module.register_parameter

-

-

29

-

torch.nn.Module.requires_grad_

-

-

30

-

torch.nn.Module.state_dict

-

-

31

-

torch.nn.Module.to

-

-

32

-

torch.nn.Module.train

-

-

33

-

torch.nn.Module.type

-

-

34

-

torch.nn.Module.zero_grad

-

-

35

-

torch.nn.Sequential

-

-

36

-

torch.nn.ModuleList

-

-

37

-

torch.nn.ModuleList.append

-

-

38

-

torch.nn.ModuleList.extend

-

-

39

-

torch.nn.ModuleList.insert

-

-

40

-

torch.nn.ModuleDict

-

-

41

-

torch.nn.ModuleDict.clear

-

-

42

-

torch.nn.ModuleDict.items

-

-

43

-

torch.nn.ModuleDict.keys

-

-

44

-

torch.nn.ModuleDict.pop

-

-

45

-

torch.nn.ModuleDict.update

-

-

46

-

torch.nn.ModuleDict.values

-

-

47

-

torch.nn.ParameterList

-

-

48

-

torch.nn.ParameterList.append

-

-

49

-

torch.nn.ParameterList.extend

-

-

50

-

torch.nn.ParameterDict

-

-

51

-

torch.nn.ParameterDict.clear

-

-

52

-

torch.nn.ParameterDict.items

-

-

53

-

torch.nn.ParameterDict.keys

-

-

54

-

torch.nn.ParameterDict.pop

-

-

55

-

torch.nn.ParameterDict.update

-

-

56

-

torch.nn.ParameterDict.values

-

-

57

-

torch.nn.Conv1d

-

-

58

-

torch.nn.Conv2d

-

-

59

-

torch.nn.Conv3d

-

-

60

-

torch.nn.ConvTranspose1d

-

-

61

-

torch.nn.ConvTranspose2d

-

-

62

-

torch.nn.ConvTranspose3d

-

-

63

-

torch.nn.Unfold

-

-

64

-

torch.nn.Fold

-

-

65

-

torch.nn.MaxPool1d

-

-

66

-

torch.nn.MaxPool2d

-

-

67

-

torch.nn.MaxPool3d

-

-

68

-

torch.nn.MaxUnpool1d

-

-

69

-

torch.nn.MaxUnpool2d

-

-

70

-

torch.nn.MaxUnpool3d

-

-

71

-

torch.nn.AvgPool1d

-

-

72

-

torch.nn.AvgPool2d

-

-

73

-

torch.nn.AvgPool3d

-

-

74

-

torch.nn.FractionalMaxPool2d

-

-

75

-

torch.nn.LPPool1d

-

-

76

-

torch.nn.LPPool2d

-

-

77

-

torch.nn.AdaptiveMaxPool1d

-

-

78

-

torch.nn.AdaptiveMaxPool2d

-

-

79

-

torch.nn.AdaptiveMaxPool3d

-

-

80

-

torch.nn.AdaptiveAvgPool1d

-

-

81

-

torch.nn.AdaptiveAvgPool2d

-

-

82

-

torch.nn.AdaptiveAvgPool3d

-

-

83

-

torch.nn.ReflectionPad1d

-

-

84

-

torch.nn.ReflectionPad2d

-

-

85

-

torch.nn.ReplicationPad1d

-

-

86

-

torch.nn.ReplicationPad2d

-

-

87

-

torch.nn.ReplicationPad3d

-

-

88

-

torch.nn.ZeroPad2d

-

-

89

-

torch.nn.ConstantPad1d

-

-

90

-

torch.nn.ConstantPad2d

-

-

91

-

torch.nn.ConstantPad3d

-

-

92

-

torch.nn.ELU

-

-

93

-

torch.nn.Hardshrink

-

-

94

-

torch.nn.Hardtanh

-

-

95

-

torch.nn.LeakyReLU

-

-

96

-

torch.nn.LogSigmoid

-

-

97

-

torch.nn.MultiheadAttention

-

-

98

-

torch.nn.PReLU

-

-

99

-

torch.nn.ReLU

-

-

100

-

torch.nn.ReLU6

-

-

101

-

torch.nn.RReLU

-

-

102

-

torch.nn.SELU

-

-

103

-

torch.nn.CELU

-

-

104

-

torch.nn.GELU

-

-

105

-

torch.nn.Sigmoid

-

-

106

-

torch.nn.Softplus

-

-

107

-

torch.nn.Softshrink

-

是,SoftShrink场景暂不支持

-

108

-

torch.nn.Softsign

-

-

109

-

torch.nn.Tanh

-

-

110

-

torch.nn.Tanhshrink

-

-

111

-

torch.nn.Threshold

-

-

112

-

torch.nn.Softmin

-

-

113

-

torch.nn.Softmax

-

-

114

-

torch.nn.Softmax2d

-

-

115

-

torch.nn.LogSoftmax

-

-

116

-

torch.nn.AdaptiveLogSoftmaxWithLoss

-

-

117

-

torch.nn.AdaptiveLogSoftmaxWithLoss.log_prob

-

-

118

-

torch.nn.AdaptiveLogSoftmaxWithLoss.predict

-

-

119

-

torch.nn.BatchNorm1d

-

-

120

-

torch.nn.BatchNorm2d

-

-

121

-

torch.nn.BatchNorm3d

-

-

122

-

torch.nn.GroupNorm

-

-

123

-

torch.nn.SyncBatchNorm

-

-

124

-

torch.nn.SyncBatchNorm.convert_sync_batchnorm

-

-

125

-

torch.nn.InstanceNorm1d

-

-

126

-

torch.nn.InstanceNorm2d

-

-

127

-

torch.nn.InstanceNorm3d

-

-

128

-

torch.nn.LayerNorm

-

-

129

-

torch.nn.LocalResponseNorm

-

-

130

-

torch.nn.RNNBase

-

-

131

-

torch.nn.RNNBase.flatten_parameters

-

-

132

-

torch.nn.RNN

-

-

133

-

torch.nn.LSTM

-

-

134

-

torch.nn.GRU

-

是,DynamicGRUV2场景暂不支持

-

135

-

torch.nn.RNNCell

-

-

136

-

torch.nn.LSTMCell

-

-

137

-

torch.nn.GRUCell

-

-

138

-

torch.nn.Transformer

-

-

139

-

torch.nn.Transformer.forward

-

-

140

-

torch.nn.Transformer.generate_square_subsequent_mask

-

-

141

-

torch.nn.TransformerEncoder

-

-

142

-

torch.nn.TransformerEncoder.forward

-

-

143

-

torch.nn.TransformerDecoder

-

-

144

-

torch.nn.TransformerDecoder.forward

-

-

145

-

torch.nn.TransformerEncoderLayer

-

-

146

-

torch.nn.TransformerEncoderLayer.forward

-

-

147

-

torch.nn.TransformerDecoderLayer

-

-

148

-

torch.nn.TransformerDecoderLayer.forward

-

-

149

-

torch.nn.Identity

-

-

150

-

torch.nn.Linear

-

-

151

-

torch.nn.Bilinear

-

-

152

-

torch.nn.Dropout

-

-

153

-

torch.nn.Dropout2d

-

-

154

-

torch.nn.Dropout3d

-

-

155

-

torch.nn.AlphaDropout

-

-

156

-

torch.nn.Embedding

-

-

157

-

torch.nn.Embedding.from_pretrained

-

-

158

-

torch.nn.EmbeddingBag

-

-

159

-

torch.nn.EmbeddingBag.from_pretrained

-

-

160

-

torch.nn.CosineSimilarity

-

-

161

-

torch.nn.PairwiseDistance

-

-

162

-

torch.nn.L1Loss

-

-

163

-

torch.nn.MSELoss

-

-

164

-

torch.nn.CrossEntropyLoss

-

-

165

-

torch.nn.CTCLoss

-

-

166

-

torch.nn.NLLLoss

-

-

167

-

torch.nn.PoissonNLLLoss

-

-

168

-

torch.nn.KLDivLoss

-

-

169

-

torch.nn.BCELoss

-

-

170

-

torch.nn.BCEWithLogitsLoss

-

-

171

-

torch.nn.MarginRankingLoss

-

-

172

-

torch.nn.HingeEmbeddingLoss

-

-

173

-

torch.nn.MultiLabelMarginLoss

-

-

174

-

torch.nn.SmoothL1Loss

-

-

175

-

torch.nn.SoftMarginLoss

-

-

176

-

torch.nn.MultiLabelSoftMarginLoss

-

-

177

-

torch.nn.CosineEmbeddingLoss

-

-

178

-

torch.nn.MultiMarginLoss

-

-

179

-

torch.nn.TripletMarginLoss

-

-

180

-

torch.nn.PixelShuffle

-

-

181

-

torch.nn.Upsample

-

-

182

-

torch.nn.UpsamplingNearest2d

-

-

183

-

torch.nn.UpsamplingBilinear2d

-

-

184

-

torch.nn.DataParallel

-

-

185

-

torch.nn.parallel.DistributedDataParallel

-

-

186

-

torch.nn.parallel.DistributedDataParallel.no_sync

-

-

187

-

torch.nn.utils.clip_grad_norm_

-

-

188

-

torch.nn.utils.clip_grad_value_

-

-

189

-

torch.nn.utils.parameters_to_vector

-

-

190

-

torch.nn.utils.vector_to_parameters

-

-

197

-

torch.nn.utils.prune.PruningContainer

-

-

198

-

torch.nn.utils.prune.PruningContainer.add_pruning_method

-

-

199

-

torch.nn.utils.prune.PruningContainer.apply

-

-

200

-

torch.nn.utils.prune.PruningContainer.apply_mask

-

-

201

-

torch.nn.utils.prune.PruningContainer.compute_mask

-

-

202

-

torch.nn.utils.prune.PruningContainer.prune

-

-

203

-

torch.nn.utils.prune.PruningContainer.remove

-

-

204

-

torch.nn.utils.prune.Identity

-

-

205

-

torch.nn.utils.prune.Identity.apply

-

-

206

-

torch.nn.utils.prune.Identity.apply_mask

-

-

207

-

torch.nn.utils.prune.Identity.prune

-

-

208

-

torch.nn.utils.prune.Identity.remove

-

-

209

-

torch.nn.utils.prune.RandomUnstructured

-

-

210

-

torch.nn.utils.prune.RandomUnstructured.apply

-

-

211

-

torch.nn.utils.prune.RandomUnstructured.apply_mask

-

-

212

-

torch.nn.utils.prune.RandomUnstructured.prune

-

-

213

-

torch.nn.utils.prune.RandomUnstructured.remove

-

-

214

-

torch.nn.utils.prune.L1Unstructured

-

-

215

-

torch.nn.utils.prune.L1Unstructured.apply

-

-

216

-

torch.nn.utils.prune.L1Unstructured.apply_mask

-

-

217

-

torch.nn.utils.prune.L1Unstructured.prune

-

-

218

-

torch.nn.utils.prune.L1Unstructured.remove

-

-

219

-

torch.nn.utils.prune.RandomStructured

-

-

220

-

torch.nn.utils.prune.RandomStructured.apply

-

-

221

-

torch.nn.utils.prune.RandomStructured.apply_mask

-

-

222

-

torch.nn.utils.prune.RandomStructured.compute_mask

-

-

223

-

torch.nn.utils.prune.RandomStructured.prune

-

-

224

-

torch.nn.utils.prune.RandomStructured.remove

-

-

225

-

torch.nn.utils.prune.LnStructured

-

-

226

-

torch.nn.utils.prune.LnStructured.apply

-

-

227

-

torch.nn.utils.prune.LnStructured.apply_mask

-

-

228

-

torch.nn.utils.prune.LnStructured.compute_mask

-

-

229

-

torch.nn.utils.prune.LnStructured.prune

-

-

230

-

torch.nn.utils.prune.LnStructured.remove

-

-

231

-

torch.nn.utils.prune.CustomFromMask

-

-

232

-

torch.nn.utils.prune.CustomFromMask.apply

-

-

233

-

torch.nn.utils.prune.CustomFromMask.apply_mask

-

-

234

-

torch.nn.utils.prune.CustomFromMask.prune

-

-

235

-

torch.nn.utils.prune.CustomFromMask.remove

-

-

236

-

torch.nn.utils.prune.identity

-

-

237

-

torch.nn.utils.prune.random_unstructured

-

-

238

-

torch.nn.utils.prune.l1_unstructured

-

-

239

-

torch.nn.utils.prune.random_structured

-

-

240

-

torch.nn.utils.prune.ln_structured

-

-

241

-

torch.nn.utils.prune.global_unstructured

-

-

242

-

torch.nn.utils.prune.custom_from_mask

-

-

243

-

torch.nn.utils.prune.remove

-

-

244

-

torch.nn.utils.prune.is_pruned

-

-

245

-

torch.nn.utils.weight_norm

-

-

246

-

torch.nn.utils.remove_weight_norm

-

-

247

-

torch.nn.utils.spectral_norm

-

-

248

-

torch.nn.utils.remove_spectral_norm

-

-

249

-

torch.nn.utils.rnn.PackedSequence

-

-

250

-

torch.nn.utils.rnn.pack_padded_sequence

-

-

251

-

torch.nn.utils.rnn.pad_packed_sequence

-

-

252

-

torch.nn.utils.rnn.pad_sequence

-

-

253

-

torch.nn.utils.rnn.pack_sequence

-

-

254

-

torch.nn.Flatten

-

-

255

-

torch.quantization.quantize

-

-

256

-

torch.quantization.quantize_dynamic

-

-

257

-

torch.quantization.quantize_qat

-

-

258

-

torch.quantization.prepare

-

-

259

-

torch.quantization.prepare_qat

-

-

260

-

torch.quantization.convert

-

-

261

-

torch.quantization.QConfig

-

-

262

-

torch.quantization.QConfigDynamic

-

-

263

-

torch.quantization.fuse_modules

-

-

264

-

torch.quantization.QuantStub

-

-

265

-

torch.quantization.DeQuantStub

-

-

266

-

torch.quantization.QuantWrapper

-

-

267

-

torch.quantization.add_quant_dequant

-

-

268

-

torch.quantization.add_observer_

-

-

269

-

torch.quantization.swap_module

-

-

270

-

torch.quantization.propagate_qconfig_

-

-

271

-

torch.quantization.default_eval_fn

-

-

272

-

torch.quantization.MinMaxObserver

-

-

273

-

torch.quantization.MovingAverageMinMaxObserver

-

-

274

-

torch.quantization.PerChannelMinMaxObserver

-

-

275

-

torch.quantization.MovingAveragePerChannelMinMaxObserver

-

-

276

-

torch.quantization.HistogramObserver

-

-

277

-

torch.quantization.FakeQuantize

-

-

278

-

torch.quantization.NoopObserver

-

-

279

-

torch.quantization.get_observer_dict

-

-

280

-

torch.quantization.RecordingObserver

-

-

281

-

torch.nn.intrinsic.ConvBn2d

-

-

282

-

torch.nn.intrinsic.ConvBnReLU2d

-

-

283

-

torch.nn.intrinsic.ConvReLU2d

-

-

284

-

torch.nn.intrinsic.ConvReLU3d

-

-

285

-

torch.nn.intrinsic.LinearReLU

-

-

286

-

torch.nn.intrinsic.qat.ConvBn2d

-

-

287

-

torch.nn.intrinsic.qat.ConvBnReLU2d

-

-

288

-

torch.nn.intrinsic.qat.ConvReLU2d

-

-

289

-

torch.nn.intrinsic.qat.LinearReLU

-

-

290

-

torch.nn.intrinsic.quantized.ConvReLU2d

-

-

291

-

torch.nn.intrinsic.quantized.ConvReLU3d

-

-

292

-

torch.nn.intrinsic.quantized.LinearReLU

-

-

293

-

torch.nn.qat.Conv2d

-

-

294

-

torch.nn.qat.Conv2d.from_float

-

-

295

-

torch.nn.qat.Linear

-

-

296

-

torch.nn.qat.Linear.from_float

-

-

297

-

torch.nn.quantized.functional.relu

-

-

298

-

torch.nn.quantized.functional.linear

-

-

299

-

torch.nn.quantized.functional.conv2d

-

-

300

-

torch.nn.quantized.functional.conv3d

-

-

301

-

torch.nn.quantized.functional.max_pool2d

-

-

302

-

torch.nn.quantized.functional.adaptive_avg_pool2d

-

-

303

-

torch.nn.quantized.functional.avg_pool2d

-

-

304

-

torch.nn.quantized.functional.interpolate

-

-

305

-

torch.nn.quantized.functional.upsample

-

-

306

-

torch.nn.quantized.functional.upsample_bilinear

-

-

307

-

torch.nn.quantized.functional.upsample_nearest

-

-

308

-

torch.nn.quantized.ReLU

-

-

309

-

torch.nn.quantized.ReLU6

-

-

310

-

torch.nn.quantized.Conv2d

-

-

311

-

torch.nn.quantized.Conv2d.from_float

-

-

312

-

torch.nn.quantized.Conv3d

-

-

313

-

torch.nn.quantized.Conv3d.from_float

-

-

314

-

torch.nn.quantized.FloatFunctional

-

-

315

-

torch.nn.quantized.QFunctional

-

-

316

-

torch.nn.quantized.Quantize

-

-

317

-

torch.nn.quantized.DeQuantize

-

-

318

-

torch.nn.quantized.Linear

-

-

319

-

torch.nn.quantized.Linear.from_float

-

-

320

-

torch.nn.quantized.dynamic.Linear

-

-

321

-

torch.nn.quantized.dynamic.Linear.from_float

-

-

322

-

torch.nn.quantized.dynamic.LSTM

-

-
- -

Functions(torch.nn.functional)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

序号

-

API名称

-

是否支持(PyTorch1.5.0)

-

1

-

torch.nn.functional.conv1d

-

-

2

-

torch.nn.functional.conv2d

-

-

3

-

torch.nn.functional.conv3d

-

-

4

-

torch.nn.functional.conv_transpose1d

-

-

5

-

torch.nn.functional.conv_transpose2d

-

-

6

-

torch.nn.functional.conv_transpose3d

-

-

7

-

torch.nn.functional.unfold

-

-

8

-

torch.nn.functional.fold

-

-

9

-

torch.nn.functional.avg_pool1d

-

-

10

-

torch.nn.functional.avg_pool2d

-

-

11

-

torch.nn.functional.avg_pool3d

-

-

12

-

torch.nn.functional.max_pool1d

-

-

13

-

torch.nn.functional.max_pool2d

-

-

14

-

torch.nn.functional.max_pool3d

-

-

15

-

torch.nn.functional.max_unpool1d

-

-

16

-

torch.nn.functional.max_unpool2d

-

-

17

-

torch.nn.functional.max_unpool3d

-

-

18

-

torch.nn.functional.lp_pool1d

-

-

19

-

torch.nn.functional.lp_pool2d

-

-

20

-

torch.nn.functional.adaptive_max_pool1d

-

-

21

-

torch.nn.functional.adaptive_max_pool2d

-

-

22

-

torch.nn.functional.adaptive_max_pool3d

-

-

23

-

torch.nn.functional.adaptive_avg_pool1d

-

-

24

-

torch.nn.functional.adaptive_avg_pool2d

-

-

25

-

torch.nn.functional.adaptive_avg_pool3d

-

-

26

-

torch.nn.functional.threshold

-

-

27

-

torch.nn.functional.threshold_

-

-

28

-

torch.nn.functional.relu

-

-

29

-

torch.nn.functional.relu_

-

-

30

-

torch.nn.functional.hardtanh

-

-

31

-

torch.nn.functional.hardtanh_

-

-

32

-

torch.nn.functional.relu6

-

-

33

-

torch.nn.functional.elu

-

-

34

-

torch.nn.functional.elu_

-

-

35

-

torch.nn.functional.selu

-

-

36

-

torch.nn.functional.celu

-

-

37

-

torch.nn.functional.leaky_relu

-

-

38

-

torch.nn.functional.leaky_relu_

-

-

39

-

torch.nn.functional.prelu

-

-

40

-

torch.nn.functional.rrelu

-

-

41

-

torch.nn.functional.rrelu_

-

-

42

-

torch.nn.functional.glu

-

-

43

-

torch.nn.functional.gelu

-

-

44

-

torch.nn.functional.logsigmoid

-

-

45

-

torch.nn.functional.hardshrink

-

-

46

-

torch.nn.functional.tanhshrink

-

-

47

-

torch.nn.functional.softsign

-

-

48

-

torch.nn.functional.softplus

-

-

49

-

torch.nn.functional.softmin

-

-

50

-

torch.nn.functional.softmax

-

-

51

-

torch.nn.functional.softshrink

-

-

52

-

torch.nn.functional.gumbel_softmax

-

-

53

-

torch.nn.functional.log_softmax

-

-

54

-

torch.nn.functional.tanh

-

-

55

-

torch.nn.functional.sigmoid

-

-

56

-

torch.nn.functional.batch_norm

-

-

57

-

torch.nn.functional.instance_norm

-

-

58

-

torch.nn.functional.layer_norm

-

-

59

-

torch.nn.functional.local_response_norm

-

-

60

-

torch.nn.functional.normalize

-

-

61

-

torch.nn.functional.linear

-

-

62

-

torch.nn.functional.bilinear

-

-

63

-

torch.nn.functional.dropout

-

-

64

-

torch.nn.functional.alpha_dropout

-

-

65

-

torch.nn.functional.dropout2d

-

-

66

-

torch.nn.functional.dropout3d

-

-

67

-

torch.nn.functional.embedding

-

-

68

-

torch.nn.functional.embedding_bag

-

-

69

-

torch.nn.functional.one_hot

-

-

70

-

torch.nn.functional.pairwise_distance

-

-

71

-

torch.nn.functional.cosine_similarity

-

-

72

-

torch.nn.functional.pdist

-

-

73

-

torch.nn.functional.binary_cross_entropy

-

-

74

-

torch.nn.functional.binary_cross_entropy_with_logits

-

-

75

-

torch.nn.functional.poisson_nll_loss

-

-

76

-

torch.nn.functional.cosine_embedding_loss

-

-

77

-

torch.nn.functional.cross_entropy

-

-

78

-

torch.nn.functional.ctc_loss

-

-

79

-

torch.nn.functional.hinge_embedding_loss

-

-

80

-

torch.nn.functional.kl_div

-

-

81

-

torch.nn.functional.l1_loss

-

-

82

-

torch.nn.functional.mse_loss

-

-

83

-

torch.nn.functional.margin_ranking_loss

-

-

84

-

torch.nn.functional.multilabel_margin_loss

-

-

85

-

torch.nn.functional.multilabel_soft_margin_loss

-

-

86

-

torch.nn.functional.multi_margin_loss

-

-

87

-

torch.nn.functional.nll_loss

-

-

88

-

torch.nn.functional.smooth_l1_loss

-

-

89

-

torch.nn.functional.soft_margin_loss

-

-

90

-

torch.nn.functional.triplet_margin_loss

-

-

91

-

torch.nn.functional.pixel_shuffle

-

-

92

-

torch.nn.functional.pad

-

-

93

-

torch.nn.functional.interpolate

-

-

94

-

torch.nn.functional.upsample

-

-

95

-

torch.nn.functional.upsample_nearest

-

-

96

-

torch.nn.functional.upsample_bilinear

-

-

97

-

torch.nn.functional.grid_sample

-

-

98

-

torch.nn.functional.affine_grid

-

-

99

-

torch.nn.parallel.data_parallel

-

-
- -

torch.distributed

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

序号

-

API名称

-

是否支持(PyTorch1.5.0)

-

1

-

torch.distributed.init_process_group

-

-

2

-

torch.distributed.Backend

-

-

3

-

torch.distributed.get_backend

-

-

4

-

torch.distributed.get_rank

-

-

5

-

torch.distributed.get_world_size

-

-

6

-

torch.distributed.is_initialized

-

-

7

-

torch.distributed.is_mpi_available

-

-

8

-

torch.distributed.is_nccl_available

-

-

9

-

torch.distributed.new_group

-

-

10

-

torch.distributed.send

-

-

11

-

torch.distributed.recv

-

-

12

-

torch.distributed.isend

-

-

13

-

torch.distributed.irecv

-

-

14

-

is_completed

-

-

15

-

wait

-

-

16

-

torch.distributed.broadcast

-

-

17

-

torch.distributed.all_reduce

-

-

18

-

torch.distributed.reduce

-

-

19

-

torch.distributed.all_gather

-

-

20

-

torch.distributed.gather

-

-

21

-

torch.distributed.scatter

-

-

22

-

torch.distributed.barrier

-

-

23

-

torch.distributed.ReduceOp

-

-

24

-

torch.distributed.reduce_op

-

-

25

-

torch.distributed.broadcast_multigpu

-

-

26

-

torch.distributed.all_reduce_multigpu

-

-

27

-

torch.distributed.reduce_multigpu

-

-

28

-

torch.distributed.all_gather_multigpu

-

-

29

-

torch.distributed.launch

-

-

30

-

torch.multiprocessing.spawn

-

-
- -

NPU和CUDA功能对齐

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

序号

-

API名称

-

npu对应API名称

-

是否支持(PyTorch1.5.0)

-

1

-

torch.cuda.current_blas_handle

-

torch.npu.current_blas_handle

-

-

2

-

torch.cuda.current_device

-

torch.npu.current_device

-

-

3

-

torch.cuda.current_stream

-

torch.npu.current_stream

-

-

4

-

torch.cuda.default_stream

-

torch.npu.default_stream

-

-

5

-

torch.cuda.device

-

torch.npu.device

-

-

6

-

torch.cuda.device_count

-

torch.npu.device_count

-

-

7

-

torch.cuda.device_of

-

torch.npu.device_of

-

-

8

-

torch.cuda.get_device_capability

-

torch.npu.get_device_capability

-

-

9

-

torch.cuda.get_device_name

-

torch.npu.get_device_name

-

-

10

-

torch.cuda.init

-

torch.npu.init

-

-

11

-

torch.cuda.ipc_collect

-

torch.npu.ipc_collect

-

-

12

-

torch.cuda.is_available

-

torch.npu.is_available

-

-

13

-

torch.cuda.is_initialized

-

torch.npu.is_initialized

-

-

14

-

torch.cuda.set_device

-

torch.npu.set_device

-

部分支持

-

15

-

torch.cuda.stream

-

torch.npu.stream

-

-

16

-

torch.cuda.synchronize

-

torch.npu.synchronize

-

-

17

-

torch.cuda.get_rng_state

-

torch.npu.get_rng_state

-

-

18

-

torch.cuda.get_rng_state_all

-

torch.npu.get_rng_state_all

-

-

19

-

torch.cuda.set_rng_state

-

torch.npu.set_rng_state

-

-

20

-

torch.cuda.set_rng_state_all

-

torch.npu.set_rng_state_all

-

-

21

-

torch.cuda.manual_seed

-

torch.npu.manual_seed

-

-

22

-

torch.cuda.manual_seed_all

-

torch.npu.manual_seed_all

-

-

23

-

torch.cuda.seed

-

torch.npu.seed

-

-

24

-

torch.cuda.seed_all

-

torch.npu.seed_all

-

-

25

-

torch.cuda.initial_seed

-

torch.npu.initial_seed

-

-

26

-

torch.cuda.comm.broadcast

-

torch.npu.comm.broadcast

-

-

27

-

torch.cuda.comm.broadcast_coalesced

-

torch.npu.comm.broadcast_coalesced

-

-

28

-

torch.cuda.comm.reduce_add

-

torch.npu.comm.reduce_add

-

-

29

-

torch.cuda.comm.scatter

-

torch.npu.comm.scatter

-

-

30

-

torch.cuda.comm.gather

-

torch.npu.comm.gather

-

-

31

-

torch.cuda.Stream

-

torch.npu.Stream

-

-

32

-

torch.cuda.Stream.query

-

torch.npu.Stream.query

-

-

33

-

torch.cuda.Stream.record_event

-

torch.npu.Stream.record_event

-

-

34

-

torch.cuda.Stream.synchronize

-

torch.npu.Stream.synchronize

-

-

35

-

torch.cuda.Stream.wait_event

-

torch.npu.Stream.wait_event

-

-

36

-

torch.cuda.Stream.wait_stream

-

torch.npu.Stream.wait_stream

-

-

37

-

torch.cuda.Event

-

torch.npu.Event

-

-

38

-

torch.cuda.Event.elapsed_time

-

torch.npu.Event.elapsed_time

-

-

39

-

torch.cuda.Event.from_ipc_handle

-

torch.npu.Event.from_ipc_handle

-

-

40

-

torch.cuda.Event.ipc_handle

-

torch.npu.Event.ipc_handle

-

-

41

-

torch.cuda.Event.query

-

torch.npu.Event.query

-

-

42

-

torch.cuda.Event.record

-

torch.npu.Event.record

-

-

43

-

torch.cuda.Event.synchronize

-

torch.npu.Event.synchronize

-

-

44

-

torch.cuda.Event.wait

-

torch.npu.Event.wait

-

-

45

-

torch.cuda.empty_cache

-

torch.npu.empty_cache

-

-

46

-

torch.cuda.memory_stats

-

torch.npu.memory_stats

-

-

47

-

torch.cuda.memory_summary

-

torch.npu.memory_summary

-

-

48

-

torch.cuda.memory_snapshot

-

torch.npu.memory_snapshot

-

-

49

-

torch.cuda.memory_allocated

-

torch.npu.memory_allocated

-

-

50

-

torch.cuda.max_memory_allocated

-

torch.npu.max_memory_allocated

-

-

51

-

torch.cuda.reset_max_memory_allocated

-

torch.npu.reset_max_memory_allocated

-

-

52

-

torch.cuda.memory_reserved

-

torch.npu.memory_reserved

-

-

53

-

torch.cuda.max_memory_reserved

-

torch.npu.max_memory_reserved

-

-

54

-

torch.cuda.memory_cached

-

torch.npu.memory_cached

-

-

55

-

torch.cuda.max_memory_cached

-

torch.npu.max_memory_cached

-

-

56

-

torch.cuda.reset_max_memory_cached

-

torch.npu.reset_max_memory_cached

-

-

57

-

torch.cuda.nvtx.mark

-

torch.npu.nvtx.mark

-

-

58

-

torch.cuda.nvtx.range_push

-

torch.npu.nvtx.range_push

-

-

59

-

torch.cuda.nvtx.range_pop

-

torch.npu.nvtx.range_pop

-

-

60

-

torch.cuda._sleep

-

torch.npu._sleep

-

-

61

-

torch.cuda.Stream.priority_range

-

torch.npu.Stream.priority_range

-

-

62

-

torch.cuda.get_device_properties

-

torch.npu.get_device_properties

-

-

63

-

torch.cuda.amp.GradScaler

-

torch.npu.amp.GradScaler

-

-
- ->![](public_sys-resources/icon-note.gif) **说明:** ->torch.npu.set\_device\(\)接口只支持在程序开始的位置通过set\_device进行指定,不支持多次指定和with torch.npu.device\(id\)方式的device切换 - diff --git "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-caution.gif" "b/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-caution.gif" deleted file mode 100644 index 6e90d7cfc2193e39e10bb58c38d01a23f045d571..0000000000000000000000000000000000000000 Binary files "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-caution.gif" and /dev/null differ diff --git "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-danger.gif" "b/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-danger.gif" deleted file mode 100644 index 6e90d7cfc2193e39e10bb58c38d01a23f045d571..0000000000000000000000000000000000000000 Binary files "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-danger.gif" and /dev/null differ diff --git "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-note.gif" "b/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-note.gif" deleted file mode 100644 index 6314297e45c1de184204098efd4814d6dc8b1cda..0000000000000000000000000000000000000000 Binary files "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-note.gif" and /dev/null differ diff --git "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-notice.gif" "b/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-notice.gif" deleted file mode 100644 index 86024f61b691400bea99e5b1f506d9d9aef36e27..0000000000000000000000000000000000000000 Binary files "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-notice.gif" and /dev/null differ diff --git "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-tip.gif" "b/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-tip.gif" deleted file mode 100644 index 93aa72053b510e456b149f36a0972703ea9999b7..0000000000000000000000000000000000000000 Binary files "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-tip.gif" and /dev/null differ diff --git "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-warning.gif" "b/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-warning.gif" deleted file mode 100644 index 6e90d7cfc2193e39e10bb58c38d01a23f045d571..0000000000000000000000000000000000000000 Binary files "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225/public_sys-resources/icon-warning.gif" and /dev/null differ diff --git "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225_1.5.0.md" "b/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225_1.5.0.md" new file mode 100644 index 0000000000000000000000000000000000000000..ec95cc153c0f391ca7b3e085990fd6fb48796651 --- /dev/null +++ "b/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225_1.5.0.md" @@ -0,0 +1,1374 @@ +## [Tensors](https://pytorch.org/docs/1.5.0/torch.html) + +| 序号 | API名称 | 支持情况 | +| ---- | ----------------------------- | -------------------------------------- | +| 1 | torch.is_tensor | 是 | +| 2 | torch.is_storage | 是 | +| 3 | torch.is_complex | 是,支持判断,但当前硬件限制不支持复数 | +| 4 | torch.is_floating_point | 是 | +| 5 | torch.set_default_dtype | 是 | +| 6 | torch.get_default_dtype | 是 | +| 7 | torch.set_default_tensor_type | 是 | +| 8 | torch.numel | 是 | +| 9 | torch.set_printoptions | 是 | +| 10 | torch.set_flush_denormal | 是 | +| 11 | torch.tensor | 是 | +| 12 | torch.sparse_coo_tensor | 否 | +| 13 | torch.as_tensor | 是 | +| 14 | torch.as_strided | 是 | +| 15 | torch.from_numpy | 是 | +| 16 | torch.zeros | 是 | +| 17 | torch.zeros_like | 是 | +| 18 | torch.ones | 是 | +| 19 | torch.ones_like | 是 | +| 20 | torch.arange | 是 | +| 21 | torch.range | 是 | +| 22 | torch.linspace | 是 | +| 23 | torch.logspace | 是 | +| 24 | torch.eye | 是 | +| 25 | torch.empty | 是 | +| 26 | torch.empty_like | 是 | +| 27 | torch.empty_strided | 是 | +| 28 | torch.full | 是 | +| 29 | torch.full_like | 是 | +| 30 | torch.quantize_per_tensor | 是 | +| 31 | torch.quantize_per_channel | 是 | +| 32 | torch.cat | 是 | +| 33 | torch.chunk | 是 | +| 34 | torch.gather | 是 | +| 35 | torch.index_select | 是 | +| 36 | torch.masked_select | 是 | +| 37 | torch.narrow | 是 | +| 38 | torch.nonzero | 是 | +| 39 | torch.reshape | 是 | +| 40 | torch.split | 是 | +| 41 | torch.squeeze | 是 | +| 42 | torch.stack | 是 | +| 43 | torch.t | 是 | +| 44 | torch.take | 是 | +| 45 | torch.transpose | 是 | +| 46 | torch.unbind | 是 | +| 47 | torch.unsqueeze | 是 | +| 48 | torch.where | 是 | + +## Generators + +| 序号 | API名称 | 是否支持 | +| ---- | ------------------------------- | -------- | +| 1 | torch._C.Generator | 是 | +| 2 | torch._C.Generator.device | 是 | +| 3 | torch._C.Generator.get_state | 否 | +| 4 | torch._C.Generator.initial_seed | 是 | +| 5 | torch._C.Generator.manual_seed | 是 | +| 6 | torch._C.Generator.seed | 是 | +| 7 | torch._C.Generator.set_state | 否 | + +## Random sampling + +| 序号 | API名称 | 是否支持 | +| ---- | ------------------------------------------ | -------- | +| 1 | torch.seed | 是 | +| 2 | torch.manual_seed | 是 | +| 3 | torch.initial_seed | 是 | +| 4 | torch.get_rng_state | 是 | +| 5 | torch.set_rng_state | 是 | +| 6 | torch.torch.default_generator | 是 | +| 7 | torch.bernoulli | 是 | +| 8 | torch.multinomial | 是 | +| 9 | torch.normal | 是 | +| 10 | torch.poisson | 否 | +| 11 | torch.rand | 是 | +| 12 | torch.rand_like | 是 | +| 13 | torch.randint | 是 | +| 14 | torch.randint_like | 是 | +| 15 | torch.randn | 是 | +| 16 | torch.randn_like | 是 | +| 17 | torch.randperm | 是 | +| 18 | torch.Tensor.bernoulli_() | 是 | +| 19 | torch.Tensor.bernoulli_() | 是 | +| 20 | torch.Tensor.exponential_() | 否 | +| 21 | torch.Tensor.geometric_() | 否 | +| 22 | torch.Tensor.log_normal_() | 否 | +| 23 | torch.Tensor.normal_() | 是 | +| 24 | torch.Tensor.random_() | 是 | +| 25 | torch.Tensor.uniform_() | 是 | +| 26 | torch.quasirandom.SobolEngine | 是 | +| 27 | torch.quasirandom.SobolEngine.draw | 是 | +| 28 | torch.quasirandom.SobolEngine.fast_forward | 是 | +| 29 | torch.quasirandom.SobolEngine.reset | 是 | + +## Serialization + +| 序号 | API名称 | 是否支持 | +| ---- | ---------- | -------- | +| 1 | torch.save | 是 | +| 2 | torch.load | 是 | + +## Math operations + +| 序号 | API名称 | 是否支持 | +| ---- | ------------------------ | -------- | +| 1 | torch.abs | 是 | +| 2 | torch.acos | 是 | +| 3 | torch.add | 是 | +| 4 | torch.addcdiv | 是 | +| 5 | torch.addcmul | 是 | +| 6 | torch.angle | 否 | +| 7 | torch.asin | 是 | +| 8 | torch.atan | 是 | +| 9 | torch.atan2 | 是 | +| 10 | torch.bitwise_not | 是 | +| 11 | torch.bitwise_and | 是 | +| 12 | torch.bitwise_or | 是 | +| 13 | torch.bitwise_xor | 是 | +| 14 | torch.ceil | 是 | +| 15 | torch.clamp | 是 | +| 16 | torch.conj | 否 | +| 17 | torch.cos | 是 | +| 18 | torch.cosh | 是 | +| 19 | torch.div | 是 | +| 20 | torch.digamma | 否 | +| 21 | torch.erf | 是 | +| 22 | torch.erfc | 是 | +| 23 | torch.erfinv | 是 | +| 24 | torch.exp | 是 | +| 25 | torch.expm1 | 是 | +| 26 | torch.floor | 是 | +| 27 | torch.floor_divide | 是 | +| 28 | torch.fmod | 是 | +| 29 | torch.frac | 是 | +| 30 | torch.imag | 否 | +| 31 | torch.lerp | 是 | +| 32 | torch.lgamma | 否 | +| 33 | torch.log | 是 | +| 34 | torch.log10 | 是 | +| 35 | torch.log1p | 是 | +| 36 | torch.log2 | 是 | +| 37 | torch.logical_and | 是 | +| 38 | torch.logical_not | 是 | +| 39 | torch.logical_or | 是 | +| 40 | torch.logical_xor | 是 | +| 41 | torch.mul | 是 | +| 42 | torch.mvlgamma | 否 | +| 43 | torch.neg | 是 | +| 44 | torch.polygamma | 否 | +| 45 | torch.pow | 是 | +| 46 | torch.real | 是 | +| 47 | torch.reciprocal | 是 | +| 48 | torch.remainder | 是 | +| 49 | torch.round | 是 | +| 50 | torch.rsqrt | 是 | +| 51 | torch.sigmoid | 是 | +| 52 | torch.sign | 是 | +| 53 | torch.sin | 是 | +| 54 | torch.sinh | 是 | +| 55 | torch.sqrt | 是 | +| 56 | torch.square | 是 | +| 57 | torch.tan | 是 | +| 58 | torch.tanh | 是 | +| 59 | torch.true_divide | 是 | +| 60 | torch.trunc | 是 | +| 61 | torch.argmax | 是 | +| 62 | torch.argmin | 是 | +| 63 | torch.dist | 是 | +| 64 | torch.logsumexp | 是 | +| 65 | torch.mean | 是 | +| 66 | torch.median | 是 | +| 67 | torch.mode | 否 | +| 68 | torch.norm | 是 | +| 69 | torch.prod | 是 | +| 70 | torch.std | 是 | +| 71 | torch.std_mean | 是 | +| 72 | torch.sum | 是 | +| 73 | torch.unique | 是 | +| 74 | torch.unique_consecutive | 否 | +| 75 | torch.var | 否 | +| 76 | torch.var_mean | 否 | +| 77 | torch.allclose | 是 | +| 78 | torch.argsort | 是 | +| 79 | torch.eq | 是 | +| 80 | torch.equal | 是 | +| 81 | torch.ge | 是 | +| 82 | torch.gt | 是 | +| 83 | torch.isfinite | 是 | +| 84 | torch.isinf | 是 | +| 85 | torch.isnan | 是 | +| 86 | torch.kthvalue | 是 | +| 87 | torch.le | 是 | +| 88 | torch.lt | 是 | +| 89 | torch.max | 是 | +| 90 | torch.min | 是 | +| 91 | torch.ne | 是 | +| 92 | torch.sort | 是 | +| 93 | torch.topk | 是 | +| 94 | torch.fft | 否 | +| 95 | torch.ifft | 否 | +| 96 | torch.rfft | 否 | +| 97 | torch.irfft | 否 | +| 98 | torch.stft | 否 | +| 99 | torch.bartlett_window | 是 | +| 100 | torch.blackman_window | 是 | +| 101 | torch.hamming_window | 是 | +| 102 | torch.hann_window | 是 | +| 103 | torch.bincount | 是 | +| 104 | torch.broadcast_tensors | 是 | +| 105 | torch.cartesian_prod | 是 | +| 106 | torch.cdist | 是 | +| 107 | torch.combinations | 否 | +| 108 | torch.cross | 是 | +| 109 | torch.cummax | 是 | +| 110 | torch.cummin | 是 | +| 111 | torch.cumprod | 是 | +| 112 | torch.cumsum | 是 | +| 113 | torch.diag | 是 | +| 114 | torch.diag_embed | 是 | +| 115 | torch.diagflat | 是 | +| 116 | torch.diagonal | 是 | +| 117 | torch.einsum | 是 | +| 118 | torch.flatten | 是 | +| 119 | torch.flip | 是 | +| 120 | torch.rot90 | 是 | +| 121 | torch.histc | 否 | +| 122 | torch.meshgrid | 是 | +| 123 | torch.renorm | 是 | +| 124 | torch.repeat_interleave | 是 | +| 125 | torch.roll | 是 | +| 126 | torch.tensordot | 是 | +| 127 | torch.trace | 否 | +| 128 | torch.tril | 是 | +| 129 | torch.tril_indices | 是 | +| 130 | torch.triu | 是 | +| 131 | torch.triu_indices | 是 | +| 132 | torch.addbmm | 是 | +| 133 | torch.addmm | 是 | +| 134 | torch.addmv | 是 | +| 135 | torch.addr | 是 | +| 136 | torch.baddbmm | 是 | +| 137 | torch.bmm | 是 | +| 138 | torch.chain_matmul | 是 | +| 139 | torch.cholesky | 否 | +| 140 | torch.cholesky_inverse | 否 | +| 141 | torch.cholesky_solve | 否 | +| 142 | torch.dot | 是 | +| 143 | torch.eig | 否 | +| 144 | torch.geqrf | 否 | +| 145 | torch.ger | 是 | +| 146 | torch.inverse | 是 | +| 147 | torch.det | 否 | +| 148 | torch.logdet | 否 | +| 149 | torch.slogdet | 是 | +| 150 | torch.lstsq | 否 | +| 151 | torch.lu | 否 | +| 152 | torch.lu_solve | 否 | +| 153 | torch.lu_unpack | 否 | +| 154 | torch.matmul | 是 | +| 155 | torch.matrix_power | 是 | +| 156 | torch.matrix_rank | 是 | +| 157 | torch.mm | 是 | +| 158 | torch.mv | 是 | +| 159 | torch.orgqr | 否 | +| 160 | torch.ormqr | 否 | +| 161 | torch.pinverse | 是 | +| 162 | torch.qr | 是 | +| 163 | torch.solve | 否 | +| 164 | torch.svd | 是 | +| 165 | torch.svd_lowrank | 是 | +| 166 | torch.pca_lowrank | 是 | +| 167 | torch.symeig | 是 | +| 168 | torch.lobpcg | 否 | +| 169 | torch.trapz | 是 | +| 170 | torch.triangular_solve | 是 | + +## Utilities + +| 序号 | API名称 | 是否支持 | +| ---- | ----------------------------- | -------- | +| 1 | torch.compiled_with_cxx11_abi | 是 | +| 2 | torch.result_type | 是 | +| 3 | torch.can_cast | 是 | +| 4 | torch.promote_types | 是 | + +## Other + +| 序号 | API名称 | 是否支持 | +| ---- | ----------------------------- | -------- | +| 1 | torch.no_grad | 是 | +| 2 | torch.enable_grad | 是 | +| 3 | torch.set_grad_enabled | 是 | +| 4 | torch.get_num_threads | 是 | +| 5 | torch.set_num_threads | 是 | +| 6 | torch.get_num_interop_threads | 是 | +| 7 | torch.set_num_interop_threads | 是 | + +## torch.Tensor + +| 序号 | API名称 | 是否支持 | +| ---- | -------------------------------------- | -------- | +| 1 | torch.Tensor | 是 | +| 2 | torch.Tensor.new_tensor | 是 | +| 3 | torch.Tensor.new_full | 是 | +| 4 | torch.Tensor.new_empty | 是 | +| 5 | torch.Tensor.new_ones | 是 | +| 6 | torch.Tensor.new_zeros | 是 | +| 7 | torch.Tensor.is_cuda | 是 | +| 8 | torch.Tensor.is_quantized | 是 | +| 9 | torch.Tensor.device | 是 | +| 10 | torch.Tensor.ndim | 是 | +| 11 | torch.Tensor.T | 是 | +| 12 | torch.Tensor.abs | 是 | +| 13 | torch.Tensor.abs_ | 是 | +| 14 | torch.Tensor.acos | 是 | +| 15 | torch.Tensor.acos_ | 是 | +| 16 | torch.Tensor.add | 是 | +| 17 | torch.Tensor.add_ | 是 | +| 18 | torch.Tensor.addbmm | 是 | +| 19 | torch.Tensor.addbmm_ | 是 | +| 20 | torch.Tensor.addcdiv | 是 | +| 21 | torch.Tensor.addcdiv_ | 是 | +| 22 | torch.Tensor.addcmul | 是 | +| 23 | torch.Tensor.addcmul_ | 是 | +| 24 | torch.Tensor.addmm | 是 | +| 25 | torch.Tensor.addmm_ | 是 | +| 26 | torch.Tensor.addmv | 是 | +| 27 | torch.Tensor.addmv_ | 是 | +| 28 | torch.Tensor.addr | 是 | +| 29 | torch.Tensor.addr_ | 是 | +| 30 | torch.Tensor.allclose | 是 | +| 31 | torch.Tensor.angle | 否 | +| 32 | torch.Tensor.apply_ | 否 | +| 33 | torch.Tensor.argmax | 是 | +| 34 | torch.Tensor.argmin | 是 | +| 35 | torch.Tensor.argsort | 是 | +| 36 | torch.Tensor.asin | 是 | +| 37 | torch.Tensor.asin_ | 是 | +| 38 | torch.Tensor.as_strided | 是 | +| 39 | torch.Tensor.atan | 是 | +| 40 | torch.Tensor.atan2 | 是 | +| 41 | torch.Tensor.atan2_ | 是 | +| 42 | torch.Tensor.atan_ | 是 | +| 43 | torch.Tensor.baddbmm | 是 | +| 44 | torch.Tensor.baddbmm_ | 是 | +| 45 | torch.Tensor.bernoulli | 是 | +| 46 | torch.Tensor.bernoulli_ | 是 | +| 47 | torch.Tensor.bfloat16 | 否 | +| 48 | torch.Tensor.bincount | 是 | +| 49 | torch.Tensor.bitwise_not | 是 | +| 50 | torch.Tensor.bitwise_not_ | 是 | +| 51 | torch.Tensor.bitwise_and | 是 | +| 52 | torch.Tensor.bitwise_and_ | 是 | +| 53 | torch.Tensor.bitwise_or | 是 | +| 54 | torch.Tensor.bitwise_or_ | 是 | +| 55 | torch.Tensor.bitwise_xor | 是 | +| 56 | torch.Tensor.bitwise_xor_ | 是 | +| 57 | torch.Tensor.bmm | 是 | +| 58 | torch.Tensor.bool | 是 | +| 59 | torch.Tensor.byte | 是 | +| 60 | torch.Tensor.cauchy_ | 否 | +| 61 | torch.Tensor.ceil | 是 | +| 62 | torch.Tensor.ceil_ | 是 | +| 63 | torch.Tensor.char | 是 | +| 64 | torch.Tensor.cholesky | 否 | +| 65 | torch.Tensor.cholesky_inverse | 否 | +| 66 | torch.Tensor.cholesky_solve | 否 | +| 67 | torch.Tensor.chunk | 是 | +| 68 | torch.Tensor.clamp | 是 | +| 69 | torch.Tensor.clamp_ | 是 | +| 70 | torch.Tensor.clone | 是 | +| 71 | torch.Tensor.contiguous | 是 | +| 72 | torch.Tensor.copy_ | 是 | +| 73 | torch.Tensor.conj | 否 | +| 74 | torch.Tensor.cos | 是 | +| 75 | torch.Tensor.cos_ | 是 | +| 76 | torch.Tensor.cosh | 是 | +| 77 | torch.Tensor.cosh_ | 是 | +| 78 | torch.Tensor.cpu | 是 | +| 79 | torch.Tensor.cross | 是 | +| 80 | torch.Tensor.cuda | 否 | +| 81 | torch.Tensor.cummax | 是 | +| 82 | torch.Tensor.cummin | 是 | +| 83 | torch.Tensor.cumprod | 是 | +| 84 | torch.Tensor.cumsum | 是 | +| 85 | torch.Tensor.data_ptr | 是 | +| 86 | torch.Tensor.dequantize | 否 | +| 87 | torch.Tensor.det | 否 | +| 88 | torch.Tensor.dense_dim | 否 | +| 89 | torch.Tensor.diag | 是 | +| 90 | torch.Tensor.diag_embed | 是 | +| 91 | torch.Tensor.diagflat | 是 | +| 92 | torch.Tensor.diagonal | 是 | +| 93 | torch.Tensor.fill_diagonal_ | 是 | +| 94 | torch.Tensor.digamma | 否 | +| 95 | torch.Tensor.digamma_ | 否 | +| 96 | torch.Tensor.dim | 是 | +| 97 | torch.Tensor.dist | 是 | +| 98 | torch.Tensor.div | 是 | +| 99 | torch.Tensor.div_ | 是 | +| 100 | torch.Tensor.dot | 是 | +| 101 | torch.Tensor.double | 否 | +| 102 | torch.Tensor.eig | 否 | +| 103 | torch.Tensor.element_size | 是 | +| 104 | torch.Tensor.eq | 是 | +| 105 | torch.Tensor.eq_ | 是 | +| 106 | torch.Tensor.equal | 是 | +| 107 | torch.Tensor.erf | 是 | +| 108 | torch.Tensor.erf_ | 是 | +| 109 | torch.Tensor.erfc | 是 | +| 110 | torch.Tensor.erfc_ | 是 | +| 111 | torch.Tensor.erfinv | 是 | +| 112 | torch.Tensor.erfinv_ | 是 | +| 113 | torch.Tensor.exp | 是 | +| 114 | torch.Tensor.exp_ | 是 | +| 115 | torch.Tensor.expm1 | 是 | +| 116 | torch.Tensor.expm1_ | 是 | +| 117 | torch.Tensor.expand | 是 | +| 118 | torch.Tensor.expand_as | 是 | +| 119 | torch.Tensor.exponential_ | 否 | +| 120 | torch.Tensor.fft | 否 | +| 121 | torch.Tensor.fill_ | 是 | +| 122 | torch.Tensor.flatten | 是 | +| 123 | torch.Tensor.flip | 是 | +| 124 | torch.Tensor.float | 是 | +| 125 | torch.Tensor.floor | 是 | +| 126 | torch.Tensor.floor_ | 是 | +| 127 | torch.Tensor.floor_divide | 是 | +| 128 | torch.Tensor.floor_divide_ | 是 | +| 129 | torch.Tensor.fmod | 是 | +| 130 | torch.Tensor.fmod_ | 是 | +| 131 | torch.Tensor.frac | 是 | +| 132 | torch.Tensor.frac_ | 是 | +| 133 | torch.Tensor.gather | 是 | +| 134 | torch.Tensor.ge | 是 | +| 135 | torch.Tensor.ge_ | 是 | +| 136 | torch.Tensor.geometric_ | 否 | +| 137 | torch.Tensor.geqrf | 否 | +| 138 | torch.Tensor.ger | 是 | +| 139 | torch.Tensor.get_device | 是 | +| 140 | torch.Tensor.gt | 是 | +| 141 | torch.Tensor.gt_ | 是 | +| 142 | torch.Tensor.half | 是 | +| 143 | torch.Tensor.hardshrink | 是 | +| 144 | torch.Tensor.histc | 否 | +| 145 | torch.Tensor.ifft | 否 | +| 146 | torch.Tensor.index_add_ | 是 | +| 147 | torch.Tensor.index_add | 是 | +| 148 | torch.Tensor.index_copy_ | 是 | +| 149 | torch.Tensor.index_copy | 是 | +| 150 | torch.Tensor.index_fill_ | 是 | +| 151 | torch.Tensor.index_fill | 是 | +| 152 | torch.Tensor.index_put_ | 是 | +| 153 | torch.Tensor.index_put | 是 | +| 154 | torch.Tensor.index_select | 是 | +| 155 | torch.Tensor.indices | 否 | +| 156 | torch.Tensor.int | 是 | +| 157 | torch.Tensor.int_repr | 否 | +| 158 | torch.Tensor.inverse | 是 | +| 159 | torch.Tensor.irfft | 否 | +| 160 | torch.Tensor.is_contiguous | 是 | +| 161 | torch.Tensor.is_complex | 是 | +| 162 | torch.Tensor.is_floating_point | 是 | +| 163 | torch.Tensor.is_pinned | 是 | +| 164 | torch.Tensor.is_set_to | 否 | +| 165 | torch.Tensor.is_shared | 是 | +| 166 | torch.Tensor.is_signed | 是 | +| 167 | torch.Tensor.is_sparse | 是 | +| 168 | torch.Tensor.item | 是 | +| 169 | torch.Tensor.kthvalue | 是 | +| 170 | torch.Tensor.le | 是 | +| 171 | torch.Tensor.le_ | 是 | +| 172 | torch.Tensor.lerp | 是 | +| 173 | torch.Tensor.lerp_ | 是 | +| 174 | torch.Tensor.lgamma | 否 | +| 175 | torch.Tensor.lgamma_ | 否 | +| 176 | torch.Tensor.log | 是 | +| 177 | torch.Tensor.log_ | 是 | +| 178 | torch.Tensor.logdet | 否 | +| 179 | torch.Tensor.log10 | 是 | +| 180 | torch.Tensor.log10_ | 是 | +| 181 | torch.Tensor.log1p | 是 | +| 182 | torch.Tensor.log1p_ | 是 | +| 183 | torch.Tensor.log2 | 是 | +| 184 | torch.Tensor.log2_ | 是 | +| 185 | torch.Tensor.log_normal_ | 是 | +| 186 | torch.Tensor.logsumexp | 是 | +| 187 | torch.Tensor.logical_and | 是 | +| 188 | torch.Tensor.logical_and_ | 是 | +| 189 | torch.Tensor.logical_not | 是 | +| 190 | torch.Tensor.logical_not_ | 是 | +| 191 | torch.Tensor.logical_or | 是 | +| 192 | torch.Tensor.logical_or_ | 是 | +| 193 | torch.Tensor.logical_xor | 否 | +| 194 | torch.Tensor.logical_xor_ | 否 | +| 195 | torch.Tensor.long | 是 | +| 196 | torch.Tensor.lstsq | 否 | +| 197 | torch.Tensor.lt | 是 | +| 198 | torch.Tensor.lt_ | 是 | +| 199 | torch.Tensor.lu | 是 | +| 200 | torch.Tensor.lu_solve | 是 | +| 201 | torch.Tensor.map_ | 否 | +| 202 | torch.Tensor.masked_scatter_ | 是 | +| 203 | torch.Tensor.masked_scatter | 是 | +| 204 | torch.Tensor.masked_fill_ | 是 | +| 205 | torch.Tensor.masked_fill | 是 | +| 206 | torch.Tensor.masked_select | 是 | +| 207 | torch.Tensor.matmul | 是 | +| 208 | torch.Tensor.matrix_power | 是 | +| 209 | torch.Tensor.max | 是 | +| 210 | torch.Tensor.mean | 是 | +| 211 | torch.Tensor.median | 是 | +| 212 | torch.Tensor.min | 是 | +| 213 | torch.Tensor.mm | 是 | +| 214 | torch.Tensor.mode | 否 | +| 215 | torch.Tensor.mul | 是 | +| 216 | torch.Tensor.mul_ | 是 | +| 217 | torch.Tensor.multinomial | 是 | +| 218 | torch.Tensor.mv | 是 | +| 219 | torch.Tensor.mvlgamma | 否 | +| 220 | torch.Tensor.mvlgamma_ | 否 | +| 221 | torch.Tensor.narrow | 是 | +| 222 | torch.Tensor.narrow_copy | 是 | +| 223 | torch.Tensor.ndimension | 是 | +| 224 | torch.Tensor.ne | 是 | +| 225 | torch.Tensor.ne_ | 是 | +| 226 | torch.Tensor.neg | 是 | +| 227 | torch.Tensor.neg_ | 是 | +| 228 | torch.Tensor.nelement | 是 | +| 229 | torch.Tensor.nonzero | 是 | +| 230 | torch.Tensor.norm | 是 | +| 231 | torch.Tensor.normal_ | 是 | +| 232 | torch.Tensor.numel | 是 | +| 233 | torch.Tensor.numpy | 否 | +| 234 | torch.Tensor.orgqr | 否 | +| 235 | torch.Tensor.ormqr | 否 | +| 236 | torch.Tensor.permute | 是 | +| 237 | torch.Tensor.pin_memory | 否 | +| 238 | torch.Tensor.pinverse | 是 | +| 239 | torch.Tensor.polygamma | 否 | +| 240 | torch.Tensor.polygamma_ | 否 | +| 241 | torch.Tensor.pow | 是 | +| 242 | torch.Tensor.pow_ | 是 | +| 243 | torch.Tensor.prod | 是 | +| 244 | torch.Tensor.put_ | 是 | +| 245 | torch.Tensor.qr | 是 | +| 246 | torch.Tensor.qscheme | 否 | +| 247 | torch.Tensor.q_scale | 否 | +| 248 | torch.Tensor.q_zero_point | 否 | +| 249 | torch.Tensor.q_per_channel_scales | 否 | +| 250 | torch.Tensor.q_per_channel_zero_points | 否 | +| 251 | torch.Tensor.q_per_channel_axis | 否 | +| 252 | torch.Tensor.random_ | 是 | +| 253 | torch.Tensor.reciprocal | 是 | +| 254 | torch.Tensor.reciprocal_ | 是 | +| 255 | torch.Tensor.record_stream | 是 | +| 256 | torch.Tensor.remainder | 是 | +| 257 | torch.Tensor.remainder_ | 是 | +| 258 | torch.Tensor.renorm | 是 | +| 259 | torch.Tensor.renorm_ | 是 | +| 260 | torch.Tensor.repeat | 是 | +| 261 | torch.Tensor.repeat_interleave | 是 | +| 262 | torch.Tensor.requires_grad_ | 是 | +| 263 | torch.Tensor.reshape | 是 | +| 264 | torch.Tensor.reshape_as | 是 | +| 265 | torch.Tensor.resize_ | 是 | +| 266 | torch.Tensor.resize_as_ | 是 | +| 267 | torch.Tensor.rfft | 否 | +| 268 | torch.Tensor.roll | 是 | +| 269 | torch.Tensor.rot90 | 是 | +| 270 | torch.Tensor.round | 是 | +| 271 | torch.Tensor.round_ | 是 | +| 272 | torch.Tensor.rsqrt | 是 | +| 273 | torch.Tensor.rsqrt_ | 是 | +| 274 | torch.Tensor.scatter | 是 | +| 275 | torch.Tensor.scatter_ | 是 | +| 276 | torch.Tensor.scatter_add_ | 是 | +| 277 | torch.Tensor.scatter_add | 是 | +| 278 | torch.Tensor.select | 是 | +| 279 | torch.Tensor.set_ | 是 | +| 280 | torch.Tensor.share_memory_ | 否 | +| 281 | torch.Tensor.short | 是 | +| 282 | torch.Tensor.sigmoid | 是 | +| 283 | torch.Tensor.sigmoid_ | 是 | +| 284 | torch.Tensor.sign | 是 | +| 285 | torch.Tensor.sign_ | 是 | +| 286 | torch.Tensor.sin | 是 | +| 287 | torch.Tensor.sin_ | 是 | +| 288 | torch.Tensor.sinh | 是 | +| 289 | torch.Tensor.sinh_ | 是 | +| 290 | torch.Tensor.size | 是 | +| 291 | torch.Tensor.slogdet | 是 | +| 292 | torch.Tensor.solve | 否 | +| 293 | torch.Tensor.sort | 是 | +| 294 | torch.Tensor.split | 是 | +| 295 | torch.Tensor.sparse_mask | 否 | +| 296 | torch.Tensor.sparse_dim | 否 | +| 297 | torch.Tensor.sqrt | 是 | +| 298 | torch.Tensor.sqrt_ | 是 | +| 299 | torch.Tensor.square | 是 | +| 300 | torch.Tensor.square_ | 是 | +| 301 | torch.Tensor.squeeze | 是 | +| 302 | torch.Tensor.squeeze_ | 是 | +| 303 | torch.Tensor.std | 是 | +| 304 | torch.Tensor.stft | 否 | +| 305 | torch.Tensor.storage | 是 | +| 306 | torch.Tensor.storage_offset | 是 | +| 307 | torch.Tensor.storage_type | 是 | +| 308 | torch.Tensor.stride | 是 | +| 309 | torch.Tensor.sub | 是 | +| 310 | torch.Tensor.sub_ | 是 | +| 311 | torch.Tensor.sum | 是 | +| 312 | torch.Tensor.sum_to_size | 是 | +| 313 | torch.Tensor.svd | 是 | +| 314 | torch.Tensor.symeig | 是 | +| 315 | torch.Tensor.t | 是 | +| 316 | torch.Tensor.t_ | 是 | +| 317 | torch.Tensor.to | 是 | +| 318 | torch.Tensor.to_mkldnn | 否 | +| 319 | torch.Tensor.take | 是 | +| 320 | torch.Tensor.tan | 是 | +| 321 | torch.Tensor.tan_ | 是 | +| 322 | torch.Tensor.tanh | 是 | +| 323 | torch.Tensor.tanh_ | 是 | +| 324 | torch.Tensor.tolist | 是 | +| 325 | torch.Tensor.topk | 是 | +| 326 | torch.Tensor.to_sparse | 否 | +| 327 | torch.Tensor.trace | 否 | +| 328 | torch.Tensor.transpose | 是 | +| 329 | torch.Tensor.transpose_ | 是 | +| 330 | torch.Tensor.triangular_solve | 是 | +| 331 | torch.Tensor.tril | 是 | +| 332 | torch.Tensor.tril_ | 是 | +| 333 | torch.Tensor.triu | 是 | +| 334 | torch.Tensor.triu_ | 是 | +| 335 | torch.Tensor.true_divide | 是 | +| 336 | torch.Tensor.true_divide_ | 是 | +| 337 | torch.Tensor.trunc | 是 | +| 338 | torch.Tensor.trunc_ | 是 | +| 339 | torch.Tensor.type | 是 | +| 340 | torch.Tensor.type_as | 是 | +| 341 | torch.Tensor.unbind | 是 | +| 342 | torch.Tensor.unfold | 是 | +| 343 | torch.Tensor.uniform_ | 是 | +| 344 | torch.Tensor.unique | 是 | +| 345 | torch.Tensor.unique_consecutive | 否 | +| 346 | torch.Tensor.unsqueeze | 是 | +| 347 | torch.Tensor.unsqueeze_ | 是 | +| 348 | torch.Tensor.values | 否 | +| 349 | torch.Tensor.var | 否 | +| 350 | torch.Tensor.view | 是 | +| 351 | torch.Tensor.view_as | 是 | +| 352 | torch.Tensor.where | 是 | +| 353 | torch.Tensor.zero_ | 是 | +| 354 | torch.BoolTensor | 是 | +| 355 | torch.BoolTensor.all | 是 | +| 356 | torch.BoolTensor.any | 是 | + +## Layers (torch.nn) + +| 序号 | API名称 | 是否支持 | +| ---- | -------------------------------------------------------- | ---------------------------- | +| 1 | torch.nn.Parameter | 是 | +| 2 | torch.nn.Module | 是 | +| 3 | torch.nn.Module.add_module | 是 | +| 4 | torch.nn.Module.apply | 是 | +| 5 | torch.nn.Module.bfloat16 | 否 | +| 6 | torch.nn.Module.buffers | 是 | +| 7 | torch.nn.Module.children | 是 | +| 8 | torch.nn.Module.cpu | 是 | +| 9 | torch.nn.Module.cuda | 否 | +| 10 | torch.nn.Module.double | 否 | +| 11 | torch.nn.Module.dump_patches | 是 | +| 12 | torch.nn.Module.eval | 是 | +| 13 | torch.nn.Module.extra_repr | 是 | +| 14 | torch.nn.Module.float | 是 | +| 15 | torch.nn.Module.forward | 是 | +| 16 | torch.nn.Module.half | 是 | +| 17 | torch.nn.Module.load_state_dict | 是 | +| 18 | torch.nn.Module.modules | 是 | +| 19 | torch.nn.Module.named_buffers | 是 | +| 20 | torch.nn.Module.named_children | 是 | +| 21 | torch.nn.Module.named_modules | 是 | +| 22 | torch.nn.Module.named_parameters | 是 | +| 23 | torch.nn.Module.parameters | 是 | +| 24 | torch.nn.Module.register_backward_hook | 是 | +| 25 | torch.nn.Module.register_buffer | 是 | +| 26 | torch.nn.Module.register_forward_hook | 是 | +| 27 | torch.nn.Module.register_forward_pre_hook | 是 | +| 28 | torch.nn.Module.register_parameter | 是 | +| 29 | torch.nn.Module.requires_grad_ | 是 | +| 30 | torch.nn.Module.state_dict | 是 | +| 31 | torch.nn.Module.to | 是 | +| 32 | torch.nn.Module.train | 是 | +| 33 | torch.nn.Module.type | 是 | +| 34 | torch.nn.Module.zero_grad | 是 | +| 35 | torch.nn.Sequential | 是 | +| 36 | torch.nn.ModuleList | 是 | +| 37 | torch.nn.ModuleList.append | 是 | +| 38 | torch.nn.ModuleList.extend | 是 | +| 39 | torch.nn.ModuleList.insert | 是 | +| 40 | torch.nn.ModuleDict | 是 | +| 41 | torch.nn.ModuleDict.clear | 是 | +| 42 | torch.nn.ModuleDict.items | 是 | +| 43 | torch.nn.ModuleDict.keys | 是 | +| 44 | torch.nn.ModuleDict.pop | 是 | +| 45 | torch.nn.ModuleDict.update | 是 | +| 46 | torch.nn.ModuleDict.values | 是 | +| 47 | torch.nn.ParameterList | 是 | +| 48 | torch.nn.ParameterList.append | 是 | +| 49 | torch.nn.ParameterList.extend | 是 | +| 50 | torch.nn.ParameterDict | 是 | +| 51 | torch.nn.ParameterDict.clear | 是 | +| 52 | torch.nn.ParameterDict.items | 是 | +| 53 | torch.nn.ParameterDict.keys | 是 | +| 54 | torch.nn.ParameterDict.pop | 是 | +| 55 | torch.nn.ParameterDict.update | 是 | +| 56 | torch.nn.ParameterDict.values | 是 | +| 57 | torch.nn.Conv1d | 是 | +| 58 | torch.nn.Conv2d | 是 | +| 59 | torch.nn.Conv3d | 是 | +| 60 | torch.nn.ConvTranspose1d | 是 | +| 61 | torch.nn.ConvTranspose2d | 是 | +| 62 | torch.nn.ConvTranspose3d | 是 | +| 63 | torch.nn.Unfold | 是 | +| 64 | torch.nn.Fold | 是 | +| 65 | torch.nn.MaxPool1d | 是 | +| 66 | torch.nn.MaxPool2d | 是 | +| 67 | torch.nn.MaxPool3d | 是 | +| 68 | torch.nn.MaxUnpool1d | 是 | +| 69 | torch.nn.MaxUnpool2d | 是 | +| 70 | torch.nn.MaxUnpool3d | 是 | +| 71 | torch.nn.AvgPool1d | 是 | +| 72 | torch.nn.AvgPool2d | 是 | +| 73 | torch.nn.AvgPool3d | 是 | +| 74 | torch.nn.FractionalMaxPool2d | 否 | +| 75 | torch.nn.LPPool1d | 是 | +| 76 | torch.nn.LPPool2d | 是 | +| 77 | torch.nn.AdaptiveMaxPool1d | 是 | +| 78 | torch.nn.AdaptiveMaxPool2d | 是 | +| 79 | torch.nn.AdaptiveMaxPool3d | 否 | +| 80 | torch.nn.AdaptiveAvgPool1d | 是 | +| 81 | torch.nn.AdaptiveAvgPool2d | 是 | +| 82 | torch.nn.AdaptiveAvgPool3d | 是,仅支持D=1,H=1,W=1场景 | +| 83 | torch.nn.ReflectionPad1d | 否 | +| 84 | torch.nn.ReflectionPad2d | 是 | +| 85 | torch.nn.ReplicationPad1d | 否 | +| 86 | torch.nn.ReplicationPad2d | 是 | +| 87 | torch.nn.ReplicationPad3d | 否 | +| 88 | torch.nn.ZeroPad2d | 是 | +| 89 | torch.nn.ConstantPad1d | 是 | +| 90 | torch.nn.ConstantPad2d | 是 | +| 91 | torch.nn.ConstantPad3d | 是 | +| 92 | torch.nn.ELU | 是 | +| 93 | torch.nn.Hardshrink | 是 | +| 94 | torch.nn.Hardtanh | 是 | +| 95 | torch.nn.LeakyReLU | 是 | +| 96 | torch.nn.LogSigmoid | 是 | +| 97 | torch.nn.MultiheadAttention | 是 | +| 98 | torch.nn.PReLU | 是 | +| 99 | torch.nn.ReLU | 是 | +| 100 | torch.nn.ReLU6 | 是 | +| 101 | torch.nn.RReLU | 是 | +| 102 | torch.nn.SELU | 是 | +| 103 | torch.nn.CELU | 是 | +| 104 | torch.nn.GELU | 是 | +| 105 | torch.nn.Sigmoid | 是 | +| 106 | torch.nn.Softplus | 是 | +| 107 | torch.nn.Softshrink | 是,SoftShrink场景暂不支持 | +| 108 | torch.nn.Softsign | 是 | +| 109 | torch.nn.Tanh | 是 | +| 110 | torch.nn.Tanhshrink | 是 | +| 111 | torch.nn.Threshold | 是 | +| 112 | torch.nn.Softmin | 是 | +| 113 | torch.nn.Softmax | 是 | +| 114 | torch.nn.Softmax2d | 是 | +| 115 | torch.nn.LogSoftmax | 是 | +| 116 | torch.nn.AdaptiveLogSoftmaxWithLoss | 否 | +| 117 | torch.nn.AdaptiveLogSoftmaxWithLoss.log_prob | 否 | +| 118 | torch.nn.AdaptiveLogSoftmaxWithLoss.predict | 否 | +| 119 | torch.nn.BatchNorm1d | 是 | +| 120 | torch.nn.BatchNorm2d | 是 | +| 121 | torch.nn.BatchNorm3d | 是 | +| 122 | torch.nn.GroupNorm | 是 | +| 123 | torch.nn.SyncBatchNorm | 否 | +| 124 | torch.nn.SyncBatchNorm.convert_sync_batchnorm | 否 | +| 125 | torch.nn.InstanceNorm1d | 是 | +| 126 | torch.nn.InstanceNorm2d | 是 | +| 127 | torch.nn.InstanceNorm3d | 是 | +| 128 | torch.nn.LayerNorm | 是 | +| 129 | torch.nn.LocalResponseNorm | 是 | +| 130 | torch.nn.RNNBase | 是 | +| 131 | torch.nn.RNNBase.flatten_parameters | 是 | +| 132 | torch.nn.RNN | 是 | +| 133 | torch.nn.LSTM | 是 | +| 134 | torch.nn.GRU | 是,DynamicGRUV2场景暂不支持 | +| 135 | torch.nn.RNNCell | 是 | +| 136 | torch.nn.LSTMCell | 是 | +| 137 | torch.nn.GRUCell | 是 | +| 138 | torch.nn.Transformer | 是 | +| 139 | torch.nn.Transformer.forward | 是 | +| 140 | torch.nn.Transformer.generate_square_subsequent_mask | 是 | +| 141 | torch.nn.TransformerEncoder | 是 | +| 142 | torch.nn.TransformerEncoder.forward | 是 | +| 143 | torch.nn.TransformerDecoder | 是 | +| 144 | torch.nn.TransformerDecoder.forward | 是 | +| 145 | torch.nn.TransformerEncoderLayer | 是 | +| 146 | torch.nn.TransformerEncoderLayer.forward | 是 | +| 147 | torch.nn.TransformerDecoderLayer | 是 | +| 148 | torch.nn.TransformerDecoderLayer.forward | 是 | +| 149 | torch.nn.Identity | 是 | +| 150 | torch.nn.Linear | 是 | +| 151 | torch.nn.Bilinear | 是 | +| 152 | torch.nn.Dropout | 是 | +| 153 | torch.nn.Dropout2d | 是 | +| 154 | torch.nn.Dropout3d | 是 | +| 155 | torch.nn.AlphaDropout | 是 | +| 156 | torch.nn.Embedding | 是 | +| 157 | torch.nn.Embedding.from_pretrained | 是 | +| 158 | torch.nn.EmbeddingBag | 是 | +| 159 | torch.nn.EmbeddingBag.from_pretrained | 是 | +| 160 | torch.nn.CosineSimilarity | 是 | +| 161 | torch.nn.PairwiseDistance | 是 | +| 162 | torch.nn.L1Loss | 是 | +| 163 | torch.nn.MSELoss | 是 | +| 164 | torch.nn.CrossEntropyLoss | 是 | +| 165 | torch.nn.CTCLoss | 是 | +| 166 | torch.nn.NLLLoss | 是 | +| 167 | torch.nn.PoissonNLLLoss | 是 | +| 168 | torch.nn.KLDivLoss | 是 | +| 169 | torch.nn.BCELoss | 是 | +| 170 | torch.nn.BCEWithLogitsLoss | 是 | +| 171 | torch.nn.MarginRankingLoss | 是 | +| 172 | torch.nn.HingeEmbeddingLoss | 是 | +| 173 | torch.nn.MultiLabelMarginLoss | 是 | +| 174 | torch.nn.SmoothL1Loss | 是 | +| 175 | torch.nn.SoftMarginLoss | 是 | +| 176 | torch.nn.MultiLabelSoftMarginLoss | 是 | +| 177 | torch.nn.CosineEmbeddingLoss | 是 | +| 178 | torch.nn.MultiMarginLoss | 否 | +| 179 | torch.nn.TripletMarginLoss | 是 | +| 180 | torch.nn.PixelShuffle | 是 | +| 181 | torch.nn.Upsample | 是 | +| 182 | torch.nn.UpsamplingNearest2d | 是 | +| 183 | torch.nn.UpsamplingBilinear2d | 是 | +| 184 | torch.nn.DataParallel | 否 | +| 185 | torch.nn.parallel.DistributedDataParallel | 是 | +| 186 | torch.nn.parallel.DistributedDataParallel.no_sync | 是 | +| 187 | torch.nn.utils.clip_grad_norm_ | 是 | +| 188 | torch.nn.utils.clip_grad_value_ | 是 | +| 189 | torch.nn.utils.parameters_to_vector | 是 | +| 190 | torch.nn.utils.vector_to_parameters | 是 | +| 197 | torch.nn.utils.prune.PruningContainer | 是 | +| 198 | torch.nn.utils.prune.PruningContainer.add_pruning_method | 是 | +| 199 | torch.nn.utils.prune.PruningContainer.apply | 是 | +| 200 | torch.nn.utils.prune.PruningContainer.apply_mask | 是 | +| 201 | torch.nn.utils.prune.PruningContainer.compute_mask | 是 | +| 202 | torch.nn.utils.prune.PruningContainer.prune | 是 | +| 203 | torch.nn.utils.prune.PruningContainer.remove | 是 | +| 204 | torch.nn.utils.prune.Identity | 是 | +| 205 | torch.nn.utils.prune.Identity.apply | 是 | +| 206 | torch.nn.utils.prune.Identity.apply_mask | 是 | +| 207 | torch.nn.utils.prune.Identity.prune | 是 | +| 208 | torch.nn.utils.prune.Identity.remove | 是 | +| 209 | torch.nn.utils.prune.RandomUnstructured | 是 | +| 210 | torch.nn.utils.prune.RandomUnstructured.apply | 是 | +| 211 | torch.nn.utils.prune.RandomUnstructured.apply_mask | 是 | +| 212 | torch.nn.utils.prune.RandomUnstructured.prune | 是 | +| 213 | torch.nn.utils.prune.RandomUnstructured.remove | 是 | +| 214 | torch.nn.utils.prune.L1Unstructured | 是 | +| 215 | torch.nn.utils.prune.L1Unstructured.apply | 是 | +| 216 | torch.nn.utils.prune.L1Unstructured.apply_mask | 是 | +| 217 | torch.nn.utils.prune.L1Unstructured.prune | 是 | +| 218 | torch.nn.utils.prune.L1Unstructured.remove | 是 | +| 219 | torch.nn.utils.prune.RandomStructured | 是 | +| 220 | torch.nn.utils.prune.RandomStructured.apply | 是 | +| 221 | torch.nn.utils.prune.RandomStructured.apply_mask | 是 | +| 222 | torch.nn.utils.prune.RandomStructured.compute_mask | 是 | +| 223 | torch.nn.utils.prune.RandomStructured.prune | 是 | +| 224 | torch.nn.utils.prune.RandomStructured.remove | 是 | +| 225 | torch.nn.utils.prune.LnStructured | 是 | +| 226 | torch.nn.utils.prune.LnStructured.apply | 是 | +| 227 | torch.nn.utils.prune.LnStructured.apply_mask | 是 | +| 228 | torch.nn.utils.prune.LnStructured.compute_mask | 是 | +| 229 | torch.nn.utils.prune.LnStructured.prune | 是 | +| 230 | torch.nn.utils.prune.LnStructured.remove | 是 | +| 231 | torch.nn.utils.prune.CustomFromMask | 是 | +| 232 | torch.nn.utils.prune.CustomFromMask.apply | 是 | +| 233 | torch.nn.utils.prune.CustomFromMask.apply_mask | 是 | +| 234 | torch.nn.utils.prune.CustomFromMask.prune | 是 | +| 235 | torch.nn.utils.prune.CustomFromMask.remove | 是 | +| 236 | torch.nn.utils.prune.identity | 是 | +| 237 | torch.nn.utils.prune.random_unstructured | 是 | +| 238 | torch.nn.utils.prune.l1_unstructured | 是 | +| 239 | torch.nn.utils.prune.random_structured | 是 | +| 240 | torch.nn.utils.prune.ln_structured | 是 | +| 241 | torch.nn.utils.prune.global_unstructured | 是 | +| 242 | torch.nn.utils.prune.custom_from_mask | 是 | +| 243 | torch.nn.utils.prune.remove | 是 | +| 244 | torch.nn.utils.prune.is_pruned | 是 | +| 245 | torch.nn.utils.weight_norm | 是 | +| 246 | torch.nn.utils.remove_weight_norm | 是 | +| 247 | torch.nn.utils.spectral_norm | 是 | +| 248 | torch.nn.utils.remove_spectral_norm | 是 | +| 249 | torch.nn.utils.rnn.PackedSequence | 是 | +| 250 | torch.nn.utils.rnn.pack_padded_sequence | 是 | +| 251 | torch.nn.utils.rnn.pad_packed_sequence | 否 | +| 252 | torch.nn.utils.rnn.pad_sequence | 是 | +| 253 | torch.nn.utils.rnn.pack_sequence | 否 | +| 254 | torch.nn.Flatten | 是 | +| 255 | torch.quantization.quantize | 否 | +| 256 | torch.quantization.quantize_dynamic | 否 | +| 257 | torch.quantization.quantize_qat | 否 | +| 258 | torch.quantization.prepare | 是 | +| 259 | torch.quantization.prepare_qat | 否 | +| 260 | torch.quantization.convert | 否 | +| 261 | torch.quantization.QConfig | 是 | +| 262 | torch.quantization.QConfigDynamic | 是 | +| 263 | torch.quantization.fuse_modules | 是 | +| 264 | torch.quantization.QuantStub | 是 | +| 265 | torch.quantization.DeQuantStub | 是 | +| 266 | torch.quantization.QuantWrapper | 是 | +| 267 | torch.quantization.add_quant_dequant | 是 | +| 268 | torch.quantization.add_observer_ | 是 | +| 269 | torch.quantization.swap_module | 是 | +| 270 | torch.quantization.propagate_qconfig_ | 是 | +| 271 | torch.quantization.default_eval_fn | 是 | +| 272 | torch.quantization.MinMaxObserver | 是 | +| 273 | torch.quantization.MovingAverageMinMaxObserver | 是 | +| 274 | torch.quantization.PerChannelMinMaxObserver | 是 | +| 275 | torch.quantization.MovingAveragePerChannelMinMaxObserver | 是 | +| 276 | torch.quantization.HistogramObserver | 否 | +| 277 | torch.quantization.FakeQuantize | 否 | +| 278 | torch.quantization.NoopObserver | 是 | +| 279 | torch.quantization.get_observer_dict | 是 | +| 280 | torch.quantization.RecordingObserver | 是 | +| 281 | torch.nn.intrinsic.ConvBn2d | 是 | +| 282 | torch.nn.intrinsic.ConvBnReLU2d | 是 | +| 283 | torch.nn.intrinsic.ConvReLU2d | 是 | +| 284 | torch.nn.intrinsic.ConvReLU3d | 是 | +| 285 | torch.nn.intrinsic.LinearReLU | 是 | +| 286 | torch.nn.intrinsic.qat.ConvBn2d | 否 | +| 287 | torch.nn.intrinsic.qat.ConvBnReLU2d | 否 | +| 288 | torch.nn.intrinsic.qat.ConvReLU2d | 否 | +| 289 | torch.nn.intrinsic.qat.LinearReLU | 否 | +| 290 | torch.nn.intrinsic.quantized.ConvReLU2d | 否 | +| 291 | torch.nn.intrinsic.quantized.ConvReLU3d | 否 | +| 292 | torch.nn.intrinsic.quantized.LinearReLU | 否 | +| 293 | torch.nn.qat.Conv2d | 否 | +| 294 | torch.nn.qat.Conv2d.from_float | 否 | +| 295 | torch.nn.qat.Linear | 否 | +| 296 | torch.nn.qat.Linear.from_float | 否 | +| 297 | torch.nn.quantized.functional.relu | 否 | +| 298 | torch.nn.quantized.functional.linear | 否 | +| 299 | torch.nn.quantized.functional.conv2d | 否 | +| 300 | torch.nn.quantized.functional.conv3d | 否 | +| 301 | torch.nn.quantized.functional.max_pool2d | 否 | +| 302 | torch.nn.quantized.functional.adaptive_avg_pool2d | 否 | +| 303 | torch.nn.quantized.functional.avg_pool2d | 否 | +| 304 | torch.nn.quantized.functional.interpolate | 否 | +| 305 | torch.nn.quantized.functional.upsample | 否 | +| 306 | torch.nn.quantized.functional.upsample_bilinear | 否 | +| 307 | torch.nn.quantized.functional.upsample_nearest | 否 | +| 308 | torch.nn.quantized.ReLU | 否 | +| 309 | torch.nn.quantized.ReLU6 | 否 | +| 310 | torch.nn.quantized.Conv2d | 否 | +| 311 | torch.nn.quantized.Conv2d.from_float | 否 | +| 312 | torch.nn.quantized.Conv3d | 否 | +| 313 | torch.nn.quantized.Conv3d.from_float | 否 | +| 314 | torch.nn.quantized.FloatFunctional | 是 | +| 315 | torch.nn.quantized.QFunctional | 否 | +| 316 | torch.nn.quantized.Quantize | 是 | +| 317 | torch.nn.quantized.DeQuantize | 否 | +| 318 | torch.nn.quantized.Linear | 否 | +| 319 | torch.nn.quantized.Linear.from_float | 否 | +| 320 | torch.nn.quantized.dynamic.Linear | 否 | +| 321 | torch.nn.quantized.dynamic.Linear.from_float | 否 | +| 322 | torch.nn.quantized.dynamic.LSTM | 否 | + +## Functions(torch.nn.functional) + +| 序号 | API名称 | 是否支持 | +| ---- | ---------------------------------------------------- | --------------------------- | +| 1 | torch.nn.functional.conv1d | 是 | +| 2 | torch.nn.functional.conv2d | 是 | +| 3 | torch.nn.functional.conv3d | 是 | +| 4 | torch.nn.functional.conv_transpose1d | 是 | +| 5 | torch.nn.functional.conv_transpose2d | 是 | +| 6 | torch.nn.functional.conv_transpose3d | 是 | +| 7 | torch.nn.functional.unfold | 是 | +| 8 | torch.nn.functional.fold | 是 | +| 9 | torch.nn.functional.avg_pool1d | 是 | +| 10 | torch.nn.functional.avg_pool2d | 是 | +| 11 | torch.nn.functional.avg_pool3d | 是 | +| 12 | torch.nn.functional.max_pool1d | 是 | +| 13 | torch.nn.functional.max_pool2d | 是 | +| 14 | torch.nn.functional.max_pool3d | 是 | +| 15 | torch.nn.functional.max_unpool1d | 是 | +| 16 | torch.nn.functional.max_unpool2d | 是 | +| 17 | torch.nn.functional.max_unpool3d | 是 | +| 18 | torch.nn.functional.lp_pool1d | 是 | +| 19 | torch.nn.functional.lp_pool2d | 是 | +| 20 | torch.nn.functional.adaptive_max_pool1d | 是 | +| 21 | torch.nn.functional.adaptive_max_pool2d | 是 | +| 22 | torch.nn.functional.adaptive_max_pool3d | 否 | +| 23 | torch.nn.functional.adaptive_avg_pool1d | 是 | +| 24 | torch.nn.functional.adaptive_avg_pool2d | 是 | +| 25 | torch.nn.functional.adaptive_avg_pool3d | 是,仅支持D=1,H=1,W=1场景 | +| 26 | torch.nn.functional.threshold | 是 | +| 27 | torch.nn.functional.threshold_ | 是 | +| 28 | torch.nn.functional.relu | 是 | +| 29 | torch.nn.functional.relu_ | 是 | +| 30 | torch.nn.functional.hardtanh | 是 | +| 31 | torch.nn.functional.hardtanh_ | 是 | +| 32 | torch.nn.functional.relu6 | 是 | +| 33 | torch.nn.functional.elu | 是 | +| 34 | torch.nn.functional.elu_ | 是 | +| 35 | torch.nn.functional.selu | 是 | +| 36 | torch.nn.functional.celu | 是 | +| 37 | torch.nn.functional.leaky_relu | 是 | +| 38 | torch.nn.functional.leaky_relu_ | 是 | +| 39 | torch.nn.functional.prelu | 是 | +| 40 | torch.nn.functional.rrelu | 是 | +| 41 | torch.nn.functional.rrelu_ | 是 | +| 42 | torch.nn.functional.glu | 是 | +| 43 | torch.nn.functional.gelu | 是 | +| 44 | torch.nn.functional.logsigmoid | 是 | +| 45 | torch.nn.functional.hardshrink | 是 | +| 46 | torch.nn.functional.tanhshrink | 是 | +| 47 | torch.nn.functional.softsign | 是 | +| 48 | torch.nn.functional.softplus | 是 | +| 49 | torch.nn.functional.softmin | 是 | +| 50 | torch.nn.functional.softmax | 是 | +| 51 | torch.nn.functional.softshrink | 是 | +| 52 | torch.nn.functional.gumbel_softmax | 否 | +| 53 | torch.nn.functional.log_softmax | 是 | +| 54 | torch.nn.functional.tanh | 是 | +| 55 | torch.nn.functional.sigmoid | 是 | +| 56 | torch.nn.functional.batch_norm | 是 | +| 57 | torch.nn.functional.instance_norm | 是 | +| 58 | torch.nn.functional.layer_norm | 是 | +| 59 | torch.nn.functional.local_response_norm | 是 | +| 60 | torch.nn.functional.normalize | 是 | +| 61 | torch.nn.functional.linear | 是 | +| 62 | torch.nn.functional.bilinear | 是 | +| 63 | torch.nn.functional.dropout | 是 | +| 64 | torch.nn.functional.alpha_dropout | 是 | +| 65 | torch.nn.functional.dropout2d | 是 | +| 66 | torch.nn.functional.dropout3d | 是 | +| 67 | torch.nn.functional.embedding | 是 | +| 68 | torch.nn.functional.embedding_bag | 是 | +| 69 | torch.nn.functional.one_hot | 是 | +| 70 | torch.nn.functional.pairwise_distance | 是 | +| 71 | torch.nn.functional.cosine_similarity | 是 | +| 72 | torch.nn.functional.pdist | 是 | +| 73 | torch.nn.functional.binary_cross_entropy | 是 | +| 74 | torch.nn.functional.binary_cross_entropy_with_logits | 是 | +| 75 | torch.nn.functional.poisson_nll_loss | 是 | +| 76 | torch.nn.functional.cosine_embedding_loss | 是 | +| 77 | torch.nn.functional.cross_entropy | 是 | +| 78 | torch.nn.functional.ctc_loss | 是(仅支持2维输入) | +| 79 | torch.nn.functional.hinge_embedding_loss | 是 | +| 80 | torch.nn.functional.kl_div | 是 | +| 81 | torch.nn.functional.l1_loss | 是 | +| 82 | torch.nn.functional.mse_loss | 是 | +| 83 | torch.nn.functional.margin_ranking_loss | 是 | +| 84 | torch.nn.functional.multilabel_margin_loss | 是 | +| 85 | torch.nn.functional.multilabel_soft_margin_loss | 是 | +| 86 | torch.nn.functional.multi_margin_loss | 否 | +| 87 | torch.nn.functional.nll_loss | 是 | +| 88 | torch.nn.functional.smooth_l1_loss | 是 | +| 89 | torch.nn.functional.soft_margin_loss | 是 | +| 90 | torch.nn.functional.triplet_margin_loss | 是 | +| 91 | torch.nn.functional.pixel_shuffle | 是 | +| 92 | torch.nn.functional.pad | 是 | +| 93 | torch.nn.functional.interpolate | 是 | +| 94 | torch.nn.functional.upsample | 是 | +| 95 | torch.nn.functional.upsample_nearest | 是 | +| 96 | torch.nn.functional.upsample_bilinear | 是 | +| 97 | torch.nn.functional.grid_sample | 是 | +| 98 | torch.nn.functional.affine_grid | 是 | +| 99 | torch.nn.parallel.data_parallel | 否 | + +## torch.distributed + +| 序号 | API名称 | 是否支持 | +| ---- | ------------------------------------- | -------- | +| 1 | torch.distributed.init_process_group | 是 | +| 2 | torch.distributed.Backend | 是 | +| 3 | torch.distributed.get_backend | 是 | +| 4 | torch.distributed.get_rank | 是 | +| 5 | torch.distributed.get_world_size | 是 | +| 6 | torch.distributed.is_initialized | 是 | +| 7 | torch.distributed.is_mpi_available | 是 | +| 8 | torch.distributed.is_nccl_available | 是 | +| 9 | torch.distributed.new_group | 是 | +| 10 | torch.distributed.send | 否 | +| 11 | torch.distributed.recv | 否 | +| 12 | torch.distributed.isend | 否 | +| 13 | torch.distributed.irecv | 否 | +| 14 | is_completed | 是 | +| 15 | wait | 是 | +| 16 | torch.distributed.broadcast | 是 | +| 17 | torch.distributed.all_reduce | 是 | +| 18 | torch.distributed.reduce | 否 | +| 19 | torch.distributed.all_gather | 是 | +| 20 | torch.distributed.gather | 否 | +| 21 | torch.distributed.scatter | 否 | +| 22 | torch.distributed.barrier | 是 | +| 23 | torch.distributed.ReduceOp | 是 | +| 24 | torch.distributed.reduce_op | 是 | +| 25 | torch.distributed.broadcast_multigpu | 否 | +| 26 | torch.distributed.all_reduce_multigpu | 否 | +| 27 | torch.distributed.reduce_multigpu | 否 | +| 28 | torch.distributed.all_gather_multigpu | 否 | +| 29 | torch.distributed.launch | 是 | +| 30 | torch.multiprocessing.spawn | 是 | + +## torch.npu + +| 序号 | API名称 | npu对应API名称 | 是否支持 | +| ---- | ------------------------------------- | ------------------------------------ | -------- | +| 1 | torch.cuda.current_blas_handle | torch.npu.current_blas_handle | 否 | +| 2 | torch.cuda.current_device | torch.npu.current_device | 是 | +| 3 | torch.cuda.current_stream | torch.npu.current_stream | 是 | +| 4 | torch.cuda.default_stream | torch.npu.default_stream | 是 | +| 5 | torch.cuda.device | torch.npu.device | 是 | +| 6 | torch.cuda.device_count | torch.npu.device_count | 是 | +| 7 | torch.cuda.device_of | torch.npu.device_of | 是 | +| 8 | torch.cuda.get_device_capability | torch.npu.get_device_capability | 否 | +| 9 | torch.cuda.get_device_name | torch.npu.get_device_name | 否 | +| 10 | torch.cuda.init | torch.npu.init | 是 | +| 11 | torch.cuda.ipc_collect | torch.npu.ipc_collect | 否 | +| 12 | torch.cuda.is_available | torch.npu.is_available | 是 | +| 13 | torch.cuda.is_initialized | torch.npu.is_initialized | 是 | +| 14 | torch.cuda.set_device | torch.npu.set_device | 部分支持 | +| 15 | torch.cuda.stream | torch.npu.stream | 是 | +| 16 | torch.cuda.synchronize | torch.npu.synchronize | 是 | +| 17 | torch.cuda.get_rng_state | torch.npu.get_rng_state | 否 | +| 18 | torch.cuda.get_rng_state_all | torch.npu.get_rng_state_all | 否 | +| 19 | torch.cuda.set_rng_state | torch.npu.set_rng_state | 否 | +| 20 | torch.cuda.set_rng_state_all | torch.npu.set_rng_state_all | 否 | +| 21 | torch.cuda.manual_seed | torch.npu.manual_seed | 否 | +| 22 | torch.cuda.manual_seed_all | torch.npu.manual_seed_all | 否 | +| 23 | torch.cuda.seed | torch.npu.seed | 否 | +| 24 | torch.cuda.seed_all | torch.npu.seed_all | 否 | +| 25 | torch.cuda.initial_seed | torch.npu.initial_seed | 否 | +| 26 | torch.cuda.comm.broadcast | torch.npu.comm.broadcast | 否 | +| 27 | torch.cuda.comm.broadcast_coalesced | torch.npu.comm.broadcast_coalesced | 否 | +| 28 | torch.cuda.comm.reduce_add | torch.npu.comm.reduce_add | 否 | +| 29 | torch.cuda.comm.scatter | torch.npu.comm.scatter | 否 | +| 30 | torch.cuda.comm.gather | torch.npu.comm.gather | 否 | +| 31 | torch.cuda.Stream | torch.npu.Stream | 是 | +| 32 | torch.cuda.Stream.query | torch.npu.Stream.query | 是 | +| 33 | torch.cuda.Stream.record_event | torch.npu.Stream.record_event | 是 | +| 34 | torch.cuda.Stream.synchronize | torch.npu.Stream.synchronize | 是 | +| 35 | torch.cuda.Stream.wait_event | torch.npu.Stream.wait_event | 是 | +| 36 | torch.cuda.Stream.wait_stream | torch.npu.Stream.wait_stream | 是 | +| 37 | torch.cuda.Event | torch.npu.Event | 是 | +| 38 | torch.cuda.Event.elapsed_time | torch.npu.Event.elapsed_time | 是 | +| 39 | torch.cuda.Event.from_ipc_handle | torch.npu.Event.from_ipc_handle | 否 | +| 40 | torch.cuda.Event.ipc_handle | torch.npu.Event.ipc_handle | 否 | +| 41 | torch.cuda.Event.query | torch.npu.Event.query | 是 | +| 42 | torch.cuda.Event.record | torch.npu.Event.record | 是 | +| 43 | torch.cuda.Event.synchronize | torch.npu.Event.synchronize | 是 | +| 44 | torch.cuda.Event.wait | torch.npu.Event.wait | 是 | +| 45 | torch.cuda.empty_cache | torch.npu.empty_cache | 是 | +| 46 | torch.cuda.memory_stats | torch.npu.memory_stats | 是 | +| 47 | torch.cuda.memory_summary | torch.npu.memory_summary | 是 | +| 48 | torch.cuda.memory_snapshot | torch.npu.memory_snapshot | 是 | +| 49 | torch.cuda.memory_allocated | torch.npu.memory_allocated | 是 | +| 50 | torch.cuda.max_memory_allocated | torch.npu.max_memory_allocated | 是 | +| 51 | torch.cuda.reset_max_memory_allocated | torch.npu.reset_max_memory_allocated | 是 | +| 52 | torch.cuda.memory_reserved | torch.npu.memory_reserved | 是 | +| 53 | torch.cuda.max_memory_reserved | torch.npu.max_memory_reserved | 是 | +| 54 | torch.cuda.memory_cached | torch.npu.memory_cached | 是 | +| 55 | torch.cuda.max_memory_cached | torch.npu.max_memory_cached | 是 | +| 56 | torch.cuda.reset_max_memory_cached | torch.npu.reset_max_memory_cached | 是 | +| 57 | torch.cuda.nvtx.mark | torch.npu.nvtx.mark | 否 | +| 58 | torch.cuda.nvtx.range_push | torch.npu.nvtx.range_push | 否 | +| 59 | torch.cuda.nvtx.range_pop | torch.npu.nvtx.range_pop | 否 | +| 60 | torch.cuda._sleep | torch.npu._sleep | 否 | +| 61 | torch.cuda.Stream.priority_range | torch.npu.Stream.priority_range | 否 | +| 62 | torch.cuda.get_device_properties | torch.npu.get_device_properties | 否 | +| 63 | torch.cuda.amp.GradScaler | torch.npu.amp.GradScaler | 否 | + +torch.npu.set_device()接口只支持在程序开始的位置通过set_device进行指定,不支持多次指定和with torch.npu.device(id)方式的device切换 + +## NPU自定义算子 + +| 序号 | 算子名称 | +| ---- | ---------------------------------------------- | +| 1 | npu_convolution_transpose | +| 2 | npu_conv_transpose2d | +| 3 | npu_convolution_transpose_backward | +| 4 | npu_conv_transpose2d_backward | +| 5 | npu_conv_transpose3d_backward | +| 6 | npu_convolution | +| 7 | npu_convolution_backward | +| 8 | npu_convolution_double_backward | +| 9 | npu_conv2d | +| 10 | npu_conv2d.out | +| 11 | npu_conv2d_backward | +| 12 | npu_conv3d | +| 13 | npu_conv3d.out | +| 14 | npu_conv3d_backward | +| 15 | one_ | +| 16 | npu_sort_v2.out | +| 17 | npu_sort_v2 | +| 18 | npu_format_cast | +| 19 | npu_format_cast_.acl_format | +| 20 | npu_format_cast_.src | +| 21 | npu_transpose_to_contiguous | +| 22 | npu_transpose | +| 23 | npu_transpose.out | +| 24 | npu_broadcast | +| 25 | npu_broadcast.out | +| 26 | npu_dtype_cast | +| 27 | npu_dtype_cast_.Tensor | +| 28 | npu_roi_alignbk | +| 29 | empty_with_format | +| 30 | empty_with_format.names | +| 31 | copy_memory_ | +| 32 | npu_one_hot | +| 33 | npu_stride_add | +| 34 | npu_softmax_cross_entropy_with_logits | +| 35 | npu_softmax_cross_entropy_with_logits_backward | +| 36 | npu_ps_roi_pooling | +| 37 | npu_ps_roi_pooling_backward | +| 38 | npu_roi_align | +| 39 | npu_nms_v4 | +| 40 | npu_lstm | +| 41 | npu_lstm_backward | +| 42 | npu_iou | +| 43 | npu_ptiou | +| 44 | npu_nms_with_mask | +| 45 | npu_pad | +| 46 | npu_bounding_box_encode | +| 47 | npu_bounding_box_decode | +| 48 | npu_gru | +| 49 | npu_gru_backward | +| 50 | npu_set_.source_Storage_storage_offset_format | +| 51 | npu_random_choice_with_mask | +| 52 | npu_batch_nms | +| 53 | npu_slice | +| 54 | npu_slice.out | +| 55 | npu_dropoutV2 | +| 56 | npu_dropoutV2_backward | +| 57 | _npu_dropout | +| 58 | _npu_dropout_inplace | +| 59 | npu_dropout_backward | +| 60 | npu_indexing | +| 61 | npu_indexing.out | +| 62 | npu_ifmr | +| 63 | npu_max.dim | +| 64 | npu_max.names_dim | +| 65 | npu_scatter | +| 66 | npu_max_backward | +| 67 | npu_apply_adam | +| 68 | npu_layer_norm_eval | +| 69 | npu_alloc_float_status | +| 70 | npu_get_float_status | +| 71 | npu_clear_float_status | +| 72 | npu_confusion_transpose | +| 73 | npu_confusion_transpose_backward | +| 74 | npu_bmmV2 | +| 75 | fast_gelu | +| 76 | fast_gelu_backward | +| 77 | npu_sub_sample | +| 78 | npu_deformable_conv2d | +| 79 | npu_deformable_conv2dbk | +| 80 | npu_mish | +| 81 | npu_anchor_response_flags | +| 82 | npu_yolo_boxes_encode | +| 83 | npu_grid_assign_positive | +| 84 | npu_mish_backward | +| 85 | npu_normalize_batch | +| 86 | npu_masked_fill_range | +| 87 | npu_linear | +| 88 | npu_linear_backward | +| 89 | npu_bert_apply_adam | +| 90 | npu_giou | +| 91 | npu_giou_backward | + +详细算子接口说明: + +> ``` +> npu_apply_adam(beta1_power, beta2_power, lr, beta1, beta2, epsilon, grad, use_locking, use_nesterov, out = (var, m, v)) +> ``` + +count adam result. + +- Parameters: + - **beta1_power** (Number) - power of beta1. + - **beta2_power** (Number) - power of beta2. + - **lr** (Number) - learning rate. + - **beta1** (Number) - exponential decay rate for the 1st moment estimates. + - **beta2** (Number) - exponential decay rate for the 2nd moment estimates. + - **epsilon** (Number) - term added to the denominator to improve numerical stability. + - **grad** (Tensor) - the gradient. + - **use_locking** (bool) - If `True` use locks for update operations. + - **use_nesterov** (bool) -If `True`, uses the nesterov update. + - **var** (Tensor) - variables to be optimized. + - **m** (Tensor) - mean value of variables. + - **v** (Tensor) - variance of variables. + +- constraints: + + None + +- Examples: + + None + +> npu_bert_apply_adam(lr, beta1, beta2, epsilon, grad, max_grad_norm, global_grad_norm, weight_decay, out = (var, m, v)) + +count adam result in bert. + +- Parameters: + - **lr** (Number) - learning rate. + - **beta1** (Number) - exponential decay rate for the 1st moment estimates. + - **beta2** (Number) - exponential decay rate for the 2nd moment estimates. + - **epsilon** (Number) - term added to the denominator to improve numerical stability. + - **grad** (Tensor) - the gradient. + - **max_grad_norm** (Number) - maximum norm for the gradients. + - **global_grad_norm** (Number) - L2_norm for the gradients. + - **weight_decay** (Number) - weight decay + - **var** (Tensor) - variables to be optimized. + - **m** (Tensor) -mean value of variables. + - **v** (Tensor) - variance of variables. + +- constraints: + + None + +- Examples: + + ```python + >>> var_in = torch.rand(321538).uniform_(-32.,21.).npu() + >>> var_in + tensor([ 0.6119, 5.8193, 3.0683, ..., -28.5832, 12.9402, -24.0488], + device='npu:0') + >>> m_in = torch.zeros(321538).npu() + >>> v_in = torchzeros(321538).npu() + >>> grad = torch.rand(321538).uniform_(-0.05,0.03).npu() + >>> grad + tensor([-0.0315, -0.0113, -0.0132, ..., 0.0106, -0.0226, -0.0252], + device='npu:0') + >>> max_grad_norm = -1. + >>> beta1 = 0.9 + >>> beta2 = 0.99 + >>> weight_decay = 0. + >>> lr = 0.1 + >>> epsilon = 1e-06 + >>> global_grad_norm = 0. + >>> var_out, m_out, v_out = torch.npu_bert_apply_adam(var_in, m_in, v_in, lr, beta1, beta2, epsilon, grad, max_grad_norm, global_grad_norm, weight_decay) + >>> var_out + tensor([ 0.7118, 5.9192, 3.1682, ..., -28.6831, 13.0402, -23.9489], + device='npu:0') + >>> m_out + tensor([-0.0032, -0.0011, -0.0013, ..., 0.0011, -0.0023, -0.0025], + device='npu:0') + >>> v_out + tensor([9.9431e-06, 1.2659e-06, 1.7328e-06, ..., 1.1206e-06, 5.0933e-06, + 6.3495e-06], device='npu:0') + ``` + + + diff --git "a/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225_1.8.1.md" "b/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225_1.8.1.md" new file mode 100644 index 0000000000000000000000000000000000000000..c280756f98f804d436367f8214ac998f6d955ce1 --- /dev/null +++ "b/docs/zh/PyTorch API\346\224\257\346\214\201\346\270\205\345\215\225_1.8.1.md" @@ -0,0 +1,1232 @@ +# Torch + +## Tensors + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [is_tensor](https://pytorch.org/docs/1.8.1/generated/torch.is_tensor.html) | 否 | +| 2 | [is_storage](https://pytorch.org/docs/1.8.1/generated/torch.is_storage.html) | 否 | +| 3 | [is_complex](https://pytorch.org/docs/1.8.1/generated/torch.is_complex.html) | 否 | +| 4 | [is_floating_point](https://pytorch.org/docs/1.8.1/generated/torch.is_floating_point.html) | 否 | +| 5 | [is_nonzero](https://pytorch.org/docs/1.8.1/generated/torch.is_nonzero.html) | 否 | +| 6 | [set_default_dtype](https://pytorch.org/docs/1.8.1/generated/torch.set_default_dtype.html) | 否 | +| 7 | [get_default_dtype](https://pytorch.org/docs/1.8.1/generated/torch.get_default_dtype.html) | 否 | +| 8 | [set_default_tensor_type](https://pytorch.org/docs/1.8.1/generated/torch.set_default_tensor_type.html) | 否 | +| 9 | [numel](https://pytorch.org/docs/1.8.1/generated/torch.numel.html) | 否 | +| 10 | [set_printoptions](https://pytorch.org/docs/1.8.1/generated/torch.set_printoptions.html) | 否 | +| 11 | [set_flush_denormal](https://pytorch.org/docs/1.8.1/generated/torch.set_flush_denormal.html) | 否 | + +### Creation Ops + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [tensor](https://pytorch.org/docs/1.8.1/generated/torch.tensor.html) | 否 | +| 2 | [sparse_coo_tensor](https://pytorch.org/docs/1.8.1/generated/torch.sparse_coo_tensor.html) | 否 | +| 3 | [as_tensor](https://pytorch.org/docs/1.8.1/generated/torch.as_tensor.html) | 否 | +| 4 | [as_strided](https://pytorch.org/docs/1.8.1/generated/torch.as_strided.html) | 否 | +| 5 | [from_numpy](https://pytorch.org/docs/1.8.1/generated/torch.from_numpy.html) | 否 | +| 6 | [zeros](https://pytorch.org/docs/1.8.1/generated/torch.zeros.html) | 否 | +| 7 | [zeros_like](https://pytorch.org/docs/1.8.1/generated/torch.zeros_like.html) | 否 | +| 8 | [ones](https://pytorch.org/docs/1.8.1/generated/torch.ones.html) | 否 | +| 9 | [ones_like](https://pytorch.org/docs/1.8.1/generated/torch.ones_like.html) | 否 | +| 10 | [arange](https://pytorch.org/docs/1.8.1/generated/torch.arange.html) | 否 | +| 11 | [range](https://pytorch.org/docs/1.8.1/generated/torch.range.html) | 否 | +| 12 | [linspace](https://pytorch.org/docs/1.8.1/generated/torch.linspace.html) | 否 | +| 13 | [logspace](https://pytorch.org/docs/1.8.1/generated/torch.logspace.html) | 否 | +| 14 | [eye](https://pytorch.org/docs/1.8.1/generated/torch.eye.html) | 否 | +| 15 | [empty](https://pytorch.org/docs/1.8.1/generated/torch.empty.html) | 否 | +| 16 | [empty_like](https://pytorch.org/docs/1.8.1/generated/torch.empty_like.html) | 否 | +| 17 | [empty_strided](https://pytorch.org/docs/1.8.1/generated/torch.empty_strided.html) | 否 | +| 18 | [full](https://pytorch.org/docs/1.8.1/generated/torch.full.html) | 否 | +| 19 | [full_like](https://pytorch.org/docs/1.8.1/generated/torch.full_like.html) | 否 | +| 20 | [quantize_per_tensor](https://pytorch.org/docs/1.8.1/generated/torch.quantize_per_tensor.html) | 否 | +| 21 | [quantize_per_channel](https://pytorch.org/docs/1.8.1/generated/torch.quantize_per_channel.html) | 否 | +| 22 | [dequantize](https://pytorch.org/docs/1.8.1/generated/torch.dequantize.html) | 否 | +| 23 | [complex](https://pytorch.org/docs/1.8.1/generated/torch.complex.html) | 否 | +| 24 | [polar](https://pytorch.org/docs/1.8.1/generated/torch.polar.html) | 否 | +| 25 | [heaviside](https://pytorch.org/docs/1.8.1/generated/torch.heaviside.html) | 否 | + +### Indexing, Slicing, Joining, Mutating Ops + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [cat](https://pytorch.org/docs/1.8.1/generated/torch.cat.html) | 否 | +| 2 | [chunk](https://pytorch.org/docs/1.8.1/generated/torch.chunk.html) | 否 | +| 3 | [column_stack](https://pytorch.org/docs/1.8.1/generated/torch.column_stack.html) | 否 | +| 4 | [dstack](https://pytorch.org/docs/1.8.1/generated/torch.dstack.html) | 否 | +| 5 | [gather](https://pytorch.org/docs/1.8.1/generated/torch.gather.html) | 否 | +| 6 | [hstack](https://pytorch.org/docs/1.8.1/generated/torch.hstack.html) | 否 | +| 7 | [index_select](https://pytorch.org/docs/1.8.1/generated/torch.index_select.html) | 否 | +| 8 | [masked_select](https://pytorch.org/docs/1.8.1/generated/torch.masked_select.html) | 否 | +| 9 | [movedim](https://pytorch.org/docs/1.8.1/generated/torch.movedim.html) | 否 | +| 10 | [moveaxis](https://pytorch.org/docs/1.8.1/generated/torch.moveaxis.html) | 否 | +| 11 | [narrow](https://pytorch.org/docs/1.8.1/generated/torch.narrow.html) | 否 | +| 12 | [nonzero](https://pytorch.org/docs/1.8.1/generated/torch.nonzero.html) | 否 | +| 13 | [reshape](https://pytorch.org/docs/1.8.1/generated/torch.reshape.html) | 否 | +| 14 | [row_stack](https://pytorch.org/docs/1.8.1/generated/torch.row_stack.html) | 否 | +| 15 | [scatter](https://pytorch.org/docs/1.8.1/generated/torch.scatter.html) | 否 | +| 16 | [scatter_add](https://pytorch.org/docs/1.8.1/generated/torch.scatter_add.html) | 否 | +| 17 | [split](https://pytorch.org/docs/1.8.1/generated/torch.split.html) | 否 | +| 18 | [squeeze](https://pytorch.org/docs/1.8.1/generated/torch.squeeze.html) | 否 | +| 19 | [stack](https://pytorch.org/docs/1.8.1/generated/torch.stack.html) | 否 | +| 20 | [swapaxes](https://pytorch.org/docs/1.8.1/generated/torch.swapaxes.html) | 否 | +| 21 | [swapdims](https://pytorch.org/docs/1.8.1/generated/torch.swapdims.html) | 否 | +| 22 | [t](https://pytorch.org/docs/1.8.1/generated/torch.t.html) | 否 | +| 23 | [take](https://pytorch.org/docs/1.8.1/generated/torch.take.html) | 否 | +| 24 | [tensor_split](https://pytorch.org/docs/1.8.1/generated/torch.tensor_split.html) | 否 | +| 25 | [tile](https://pytorch.org/docs/1.8.1/generated/torch.tile.html) | 否 | +| 26 | [transpose](https://pytorch.org/docs/1.8.1/generated/torch.transpose.html) | 否 | +| 27 | [unbind](https://pytorch.org/docs/1.8.1/generated/torch.unbind.html) | 否 | +| 28 | [unsqueeze](https://pytorch.org/docs/1.8.1/generated/torch.unsqueeze.html) | 否 | +| 29 | [vstack](https://pytorch.org/docs/1.8.1/generated/torch.vstack.html) | 否 | +| 30 | [where](https://pytorch.org/docs/1.8.1/generated/torch.where.html) | 否 | + +## Generators + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [Generator](https://pytorch.org/docs/1.8.1/generated/torch.Generator.html) | 否 | + +## Random sampling + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [seed](https://pytorch.org/docs/1.8.1/generated/torch.seed.html) | 否 | +| 2 | [manual_seed](https://pytorch.org/docs/1.8.1/generated/torch.manual_seed.html) | 否 | +| 3 | [initial_seed](https://pytorch.org/docs/1.8.1/generated/torch.initial_seed.html) | 否 | +| 4 | [get_rng_state](https://pytorch.org/docs/1.8.1/generated/torch.get_rng_state.html) | 否 | +| 5 | [set_rng_state](https://pytorch.org/docs/1.8.1/generated/torch.set_rng_state.html) | 否 | +| 6 | [bernoulli](https://pytorch.org/docs/1.8.1/generated/torch.bernoulli.html) | 否 | +| 7 | [multinomial](https://pytorch.org/docs/1.8.1/generated/torch.multinomial.html) | 否 | +| 8 | [normal](https://pytorch.org/docs/1.8.1/generated/torch.normal.html) | 否 | +| 9 | [poisson](https://pytorch.org/docs/1.8.1/generated/torch.poisson.html) | 否 | +| 10 | [rand](https://pytorch.org/docs/1.8.1/generated/torch.rand.html) | 否 | +| 11 | [rand_like](https://pytorch.org/docs/1.8.1/generated/torch.rand_like.html) | 否 | +| 12 | [randint](https://pytorch.org/docs/1.8.1/generated/torch.randint.html) | 否 | +| 13 | [randint_like](https://pytorch.org/docs/1.8.1/generated/torch.randint_like.html) | 否 | +| 14 | [randn](https://pytorch.org/docs/1.8.1/generated/torch.randn.html) | 否 | +| 15 | [randn_like](https://pytorch.org/docs/1.8.1/generated/torch.randn_like.html) | 否 | +| 16 | [randperm](https://pytorch.org/docs/1.8.1/generated/torch.randperm.html) | 否 | + +### In-place random sampling + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [torch.Tensor.bernoulli_()](https://pytorch.org/docs/1.8.1/tensors.html) | 否 | +| 2 | [torch.Tensor.cauchy_()](https://pytorch.org/docs/1.8.1/tensors.html) | 否 | +| 3 | [torch.Tensor.exponential_()](https://pytorch.org/docs/1.8.1/tensors.html) | 否 | +| 4 | [torch.Tensor.geometric_()](https://pytorch.org/docs/1.8.1/tensors.html) | 否 | +| 5 | [torch.Tensor.log_normal_()](https://pytorch.org/docs/1.8.1/tensors.html) | 否 | +| 6 | [torch.Tensor.normal_()](https://pytorch.org/docs/1.8.1/tensors.html) | 否 | +| 7 | [torch.Tensor.random_()](https://pytorch.org/docs/1.8.1/tensors.html) | 否 | +| 8 | [torch.Tensor.uniform_()](https://pytorch.org/docs/1.8.1/tensors.html) | 否 | + +### Quasi-random sampling + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [quasirandom.SobolEngine](https://pytorch.org/docs/1.8.1/generated/torch.quasirandom.SobolEngine.html) | 否 | + +## Serialization + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [save](https://pytorch.org/docs/1.8.1/generated/torch.save.html) | 否 | +| 2 | [load](https://pytorch.org/docs/1.8.1/generated/torch.load.html) | 否 | + +## Parallelism + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [get_num_threads](https://pytorch.org/docs/1.8.1/generated/torch.get_num_threads.html) | 否 | +| 2 | [set_num_threads](https://pytorch.org/docs/1.8.1/generated/torch.set_num_threads.html) | 否 | +| 3 | [get_num_interop_threads](https://pytorch.org/docs/1.8.1/generated/torch.get_num_interop_threads.html) | 否 | +| 4 | [set_num_interop_threads](https://pytorch.org/docs/1.8.1/generated/torch.set_num_interop_threads.html) | 否 | + +## Locally disabling gradient computation + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [no_grad](https://pytorch.org/docs/1.8.1/generated/torch.no_grad.html#torch.no_grad) | 否 | +| 2 | [enable_grad](https://pytorch.org/docs/1.8.1/generated/torch.enable_grad.html#torch.enable_grad) | 否 | +| 3 | set_grad_enabled | 否 | + +## Math operations + +### Pointwise Ops + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [abs](https://pytorch.org/docs/1.8.1/generated/torch.abs.html#torch.abs) | 否 | +| 2 | [absolute](https://pytorch.org/docs/1.8.1/generated/torch.absolute.html#torch.absolute) | 否 | +| 3 | [acos](https://pytorch.org/docs/1.8.1/generated/torch.acos.html#torch.acos) | 否 | +| 4 | [arccos](https://pytorch.org/docs/1.8.1/generated/torch.arccos.html#torch.arccos) | 否 | +| 5 | [acosh](https://pytorch.org/docs/1.8.1/generated/torch.acosh.html#torch.acosh) | 否 | +| 6 | [arccosh](https://pytorch.org/docs/1.8.1/generated/torch.arccosh.html#torch.arccosh) | 否 | +| 7 | [add](https://pytorch.org/docs/1.8.1/generated/torch.add.html#torch.add) | 否 | +| 8 | [addcdiv](https://pytorch.org/docs/1.8.1/generated/torch.addcdiv.html#torch.addcdiv) | 否 | +| 9 | [addcmul](https://pytorch.org/docs/1.8.1/generated/torch.addcmul.html#torch.addcmul) | 否 | +| 10 | [angle](https://pytorch.org/docs/1.8.1/generated/torch.angle.html#torch.angle) | 否 | +| 11 | [asin](https://pytorch.org/docs/1.8.1/generated/torch.asin.html#torch.asin) | 否 | +| 12 | [arcsin](https://pytorch.org/docs/1.8.1/generated/torch.arcsin.html#torch.arcsin) | 否 | +| 13 | [asinh](https://pytorch.org/docs/1.8.1/generated/torch.asinh.html#torch.asinh) | 否 | +| 14 | [arcsinh](https://pytorch.org/docs/1.8.1/generated/torch.arcsinh.html#torch.arcsinh) | 否 | +| 15 | [atan](https://pytorch.org/docs/1.8.1/generated/torch.atan.html#torch.atan) | 否 | +| 16 | [arctan](https://pytorch.org/docs/1.8.1/generated/torch.arctan.html#torch.arctan) | 否 | +| 17 | [atanh](https://pytorch.org/docs/1.8.1/generated/torch.atanh.html#torch.atanh) | 否 | +| 18 | [arctanh](https://pytorch.org/docs/1.8.1/generated/torch.arctanh.html#torch.arctanh) | 否 | +| 19 | [atan2](https://pytorch.org/docs/1.8.1/generated/torch.atan2.html#torch.atan2) | 否 | +| 20 | [bitwise_not](https://pytorch.org/docs/1.8.1/generated/torch.bitwise_not.html#torch.bitwise_not) | 否 | +| 21 | [bitwise_and](https://pytorch.org/docs/1.8.1/generated/torch.bitwise_and.html#torch.bitwise_and) | 否 | +| 22 | [bitwise_or](https://pytorch.org/docs/1.8.1/generated/torch.bitwise_or.html#torch.bitwise_or) | 否 | +| 23 | [bitwise_xor](https://pytorch.org/docs/1.8.1/generated/torch.bitwise_xor.html#torch.bitwise_xor) | 否 | +| 24 | [ceil](https://pytorch.org/docs/1.8.1/generated/torch.ceil.html#torch.ceil) | 否 | +| 25 | [clamp](https://pytorch.org/docs/1.8.1/generated/torch.clamp.html#torch.clamp) | 否 | +| 26 | [clip](https://pytorch.org/docs/1.8.1/generated/torch.clip.html#torch.clip) | 否 | +| 27 | [conj](https://pytorch.org/docs/1.8.1/generated/torch.conj.html#torch.conj) | 否 | +| 28 | [copysign](https://pytorch.org/docs/1.8.1/generated/torch.copysign.html#torch.copysign) | 否 | +| 29 | [cos](https://pytorch.org/docs/1.8.1/generated/torch.cos.html#torch.cos) | 否 | +| 30 | [cosh](https://pytorch.org/docs/1.8.1/generated/torch.cosh.html#torch.cosh) | 否 | +| 31 | [deg2rad](https://pytorch.org/docs/1.8.1/generated/torch.deg2rad.html#torch.deg2rad) | 否 | +| 32 | [div](https://pytorch.org/docs/1.8.1/generated/torch.div.html#torch.div) | 否 | +| 33 | [divide](https://pytorch.org/docs/1.8.1/generated/torch.divide.html#torch.divide) | 否 | +| 34 | [digamma](https://pytorch.org/docs/1.8.1/generated/torch.digamma.html#torch.digamma) | 否 | +| 35 | [erf](https://pytorch.org/docs/1.8.1/generated/torch.erf.html#torch.erf) | 否 | +| 36 | [erfc](https://pytorch.org/docs/1.8.1/generated/torch.erfc.html#torch.erfc) | 否 | +| 37 | [erfinv](https://pytorch.org/docs/1.8.1/generated/torch.erfinv.html#torch.erfinv) | 否 | +| 38 | [exp](https://pytorch.org/docs/1.8.1/generated/torch.exp.html#torch.exp) | 否 | +| 39 | [exp2](https://pytorch.org/docs/1.8.1/generated/torch.exp2.html#torch.exp2) | 否 | +| 40 | [expm1](https://pytorch.org/docs/1.8.1/generated/torch.expm1.html#torch.expm1) | 否 | +| 41 | [fake_quantize_per_channel_affine](https://pytorch.org/docs/1.8.1/generated/torch.fake_quantize_per_channel_affine.html#torch.fake_quantize_per_channel_affine) | 否 | +| 42 | [fake_quantize_per_tensor_affine](https://pytorch.org/docs/1.8.1/generated/torch.fake_quantize_per_tensor_affine.html#torch.fake_quantize_per_tensor_affine) | 否 | +| 43 | [fix](https://pytorch.org/docs/1.8.1/generated/torch.fix.html#torch.fix) | 否 | +| 44 | [float_power](https://pytorch.org/docs/1.8.1/generated/torch.float_power.html#torch.float_power) | 否 | +| 45 | [floor](https://pytorch.org/docs/1.8.1/generated/torch.floor.html#torch.floor) | 否 | +| 46 | [floor_divide](https://pytorch.org/docs/1.8.1/generated/torch.floor_divide.html#torch.floor_divide) | 否 | +| 47 | [fmod](https://pytorch.org/docs/1.8.1/generated/torch.fmod.html#torch.fmod) | 否 | +| 48 | [frac](https://pytorch.org/docs/1.8.1/generated/torch.frac.html#torch.frac) | 否 | +| 49 | [imag](https://pytorch.org/docs/1.8.1/generated/torch.imag.html#torch.imag) | 否 | +| 50 | [ldexp](https://pytorch.org/docs/1.8.1/generated/torch.ldexp.html#torch.ldexp) | 否 | +| 51 | [lerp](https://pytorch.org/docs/1.8.1/generated/torch.lerp.html#torch.lerp) | 否 | +| 52 | [lgamma](https://pytorch.org/docs/1.8.1/generated/torch.lgamma.html#torch.lgamma) | 否 | +| 53 | [log](https://pytorch.org/docs/1.8.1/generated/torch.log.html#torch.log) | 否 | +| 54 | [log10](https://pytorch.org/docs/1.8.1/generated/torch.log10.html#torch.log10) | 否 | +| 55 | [log1p](https://pytorch.org/docs/1.8.1/generated/torch.log1p.html#torch.log1p) | 否 | +| 56 | [log2](https://pytorch.org/docs/1.8.1/generated/torch.log2.html#torch.log2) | 否 | +| 57 | [logaddexp](https://pytorch.org/docs/1.8.1/generated/torch.logaddexp.html#torch.logaddexp) | 否 | +| 58 | [logaddexp2](https://pytorch.org/docs/1.8.1/generated/torch.logaddexp2.html#torch.logaddexp2) | 否 | +| 59 | [logical_and](https://pytorch.org/docs/1.8.1/generated/torch.logical_and.html#torch.logical_and) | 否 | +| 60 | [logical_not](https://pytorch.org/docs/1.8.1/generated/torch.logical_not.html#torch.logical_not) | 否 | +| 61 | [logical_or](https://pytorch.org/docs/1.8.1/generated/torch.logical_or.html#torch.logical_or) | 否 | +| 62 | [logical_xor](https://pytorch.org/docs/1.8.1/generated/torch.logical_xor.html#torch.logical_xor) | 否 | +| 63 | [logit](https://pytorch.org/docs/1.8.1/generated/torch.logit.html#torch.logit) | 否 | +| 64 | [hypot](https://pytorch.org/docs/1.8.1/generated/torch.hypot.html#torch.hypot) | 否 | +| 65 | [i0](https://pytorch.org/docs/1.8.1/generated/torch.i0.html#torch.i0) | 否 | +| 66 | [igamma](https://pytorch.org/docs/1.8.1/generated/torch.igamma.html#torch.igamma) | 否 | +| 67 | [igammac](https://pytorch.org/docs/1.8.1/generated/torch.igammac.html#torch.igammac) | 否 | +| 68 | [mul](https://pytorch.org/docs/1.8.1/generated/torch.mul.html#torch.mul) | 否 | +| 69 | [multiply](https://pytorch.org/docs/1.8.1/generated/torch.multiply.html#torch.multiply) | 否 | +| 70 | [mvlgamma](https://pytorch.org/docs/1.8.1/generated/torch.mvlgamma.html#torch.mvlgamma) | 否 | +| 71 | [nan_to_num](https://pytorch.org/docs/1.8.1/generated/torch.nan_to_num.html#torch.nan_to_num) | 否 | +| 72 | [neg](https://pytorch.org/docs/1.8.1/generated/torch.neg.html#torch.neg) | 否 | +| 73 | [negative](https://pytorch.org/docs/1.8.1/generated/torch.negative.html#torch.negative) | 否 | +| 74 | [nextafter](https://pytorch.org/docs/1.8.1/generated/torch.nextafter.html#torch.nextafter) | 否 | +| 75 | [polygamma](https://pytorch.org/docs/1.8.1/generated/torch.polygamma.html#torch.polygamma) | 否 | +| 76 | [pow](https://pytorch.org/docs/1.8.1/generated/torch.pow.html#torch.pow) | 否 | +| 77 | [rad2deg](https://pytorch.org/docs/1.8.1/generated/torch.rad2deg.html#torch.rad2deg) | 否 | +| 78 | [real](https://pytorch.org/docs/1.8.1/generated/torch.real.html#torch.real) | 否 | +| 79 | [reciprocal](https://pytorch.org/docs/1.8.1/generated/torch.reciprocal.html#torch.reciprocal) | 否 | +| 80 | [remainder](https://pytorch.org/docs/1.8.1/generated/torch.remainder.html#torch.remainder) | 否 | +| 81 | [round](https://pytorch.org/docs/1.8.1/generated/torch.round.html#torch.round) | 否 | +| 82 | [rsqrt](https://pytorch.org/docs/1.8.1/generated/torch.rsqrt.html#torch.rsqrt) | 否 | +| 83 | [sigmoid](https://pytorch.org/docs/1.8.1/generated/torch.sigmoid.html#torch.sigmoid) | 否 | +| 84 | [sign](https://pytorch.org/docs/1.8.1/generated/torch.sign.html#torch.sign) | 否 | +| 85 | [sgn](https://pytorch.org/docs/1.8.1/generated/torch.sgn.html#torch.sgn) | 否 | +| 86 | [signbit](https://pytorch.org/docs/1.8.1/generated/torch.signbit.html#torch.signbit) | 否 | +| 87 | [sin](https://pytorch.org/docs/1.8.1/generated/torch.sin.html#torch.sin) | 否 | +| 88 | [sinc](https://pytorch.org/docs/1.8.1/generated/torch.sinc.html#torch.sinc) | 否 | +| 89 | [sinh](https://pytorch.org/docs/1.8.1/generated/torch.sinh.html#torch.sinh) | 否 | +| 90 | [sqrt](https://pytorch.org/docs/1.8.1/generated/torch.sqrt.html#torch.sqrt) | 否 | +| 91 | [square](https://pytorch.org/docs/1.8.1/generated/torch.square.html#torch.square) | 否 | +| 92 | [sub](https://pytorch.org/docs/1.8.1/generated/torch.sub.html#torch.sub) | 否 | +| 93 | [subtract](https://pytorch.org/docs/1.8.1/generated/torch.subtract.html#torch.subtract) | 否 | +| 94 | [tan](https://pytorch.org/docs/1.8.1/generated/torch.tan.html#torch.tan) | 否 | +| 95 | [tanh](https://pytorch.org/docs/1.8.1/generated/torch.tanh.html#torch.tanh) | 否 | +| 96 | [true_divide](https://pytorch.org/docs/1.8.1/generated/torch.true_divide.html#torch.true_divide) | 否 | +| 97 | [trunc](https://pytorch.org/docs/1.8.1/generated/torch.trunc.html#torch.trunc) | 否 | +| 98 | [xlogy](https://pytorch.org/docs/1.8.1/generated/torch.xlogy.html#torch.xlogy) | 否 | + +### Reduction Ops + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [argmax](https://pytorch.org/docs/1.8.1/generated/torch.argmax.html#torch.argmax) | 否 | +| 2 | [argmin](https://pytorch.org/docs/1.8.1/generated/torch.argmin.html#torch.argmin) | 否 | +| 3 | [amax](https://pytorch.org/docs/1.8.1/generated/torch.amax.html#torch.amax) | 否 | +| 4 | [amin](https://pytorch.org/docs/1.8.1/generated/torch.amin.html#torch.amin) | 否 | +| 5 | [all](https://pytorch.org/docs/1.8.1/generated/torch.all.html#torch.all) | 否 | +| 6 | [any](https://pytorch.org/docs/1.8.1/generated/torch.any.html#torch.any) | 否 | +| 7 | [max](https://pytorch.org/docs/1.8.1/generated/torch.max.html#torch.max) | 否 | +| 8 | [min](https://pytorch.org/docs/1.8.1/generated/torch.min.html#torch.min) | 否 | +| 9 | [dist](https://pytorch.org/docs/1.8.1/generated/torch.dist.html#torch.dist) | 否 | +| 10 | [logsumexp](https://pytorch.org/docs/1.8.1/generated/torch.logsumexp.html#torch.logsumexp) | 否 | +| 11 | [mean](https://pytorch.org/docs/1.8.1/generated/torch.mean.html#torch.mean) | 否 | +| 12 | [median](https://pytorch.org/docs/1.8.1/generated/torch.median.html#torch.median) | 否 | +| 13 | [nanmedian](https://pytorch.org/docs/1.8.1/generated/torch.nanmedian.html#torch.nanmedian) | 否 | +| 14 | [mode](https://pytorch.org/docs/1.8.1/generated/torch.mode.html#torch.mode) | 否 | +| 15 | [norm](https://pytorch.org/docs/1.8.1/generated/torch.norm.html#torch.norm) | 否 | +| 16 | [nansum](https://pytorch.org/docs/1.8.1/generated/torch.nansum.html#torch.nansum) | 否 | +| 17 | [prod](https://pytorch.org/docs/1.8.1/generated/torch.prod.html#torch.prod) | 否 | +| 18 | [quantile](https://pytorch.org/docs/1.8.1/generated/torch.quantile.html#torch.quantile) | 否 | +| 19 | [nanquantile](https://pytorch.org/docs/1.8.1/generated/torch.nanquantile.html#torch.nanquantile) | 否 | +| 20 | [std](https://pytorch.org/docs/1.8.1/generated/torch.std.html#torch.std) | 否 | +| 21 | [std_mean](https://pytorch.org/docs/1.8.1/generated/torch.std_mean.html#torch.std_mean) | 否 | +| 22 | [sum](https://pytorch.org/docs/1.8.1/generated/torch.sum.html#torch.sum) | 否 | +| 23 | [unique](https://pytorch.org/docs/1.8.1/generated/torch.unique.html#torch.unique) | 否 | +| 24 | [unique_consecutive](https://pytorch.org/docs/1.8.1/generated/torch.unique_consecutive.html#torch.unique_consecutive) | 否 | +| 25 | [var](https://pytorch.org/docs/1.8.1/generated/torch.var.html#torch.var) | 否 | +| 26 | [var_mean](https://pytorch.org/docs/1.8.1/generated/torch.var_mean.html#torch.var_mean) | 否 | +| 27 | [count_nonzero](https://pytorch.org/docs/1.8.1/generated/torch.count_nonzero.html#torch.count_nonzero) | 否 | + +### Comparison Ops + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [allclose](https://pytorch.org/docs/1.8.1/generated/torch.allclose.html#torch.allclose) | 否 | +| 2 | [argsort](https://pytorch.org/docs/1.8.1/generated/torch.argsort.html#torch.argsort) | 否 | +| 3 | [eq](https://pytorch.org/docs/1.8.1/generated/torch.eq.html#torch.eq) | 否 | +| 4 | [equal](https://pytorch.org/docs/1.8.1/generated/torch.equal.html#torch.equal) | 否 | +| 5 | [ge](https://pytorch.org/docs/1.8.1/generated/torch.ge.html#torch.ge) | 否 | +| 6 | [greater_equal](https://pytorch.org/docs/1.8.1/generated/torch.greater_equal.html#torch.greater_equal) | 否 | +| 7 | [gt](https://pytorch.org/docs/1.8.1/generated/torch.gt.html#torch.gt) | 否 | +| 8 | [greater](https://pytorch.org/docs/1.8.1/generated/torch.greater.html#torch.greater) | 否 | +| 9 | [isclose](https://pytorch.org/docs/1.8.1/generated/torch.isclose.html#torch.isclose) | 否 | +| 10 | [isfinite](https://pytorch.org/docs/1.8.1/generated/torch.isfinite.html#torch.isfinite) | 否 | +| 11 | [isinf](https://pytorch.org/docs/1.8.1/generated/torch.isinf.html#torch.isinf) | 否 | +| 12 | [isposinf](https://pytorch.org/docs/1.8.1/generated/torch.isposinf.html#torch.isposinf) | 否 | +| 13 | [isneginf](https://pytorch.org/docs/1.8.1/generated/torch.isneginf.html#torch.isneginf) | 否 | +| 14 | [isnan](https://pytorch.org/docs/1.8.1/generated/torch.isnan.html#torch.isnan) | 否 | +| 15 | [isreal](https://pytorch.org/docs/1.8.1/generated/torch.isreal.html#torch.isreal) | 否 | +| 16 | [kthvalue](https://pytorch.org/docs/1.8.1/generated/torch.kthvalue.html#torch.kthvalue) | 否 | +| 17 | [le](https://pytorch.org/docs/1.8.1/generated/torch.le.html#torch.le) | 否 | +| 18 | [less_equal](https://pytorch.org/docs/1.8.1/generated/torch.less_equal.html#torch.less_equal) | 否 | +| 19 | [lt](https://pytorch.org/docs/1.8.1/generated/torch.lt.html#torch.lt) | 否 | +| 20 | [less](https://pytorch.org/docs/1.8.1/generated/torch.less.html#torch.less) | 否 | +| 21 | [maximum](https://pytorch.org/docs/1.8.1/generated/torch.maximum.html#torch.maximum) | 否 | +| 22 | [minimum](https://pytorch.org/docs/1.8.1/generated/torch.minimum.html#torch.minimum) | 否 | +| 23 | [fmax](https://pytorch.org/docs/1.8.1/generated/torch.fmax.html#torch.fmax) | 否 | +| 24 | [fmin](https://pytorch.org/docs/1.8.1/generated/torch.fmin.html#torch.fmin) | 否 | +| 25 | [ne](https://pytorch.org/docs/1.8.1/generated/torch.ne.html#torch.ne) | 否 | +| 26 | [not_equal](https://pytorch.org/docs/1.8.1/generated/torch.not_equal.html#torch.not_equal) | 否 | +| 27 | [sort](https://pytorch.org/docs/1.8.1/generated/torch.sort.html#torch.sort) | 否 | +| 28 | [topk](https://pytorch.org/docs/1.8.1/generated/torch.topk.html#torch.topk) | 否 | +| 29 | [msort](https://pytorch.org/docs/1.8.1/generated/torch.msort.html#torch.msort) | 否 | + +### Spectral Ops + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [stft](https://pytorch.org/docs/1.8.1/generated/torch.stft.html#torch.stft) | 否 | +| 2 | [istft](https://pytorch.org/docs/1.8.1/generated/torch.istft.html#torch.istft) | 否 | +| 3 | [bartlett_window](https://pytorch.org/docs/1.8.1/generated/torch.bartlett_window.html#torch.bartlett_window) | 否 | +| 4 | [blackman_window](https://pytorch.org/docs/1.8.1/generated/torch.blackman_window.html#torch.blackman_window) | 否 | +| 5 | [hamming_window](https://pytorch.org/docs/1.8.1/generated/torch.hamming_window.html#torch.hamming_window) | 否 | +| 6 | [hann_window](https://pytorch.org/docs/1.8.1/generated/torch.hann_window.html#torch.hann_window) | 否 | +| 7 | [kaiser_window](https://pytorch.org/docs/1.8.1/generated/torch.kaiser_window.html#torch.kaiser_window) | 否 | + +### Other Operations + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [atleast_1d](https://pytorch.org/docs/1.8.1/generated/torch.atleast_1d.html#torch.atleast_1d) | 否 | +| 2 | [atleast_2d](https://pytorch.org/docs/1.8.1/generated/torch.atleast_2d.html#torch.atleast_2d) | 否 | +| 3 | [atleast_3d](https://pytorch.org/docs/1.8.1/generated/torch.atleast_3d.html#torch.atleast_3d) | 否 | +| 4 | [bincount](https://pytorch.org/docs/1.8.1/generated/torch.bincount.html#torch.bincount) | 否 | +| 5 | [block_diag](https://pytorch.org/docs/1.8.1/generated/torch.block_diag.html#torch.block_diag) | 否 | +| 6 | [broadcast_tensors](https://pytorch.org/docs/1.8.1/generated/torch.broadcast_tensors.html#torch.broadcast_tensors) | 否 | +| 7 | [broadcast_to](https://pytorch.org/docs/1.8.1/generated/torch.broadcast_to.html#torch.broadcast_to) | 否 | +| 8 | [broadcast_shapes](https://pytorch.org/docs/1.8.1/generated/torch.broadcast_shapes.html#torch.broadcast_shapes) | 否 | +| 9 | [bucketize](https://pytorch.org/docs/1.8.1/generated/torch.bucketize.html#torch.bucketize) | 否 | +| 10 | [cartesian_prod](https://pytorch.org/docs/1.8.1/generated/torch.cartesian_prod.html#torch.cartesian_prod) | 否 | +| 11 | [cdist](https://pytorch.org/docs/1.8.1/generated/torch.cdist.html#torch.cdist) | 否 | +| 12 | [clone](https://pytorch.org/docs/1.8.1/generated/torch.clone.html#torch.clone) | 否 | +| 13 | [combinations](https://pytorch.org/docs/1.8.1/generated/torch.combinations.html#torch.combinations) | 否 | +| 14 | [cross](https://pytorch.org/docs/1.8.1/generated/torch.cross.html#torch.cross) | 否 | +| 15 | [cummax](https://pytorch.org/docs/1.8.1/generated/torch.cummax.html#torch.cummax) | 否 | +| 16 | [cummin](https://pytorch.org/docs/1.8.1/generated/torch.cummin.html#torch.cummin) | 否 | +| 17 | [cumprod](https://pytorch.org/docs/1.8.1/generated/torch.cumprod.html#torch.cumprod) | 否 | +| 18 | [cumsum](https://pytorch.org/docs/1.8.1/generated/torch.cumsum.html#torch.cumsum) | 否 | +| 19 | [diag](https://pytorch.org/docs/1.8.1/generated/torch.diag.html#torch.diag) | 否 | +| 20 | [diag_embed](https://pytorch.org/docs/1.8.1/generated/torch.diag_embed.html#torch.diag_embed) | 否 | +| 21 | [diagflat](https://pytorch.org/docs/1.8.1/generated/torch.diagflat.html#torch.diagflat) | 否 | +| 22 | [diagonal](https://pytorch.org/docs/1.8.1/generated/torch.diagonal.html#torch.diagonal) | 否 | +| 23 | [diff](https://pytorch.org/docs/1.8.1/generated/torch.diff.html#torch.diff) | 否 | +| 24 | [einsum](https://pytorch.org/docs/1.8.1/generated/torch.einsum.html#torch.einsum) | 否 | +| 25 | [flatten](https://pytorch.org/docs/1.8.1/generated/torch.flatten.html#torch.flatten) | 否 | +| 26 | [flip](https://pytorch.org/docs/1.8.1/generated/torch.flip.html#torch.flip) | 否 | +| 27 | [fliplr](https://pytorch.org/docs/1.8.1/generated/torch.fliplr.html#torch.fliplr) | 否 | +| 28 | [flipud](https://pytorch.org/docs/1.8.1/generated/torch.flipud.html#torch.flipud) | 否 | +| 29 | [kron](https://pytorch.org/docs/1.8.1/generated/torch.kron.html#torch.kron) | 否 | +| 30 | [rot90](https://pytorch.org/docs/1.8.1/generated/torch.rot90.html#torch.rot90) | 否 | +| 31 | [gcd](https://pytorch.org/docs/1.8.1/generated/torch.gcd.html#torch.gcd) | 否 | +| 32 | [histc](https://pytorch.org/docs/1.8.1/generated/torch.histc.html#torch.histc) | 否 | +| 33 | [meshgrid](https://pytorch.org/docs/1.8.1/generated/torch.meshgrid.html#torch.meshgrid) | 否 | +| 34 | [lcm](https://pytorch.org/docs/1.8.1/generated/torch.lcm.html#torch.lcm) | 否 | +| 35 | [logcumsumexp](https://pytorch.org/docs/1.8.1/generated/torch.logcumsumexp.html#torch.logcumsumexp) | 否 | +| 36 | [ravel](https://pytorch.org/docs/1.8.1/generated/torch.ravel.html#torch.ravel) | 否 | +| 37 | [renorm](https://pytorch.org/docs/1.8.1/generated/torch.renorm.html#torch.renorm) | 否 | +| 38 | [repeat_interleave](https://pytorch.org/docs/1.8.1/generated/torch.repeat_interleave.html#torch.repeat_interleave) | 否 | +| 39 | [roll](https://pytorch.org/docs/1.8.1/generated/torch.roll.html#torch.roll) | 否 | +| 40 | [searchsorted](https://pytorch.org/docs/1.8.1/generated/torch.searchsorted.html#torch.searchsorted) | 否 | +| 41 | [tensordot](https://pytorch.org/docs/1.8.1/generated/torch.tensordot.html#torch.tensordot) | 否 | +| 42 | [trace](https://pytorch.org/docs/1.8.1/generated/torch.trace.html#torch.trace) | 否 | +| 43 | [tril](https://pytorch.org/docs/1.8.1/generated/torch.tril.html#torch.tril) | 否 | +| 44 | [tril_indices](https://pytorch.org/docs/1.8.1/generated/torch.tril_indices.html#torch.tril_indices) | 否 | +| 45 | [triu](https://pytorch.org/docs/1.8.1/generated/torch.triu.html#torch.triu) | 否 | +| 46 | [triu_indices](https://pytorch.org/docs/1.8.1/generated/torch.triu_indices.html#torch.triu_indices) | 否 | +| 47 | [vander](https://pytorch.org/docs/1.8.1/generated/torch.vander.html#torch.vander) | 否 | +| 48 | [view_as_real](https://pytorch.org/docs/1.8.1/generated/torch.view_as_real.html#torch.view_as_real) | 否 | +| 49 | [view_as_complex](https://pytorch.org/docs/1.8.1/generated/torch.view_as_complex.html#torch.view_as_complex) | 否 | + +### BLAS and LAPACK Operations + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [addbmm](https://pytorch.org/docs/1.8.1/generated/torch.addbmm.html#torch.addbmm) | 否 | +| 2 | [addmm](https://pytorch.org/docs/1.8.1/generated/torch.addmm.html#torch.addmm) | 否 | +| 3 | [addmv](https://pytorch.org/docs/1.8.1/generated/torch.addmv.html#torch.addmv) | 否 | +| 4 | [addr](https://pytorch.org/docs/1.8.1/generated/torch.addr.html#torch.addr) | 否 | +| 5 | [baddbmm](https://pytorch.org/docs/1.8.1/generated/torch.baddbmm.html#torch.baddbmm) | 否 | +| 6 | [bmm](https://pytorch.org/docs/1.8.1/generated/torch.bmm.html#torch.bmm) | 否 | +| 7 | [chain_matmul](https://pytorch.org/docs/1.8.1/generated/torch.chain_matmul.html#torch.chain_matmul) | 否 | +| 8 | [cholesky](https://pytorch.org/docs/1.8.1/generated/torch.cholesky.html#torch.cholesky) | 否 | +| 9 | [cholesky_inverse](https://pytorch.org/docs/1.8.1/generated/torch.cholesky_inverse.html#torch.cholesky_inverse) | 否 | +| 10 | [cholesky_solve](https://pytorch.org/docs/1.8.1/generated/torch.cholesky_solve.html#torch.cholesky_solve) | 否 | +| 11 | [dot](https://pytorch.org/docs/1.8.1/generated/torch.dot.html#torch.dot) | 否 | +| 12 | [eig](https://pytorch.org/docs/1.8.1/generated/torch.eig.html#torch.eig) | 否 | +| 13 | [geqrf](https://pytorch.org/docs/1.8.1/generated/torch.geqrf.html#torch.geqrf) | 否 | +| 14 | [ger](https://pytorch.org/docs/1.8.1/generated/torch.ger.html#torch.ger) | 否 | +| 15 | [inner](https://pytorch.org/docs/1.8.1/generated/torch.inner.html#torch.inner) | 否 | +| 16 | [inverse](https://pytorch.org/docs/1.8.1/generated/torch.inverse.html#torch.inverse) | 否 | +| 17 | [det](https://pytorch.org/docs/1.8.1/generated/torch.det.html#torch.det) | 否 | +| 18 | [logdet](https://pytorch.org/docs/1.8.1/generated/torch.logdet.html#torch.logdet) | 否 | +| 19 | [slogdet](https://pytorch.org/docs/1.8.1/generated/torch.slogdet.html#torch.slogdet) | 否 | +| 20 | [lstsq](https://pytorch.org/docs/1.8.1/generated/torch.lstsq.html#torch.lstsq) | 否 | +| 21 | [lu](https://pytorch.org/docs/1.8.1/generated/torch.lu.html#torch.lu) | 否 | +| 22 | [lu_solve](https://pytorch.org/docs/1.8.1/generated/torch.lu_solve.html#torch.lu_solve) | 否 | +| 23 | [lu_unpack](https://pytorch.org/docs/1.8.1/generated/torch.lu_unpack.html#torch.lu_unpack) | 否 | +| 24 | [matmul](https://pytorch.org/docs/1.8.1/generated/torch.matmul.html#torch.matmul) | 否 | +| 25 | [matrix_power](https://pytorch.org/docs/1.8.1/generated/torch.matrix_power.html#torch.matrix_power) | 否 | +| 26 | [matrix_rank](https://pytorch.org/docs/1.8.1/generated/torch.matrix_rank.html#torch.matrix_rank) | 否 | +| 27 | [matrix_exp](https://pytorch.org/docs/1.8.1/generated/torch.matrix_exp.html#torch.matrix_exp) | 否 | +| 28 | [mm](https://pytorch.org/docs/1.8.1/generated/torch.mm.html#torch.mm) | 否 | +| 29 | [mv](https://pytorch.org/docs/1.8.1/generated/torch.mv.html#torch.mv) | 否 | +| 30 | [orgqr](https://pytorch.org/docs/1.8.1/generated/torch.orgqr.html#torch.orgqr) | 否 | +| 31 | [ormqr](https://pytorch.org/docs/1.8.1/generated/torch.ormqr.html#torch.ormqr) | 否 | +| 32 | [outer](https://pytorch.org/docs/1.8.1/generated/torch.outer.html#torch.outer) | 否 | +| 33 | [pinverse](https://pytorch.org/docs/1.8.1/generated/torch.pinverse.html#torch.pinverse) | 否 | +| 34 | [qr](https://pytorch.org/docs/1.8.1/generated/torch.qr.html#torch.qr) | 否 | +| 35 | [solve](https://pytorch.org/docs/1.8.1/generated/torch.solve.html#torch.solve) | 否 | +| 36 | [svd](https://pytorch.org/docs/1.8.1/generated/torch.svd.html#torch.svd) | 否 | +| 37 | [svd_lowrank](https://pytorch.org/docs/1.8.1/generated/torch.svd_lowrank.html#torch.svd_lowrank) | 否 | +| 38 | [pca_lowrank](https://pytorch.org/docs/1.8.1/generated/torch.pca_lowrank.html#torch.pca_lowrank) | 否 | +| 39 | [symeig](https://pytorch.org/docs/1.8.1/generated/torch.symeig.html#torch.symeig) | 否 | +| 40 | [lobpcg](https://pytorch.org/docs/1.8.1/generated/torch.lobpcg.html#torch.lobpcg) | 否 | +| 41 | [trapz](https://pytorch.org/docs/1.8.1/generated/torch.trapz.html#torch.trapz) | 否 | +| 42 | [triangular_solve](https://pytorch.org/docs/1.8.1/generated/torch.triangular_solve.html#torch.triangular_solve) | 否 | +| 43 | [vdot](https://pytorch.org/docs/1.8.1/generated/torch.vdot.html#torch.vdot) | 否 | + +## Utilities + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [compiled_with_cxx11_abi](https://pytorch.org/docs/1.8.1/generated/torch.compiled_with_cxx11_abi.html#torch.compiled_with_cxx11_abi) | 否 | +| 2 | [result_type](https://pytorch.org/docs/1.8.1/generated/torch.result_type.html#torch.result_type) | 否 | +| 3 | [can_cast](https://pytorch.org/docs/1.8.1/generated/torch.can_cast.html#torch.can_cast) | 否 | +| 4 | [promote_types](https://pytorch.org/docs/1.8.1/generated/torch.promote_types.html#torch.promote_types) | 否 | +| 5 | [use_deterministic_algorithms](https://pytorch.org/docs/1.8.1/generated/torch.use_deterministic_algorithms.html#torch.use_deterministic_algorithms) | 否 | +| 6 | [are_deterministic_algorithms_enabled](https://pytorch.org/docs/1.8.1/generated/torch.are_deterministic_algorithms_enabled.html#torch.are_deterministic_algorithms_enabled) | 否 | +| 7 | [_assert](https://pytorch.org/docs/1.8.1/generated/torch._assert.html#torch._assert) | 否 | + +# Layers (torch.nn) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [Parameter](https://pytorch.org/docs/1.8.1/generated/torch.nn.parameter.Parameter.html#torch.nn.parameter.Parameter) | 否 | +| 2 | [UninitializedParameter](https://pytorch.org/docs/1.8.1/generated/torch.nn.parameter.UninitializedParameter.html#torch.nn.parameter.UninitializedParameter) | 否 | + +## [Containers](https://pytorch.org/docs/1.8.1/nn.html#id1) + + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [Module](https://pytorch.org/docs/1.8.1/generated/torch.nn.Module.html#torch.nn.Module) | 否 | +| 2 | [Sequential](https://pytorch.org/docs/1.8.1/generated/torch.nn.Sequential.html#torch.nn.Sequential) | 否 | +| 3 | [ModuleList](https://pytorch.org/docs/1.8.1/generated/torch.nn.ModuleList.html#torch.nn.ModuleList) | 否 | +| 4 | [ModuleDict](https://pytorch.org/docs/1.8.1/generated/torch.nn.ModuleDict.html#torch.nn.ModuleDict) | 否 | +| 5 | [ParameterList](https://pytorch.org/docs/1.8.1/generated/torch.nn.ParameterList.html#torch.nn.ParameterList) | 否 | +| 6 | [ParameterDict](https://pytorch.org/docs/1.8.1/generated/torch.nn.ParameterDict.html#torch.nn.ParameterDict) | 否 | + +### Global Hooks For Module + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [register_module_forward_pre_hook](https://pytorch.org/docs/1.8.1/generated/torch.nn.modules.module.register_module_forward_pre_hook.html#torch.nn.modules.module.register_module_forward_pre_hook) | 否 | +| 2 | [register_module_forward_hook](https://pytorch.org/docs/1.8.1/generated/torch.nn.modules.module.register_module_forward_hook.html#torch.nn.modules.module.register_module_forward_hook) | 否 | +| 3 | [register_module_backward_hook](https://pytorch.org/docs/1.8.1/generated/torch.nn.modules.module.register_module_backward_hook.html#torch.nn.modules.module.register_module_backward_hook) | 否 | + +## [Convolution Layers](https://pytorch.org/docs/1.8.1/nn.html#id1) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.Conv1d](https://pytorch.org/docs/1.8.1/generated/torch.nn.Conv1d.html#torch.nn.Conv1d) | 否 | +| 2 | [nn.Conv2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.Conv2d.html#torch.nn.Conv2d) | 否 | +| 3 | [nn.Conv3d](https://pytorch.org/docs/1.8.1/generated/torch.nn.Conv3d.html#torch.nn.Conv3d) | 否 | +| 4 | [nn.ConvTranspose1d](https://pytorch.org/docs/1.8.1/generated/torch.nn.ConvTranspose1d.html#torch.nn.ConvTranspose1d) | 否 | +| 5 | [nn.ConvTranspose2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.ConvTranspose2d.html#torch.nn.ConvTranspose2d) | 否 | +| 6 | [nn.ConvTranspose3d](https://pytorch.org/docs/1.8.1/generated/torch.nn.ConvTranspose3d.html#torch.nn.ConvTranspose3d) | 否 | +| 7 | [nn.LazyConv1d](https://pytorch.org/docs/1.8.1/generated/torch.nn.LazyConv1d.html#torch.nn.LazyConv1d) | 否 | +| 8 | [nn.LazyConv2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.LazyConv2d.html#torch.nn.LazyConv2d) | 否 | +| 9 | [nn.LazyConv3d](https://pytorch.org/docs/1.8.1/generated/torch.nn.LazyConv3d.html#torch.nn.LazyConv3d) | 否 | +| 10 | [nn.LazyConvTranspose1d](https://pytorch.org/docs/1.8.1/generated/torch.nn.LazyConvTranspose1d.html#torch.nn.LazyConvTranspose1d) | 否 | +| 11 | [nn.LazyConvTranspose2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.LazyConvTranspose2d.html#torch.nn.LazyConvTranspose2d) | 否 | +| 12 | [nn.LazyConvTranspose3d](https://pytorch.org/docs/1.8.1/generated/torch.nn.LazyConvTranspose3d.html#torch.nn.LazyConvTranspose3d) | 否 | +| 13 | [nn.Unfold](https://pytorch.org/docs/1.8.1/generated/torch.nn.Unfold.html#torch.nn.Unfold) | 否 | +| 14 | [nn.Fold](https://pytorch.org/docs/1.8.1/generated/torch.nn.Fold.html#torch.nn.Fold) | 否 | + +## [Pooling layers](https://pytorch.org/docs/1.8.1/nn.html#id1) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.MaxPool1d](https://pytorch.org/docs/1.8.1/generated/torch.nn.MaxPool1d.html#torch.nn.MaxPool1d) | 否 | +| 2 | [nn.MaxPool2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.MaxPool2d.html#torch.nn.MaxPool2d) | 否 | +| 3 | [nn.MaxPool3d](https://pytorch.org/docs/1.8.1/generated/torch.nn.MaxPool3d.html#torch.nn.MaxPool3d) | 否 | +| 4 | [nn.MaxUnpool1d](https://pytorch.org/docs/1.8.1/generated/torch.nn.MaxUnpool1d.html#torch.nn.MaxUnpool1d) | 否 | +| 5 | [nn.MaxUnpool2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.MaxUnpool2d.html#torch.nn.MaxUnpool2d) | 否 | +| 6 | [nn.MaxUnpool3d](https://pytorch.org/docs/1.8.1/generated/torch.nn.MaxUnpool3d.html#torch.nn.MaxUnpool3d) | 否 | +| 7 | [nn.AvgPool1d](https://pytorch.org/docs/1.8.1/generated/torch.nn.AvgPool1d.html#torch.nn.AvgPool1d) | 否 | +| 8 | [nn.AvgPool2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.AvgPool2d.html#torch.nn.AvgPool2d) | 否 | +| 9 | [nn.AvgPool3d](https://pytorch.org/docs/1.8.1/generated/torch.nn.AvgPool3d.html#torch.nn.AvgPool3d) | 否 | +| 10 | [nn.FractionalMaxPool2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.FractionalMaxPool2d.html#torch.nn.FractionalMaxPool2d) | 否 | +| 11 | [nn.LPPool1d](https://pytorch.org/docs/1.8.1/generated/torch.nn.LPPool1d.html#torch.nn.LPPool1d) | 否 | +| 12 | [nn.LPPool2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.LPPool2d.html#torch.nn.LPPool2d) | 否 | +| 13 | [nn.AdaptiveMaxPool1d](https://pytorch.org/docs/1.8.1/generated/torch.nn.AdaptiveMaxPool1d.html#torch.nn.AdaptiveMaxPool1d) | 否 | +| 14 | [nn.AdaptiveMaxPool2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.AdaptiveMaxPool2d.html#torch.nn.AdaptiveMaxPool2d) | 否 | +| 15 | [nn.AdaptiveMaxPool3d](https://pytorch.org/docs/1.8.1/generated/torch.nn.AdaptiveMaxPool3d.html#torch.nn.AdaptiveMaxPool3d) | 否 | +| 16 | [nn.AdaptiveAvgPool1d](https://pytorch.org/docs/1.8.1/generated/torch.nn.AdaptiveAvgPool1d.html#torch.nn.AdaptiveAvgPool1d) | 否 | +| 17 | [nn.AdaptiveAvgPool2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.AdaptiveAvgPool2d.html#torch.nn.AdaptiveAvgPool2d) | 否 | +| 18 | [nn.AdaptiveAvgPool3d](https://pytorch.org/docs/1.8.1/generated/torch.nn.AdaptiveAvgPool3d.html#torch.nn.AdaptiveAvgPool3d) | 否 | + +## [Padding Layers](https://pytorch.org/docs/1.8.1/nn.html#id1) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.ReflectionPad1d](https://pytorch.org/docs/1.8.1/generated/torch.nn.ReflectionPad1d.html#torch.nn.ReflectionPad1d) | 否 | +| 2 | [nn.ReflectionPad2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.ReflectionPad2d.html#torch.nn.ReflectionPad2d) | 否 | +| 3 | [nn.ReplicationPad1d](https://pytorch.org/docs/1.8.1/generated/torch.nn.ReplicationPad1d.html#torch.nn.ReplicationPad1d) | 否 | +| 4 | [nn.ReplicationPad2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.ReplicationPad2d.html#torch.nn.ReplicationPad2d) | 否 | +| 5 | [nn.ReplicationPad3d](https://pytorch.org/docs/1.8.1/generated/torch.nn.ReplicationPad3d.html#torch.nn.ReplicationPad3d) | 否 | +| 6 | [nn.ZeroPad2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.ZeroPad2d.html#torch.nn.ZeroPad2d) | 否 | +| 7 | [nn.ConstantPad1d](https://pytorch.org/docs/1.8.1/generated/torch.nn.ConstantPad1d.html#torch.nn.ConstantPad1d) | 否 | +| 8 | [nn.ConstantPad2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.ConstantPad2d.html#torch.nn.ConstantPad2d) | 否 | +| 9 | [nn.ConstantPad3d](https://pytorch.org/docs/1.8.1/generated/torch.nn.ConstantPad3d.html#torch.nn.ConstantPad3d) | 否 | + + + +## [Non-linear Activations (weighted sum, nonlinearity)](https://pytorch.org/docs/1.8.1/nn.html#id1) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.ELU](https://pytorch.org/docs/1.8.1/generated/torch.nn.ELU.html#torch.nn.ELU) | 否 | +| 2 | [nn.Hardshrink](https://pytorch.org/docs/1.8.1/generated/torch.nn.Hardshrink.html#torch.nn.Hardshrink) | 否 | +| 3 | [nn.Hardsigmoid](https://pytorch.org/docs/1.8.1/generated/torch.nn.Hardsigmoid.html#torch.nn.Hardsigmoid) | 否 | +| 4 | [nn.Hardtanh](https://pytorch.org/docs/1.8.1/generated/torch.nn.Hardtanh.html#torch.nn.Hardtanh) | 否 | +| 5 | [nn.Hardswish](https://pytorch.org/docs/1.8.1/generated/torch.nn.Hardswish.html#torch.nn.Hardswish) | 否 | +| 6 | [nn.LeakyReLU](https://pytorch.org/docs/1.8.1/generated/torch.nn.LeakyReLU.html#torch.nn.LeakyReLU) | 否 | +| 7 | [nn.LogSigmoid](https://pytorch.org/docs/1.8.1/generated/torch.nn.LogSigmoid.html#torch.nn.LogSigmoid) | 否 | +| 8 | [nn.MultiheadAttention](https://pytorch.org/docs/1.8.1/generated/torch.nn.MultiheadAttention.html#torch.nn.MultiheadAttention) | 否 | +| 9 | [nn.PReLU](https://pytorch.org/docs/1.8.1/generated/torch.nn.PReLU.html#torch.nn.PReLU) | 否 | +| 10 | [nn.ReLU](https://pytorch.org/docs/1.8.1/generated/torch.nn.ReLU.html#torch.nn.ReLU) | 否 | +| 11 | [nn.ReLU6](https://pytorch.org/docs/1.8.1/generated/torch.nn.ReLU6.html#torch.nn.ReLU6) | 否 | +| 12 | [nn.RReLU](https://pytorch.org/docs/1.8.1/generated/torch.nn.RReLU.html#torch.nn.RReLU) | 否 | +| 13 | [nn.SELU](https://pytorch.org/docs/1.8.1/generated/torch.nn.SELU.html#torch.nn.SELU) | 否 | +| 14 | [nn.CELU](https://pytorch.org/docs/1.8.1/generated/torch.nn.CELU.html#torch.nn.CELU) | 否 | +| 15 | [nn.GELU](https://pytorch.org/docs/1.8.1/generated/torch.nn.GELU.html#torch.nn.GELU) | 否 | +| 16 | [nn.Sigmoid](https://pytorch.org/docs/1.8.1/generated/torch.nn.Sigmoid.html#torch.nn.Sigmoid) | 否 | +| 17 | [nn.SiLU](https://pytorch.org/docs/1.8.1/generated/torch.nn.SiLU.html#torch.nn.SiLU) | 否 | +| 18 | [nn.Softplus](https://pytorch.org/docs/1.8.1/generated/torch.nn.Softplus.html#torch.nn.Softplus) | 否 | +| 19 | [nn.Softshrink](https://pytorch.org/docs/1.8.1/generated/torch.nn.Softshrink.html#torch.nn.Softshrink) | 否 | +| 20 | [nn.Softsign](https://pytorch.org/docs/1.8.1/generated/torch.nn.Softsign.html#torch.nn.Softsign) | 否 | +| 21 | [nn.Tanh](https://pytorch.org/docs/1.8.1/generated/torch.nn.Tanh.html#torch.nn.Tanh) | 否 | +| 22 | [nn.Tanhshrink](https://pytorch.org/docs/1.8.1/generated/torch.nn.Tanhshrink.html#torch.nn.Tanhshrink) | 否 | +| 23 | [nn.Threshold](https://pytorch.org/docs/1.8.1/generated/torch.nn.Threshold.html#torch.nn.Threshold) | 否 | + +## [Non-linear Activations (other)](https://pytorch.org/docs/1.8.1/nn.html#id1) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.Softmin](https://pytorch.org/docs/1.8.1/generated/torch.nn.Softmin.html#torch.nn.Softmin) | 否 | +| 2 | [nn.Softmax](https://pytorch.org/docs/1.8.1/generated/torch.nn.Softmax.html#torch.nn.Softmax) | 否 | +| 3 | [nn.Softmax2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.Softmax2d.html#torch.nn.Softmax2d) | 否 | +| 4 | [nn.LogSoftmax](https://pytorch.org/docs/1.8.1/generated/torch.nn.LogSoftmax.html#torch.nn.LogSoftmax) | 否 | +| 5 | [nn.AdaptiveLogSoftmaxWithLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.AdaptiveLogSoftmaxWithLoss.html#torch.nn.AdaptiveLogSoftmaxWithLoss) | 否 | + +## [Normalization Layers](https://pytorch.org/docs/1.8.1/nn.html#id1) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.BatchNorm1d](https://pytorch.org/docs/1.8.1/generated/torch.nn.BatchNorm1d.html#torch.nn.BatchNorm1d) | 否 | +| 2 | [nn.BatchNorm2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.BatchNorm2d.html#torch.nn.BatchNorm2d) | 否 | +| 3 | [nn.BatchNorm3d](https://pytorch.org/docs/1.8.1/generated/torch.nn.BatchNorm3d.html#torch.nn.BatchNorm3d) | 否 | +| 4 | [nn.GroupNorm](https://pytorch.org/docs/1.8.1/generated/torch.nn.GroupNorm.html#torch.nn.GroupNorm) | 否 | +| 5 | [nn.SyncBatchNorm](https://pytorch.org/docs/1.8.1/generated/torch.nn.SyncBatchNorm.html#torch.nn.SyncBatchNorm) | 否 | +| 6 | [nn.InstanceNorm1d](https://pytorch.org/docs/1.8.1/generated/torch.nn.InstanceNorm1d.html#torch.nn.InstanceNorm1d) | 否 | +| 7 | [nn.InstanceNorm2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.InstanceNorm2d.html#torch.nn.InstanceNorm2d) | 否 | +| 8 | [nn.InstanceNorm3d](https://pytorch.org/docs/1.8.1/generated/torch.nn.InstanceNorm3d.html#torch.nn.InstanceNorm3d) | 否 | +| 9 | [nn.LayerNorm](https://pytorch.org/docs/1.8.1/generated/torch.nn.LayerNorm.html#torch.nn.LayerNorm) | 否 | +| 10 | [nn.LocalResponseNorm](https://pytorch.org/docs/1.8.1/generated/torch.nn.LocalResponseNorm.html#torch.nn.LocalResponseNorm) | 否 | + + + +## [Recurrent Layers](https://pytorch.org/docs/1.8.1/nn.html#id1) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.RNNBase](https://pytorch.org/docs/1.8.1/generated/torch.nn.RNNBase.html#torch.nn.RNNBase) | 否 | +| 2 | [nn.RNN](https://pytorch.org/docs/1.8.1/generated/torch.nn.RNN.html#torch.nn.RNN) | 否 | +| 3 | [nn.LSTM](https://pytorch.org/docs/1.8.1/generated/torch.nn.LSTM.html#torch.nn.LSTM) | 否 | +| 4 | [nn.GRU](https://pytorch.org/docs/1.8.1/generated/torch.nn.GRU.html#torch.nn.GRU) | 否 | +| 5 | [nn.RNNCell](https://pytorch.org/docs/1.8.1/generated/torch.nn.RNNCell.html#torch.nn.RNNCell) | 否 | +| 6 | [nn.LSTMCell](https://pytorch.org/docs/1.8.1/generated/torch.nn.LSTMCell.html#torch.nn.LSTMCell) | 否 | +| 7 | [nn.GRUCell](https://pytorch.org/docs/1.8.1/generated/torch.nn.GRUCell.html#torch.nn.GRUCell) | 否 | + + + +## [Transformer Layers](https://pytorch.org/docs/1.8.1/nn.html#id1) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.Transformer](https://pytorch.org/docs/1.8.1/generated/torch.nn.Transformer.html#torch.nn.Transformer) | 否 | +| 2 | [nn.TransformerEncoder](https://pytorch.org/docs/1.8.1/generated/torch.nn.TransformerEncoder.html#torch.nn.TransformerEncoder) | 否 | +| 3 | [nn.TransformerDecoder](https://pytorch.org/docs/1.8.1/generated/torch.nn.TransformerDecoder.html#torch.nn.TransformerDecoder) | 否 | +| 4 | [nn.TransformerEncoderLayer](https://pytorch.org/docs/1.8.1/generated/torch.nn.TransformerEncoderLayer.html#torch.nn.TransformerEncoderLayer) | 否 | +| 5 | [nn.TransformerDecoderLayer](https://pytorch.org/docs/1.8.1/generated/torch.nn.TransformerDecoderLayer.html#torch.nn.TransformerDecoderLayer) | 否 | + + + +## [Linear Layers](https://pytorch.org/docs/1.8.1/nn.html#id1) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.Identity](https://pytorch.org/docs/1.8.1/generated/torch.nn.Identity.html#torch.nn.Identity) | 否 | +| 2 | [nn.Linear](https://pytorch.org/docs/1.8.1/generated/torch.nn.Linear.html#torch.nn.Linear) | 否 | +| 3 | [nn.Bilinear](https://pytorch.org/docs/1.8.1/generated/torch.nn.Bilinear.html#torch.nn.Bilinear) | 否 | +| 4 | [nn.LazyLinear](https://pytorch.org/docs/1.8.1/generated/torch.nn.LazyLinear.html#torch.nn.LazyLinear) | 否 | + + + +## [Dropout Layers](https://pytorch.org/docs/1.8.1/nn.html#id1) + + + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.Dropout](https://pytorch.org/docs/1.8.1/generated/torch.nn.Dropout.html#torch.nn.Dropout) | 否 | +| 2 | [nn.Dropout2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.Dropout2d.html#torch.nn.Dropout2d) | 否 | +| 3 | [nn.Dropout3d](https://pytorch.org/docs/1.8.1/generated/torch.nn.Dropout3d.html#torch.nn.Dropout3d) | 否 | +| 4 | [nn.AlphaDropout](https://pytorch.org/docs/1.8.1/generated/torch.nn.AlphaDropout.html#torch.nn.AlphaDropout) | 否 | + +## [Sparse Layers](https://pytorch.org/docs/1.8.1/nn.html#id1) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.Embedding](https://pytorch.org/docs/1.8.1/generated/torch.nn.Embedding.html#torch.nn.Embedding) | 否 | +| 2 | [nn.EmbeddingBag](https://pytorch.org/docs/1.8.1/generated/torch.nn.EmbeddingBag.html#torch.nn.EmbeddingBag) | 否 | + + + +## [Distance Functions](https://pytorch.org/docs/1.8.1/nn.html#id1) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.CosineSimilarity](https://pytorch.org/docs/1.8.1/generated/torch.nn.CosineSimilarity.html#torch.nn.CosineSimilarity) | 否 | +| 2 | [nn.PairwiseDistance](https://pytorch.org/docs/1.8.1/generated/torch.nn.PairwiseDistance.html#torch.nn.PairwiseDistance) | 否 | + + + +## [Loss Functions](https://pytorch.org/docs/1.8.1/nn.html#id1) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.L1Loss](https://pytorch.org/docs/1.8.1/generated/torch.nn.L1Loss.html#torch.nn.L1Loss) | 否 | +| 2 | [nn.MSELoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.MSELoss.html#torch.nn.MSELoss) | 否 | +| 3 | [nn.CrossEntropyLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.CrossEntropyLoss.html#torch.nn.CrossEntropyLoss) | 否 | +| 4 | [nn.CTCLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.CTCLoss.html#torch.nn.CTCLoss) | 否 | +| 5 | [nn.NLLLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.NLLLoss.html#torch.nn.NLLLoss) | 否 | +| 6 | [nn.PoissonNLLLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.PoissonNLLLoss.html#torch.nn.PoissonNLLLoss) | 否 | +| 7 | [nn.GaussianNLLLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.GaussianNLLLoss.html#torch.nn.GaussianNLLLoss) | 否 | +| 8 | [nn.KLDivLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.KLDivLoss.html#torch.nn.KLDivLoss) | 否 | +| 9 | [nn.BCELoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.BCELoss.html#torch.nn.BCELoss) | 否 | +| 10 | [nn.BCEWithLogitsLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.BCEWithLogitsLoss.html#torch.nn.BCEWithLogitsLoss) | 否 | +| 11 | [nn.MarginRankingLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.MarginRankingLoss.html#torch.nn.MarginRankingLoss) | 否 | +| 12 | [nn.HingeEmbeddingLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.HingeEmbeddingLoss.html#torch.nn.HingeEmbeddingLoss) | 否 | +| 13 | [nn.MultiLabelMarginLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.MultiLabelMarginLoss.html#torch.nn.MultiLabelMarginLoss) | 否 | +| 14 | [nn.SmoothL1Loss](https://pytorch.org/docs/1.8.1/generated/torch.nn.SmoothL1Loss.html#torch.nn.SmoothL1Loss) | 否 | +| 15 | [nn.SoftMarginLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.SoftMarginLoss.html#torch.nn.SoftMarginLoss) | 否 | +| 16 | [nn.MultiLabelSoftMarginLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.MultiLabelSoftMarginLoss.html#torch.nn.MultiLabelSoftMarginLoss) | 否 | +| 17 | [nn.CosineEmbeddingLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.CosineEmbeddingLoss.html#torch.nn.CosineEmbeddingLoss) | 否 | +| 18 | [nn.MultiMarginLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.MultiMarginLoss.html#torch.nn.MultiMarginLoss) | 否 | +| 19 | [nn.TripletMarginLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.TripletMarginLoss.html#torch.nn.TripletMarginLoss) | 否 | +| 20 | [nn.TripletMarginWithDistanceLoss](https://pytorch.org/docs/1.8.1/generated/torch.nn.TripletMarginWithDistanceLoss.html#torch.nn.TripletMarginWithDistanceLoss) | 否 | + +## [Vision Layers](https://pytorch.org/docs/1.8.1/nn.html#id1) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.PixelShuffle](https://pytorch.org/docs/1.8.1/generated/torch.nn.PixelShuffle.html#torch.nn.PixelShuffle) | 否 | +| 2 | [nn.PixelUnshuffle](https://pytorch.org/docs/1.8.1/generated/torch.nn.PixelUnshuffle.html#torch.nn.PixelUnshuffle) | 否 | +| 3 | [nn.Upsample](https://pytorch.org/docs/1.8.1/generated/torch.nn.Upsample.html#torch.nn.Upsample) | 否 | +| 4 | [nn.UpsamplingNearest2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.UpsamplingNearest2d.html#torch.nn.UpsamplingNearest2d) | 否 | +| 5 | [nn.UpsamplingBilinear2d](https://pytorch.org/docs/1.8.1/generated/torch.nn.UpsamplingBilinear2d.html#torch.nn.UpsamplingBilinear2d) | 否 | + + + +## [Shuffle Layers](https://pytorch.org/docs/1.8.1/nn.html#id1) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.ChannelShuffle](https://pytorch.org/docs/1.8.1/generated/torch.nn.ChannelShuffle.html#torch.nn.ChannelShuffle) | 否 | + + + +## [DataParallel Layers (multi-GPU, distributed)](https://pytorch.org/docs/1.8.1/nn.html#id1) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.DataParallel](https://pytorch.org/docs/1.8.1/generated/torch.nn.DataParallel.html#torch.nn.DataParallel) | 否 | +| 2 | [nn.parallel.DistributedDataParallel](https://pytorch.org/docs/1.8.1/generated/torch.nn.parallel.DistributedDataParallel.html#torch.nn.parallel.DistributedDataParallel) | 否 | + +## [Utilities](https://pytorch.org/docs/1.8.1/nn.html#id1) + + + +From the `torch.nn.utils` module + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [clip_grad_norm_](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.clip_grad_norm_.html#torch.nn.utils.clip_grad_norm_) | 否 | +| 2 | [clip_grad_value_](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.clip_grad_value_.html#torch.nn.utils.clip_grad_value_) | 否 | +| 3 | [parameters_to_vector](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.parameters_to_vector.html#torch.nn.utils.parameters_to_vector) | 否 | +| 4 | [vector_to_parameters](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.vector_to_parameters.html#torch.nn.utils.vector_to_parameters) | 否 | +| 5 | [prune.BasePruningMethod](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.BasePruningMethod.html#torch.nn.utils.prune.BasePruningMethod) | 否 | +| 6 | [prune.PruningContainer](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.PruningContainer.html#torch.nn.utils.prune.PruningContainer) | 否 | +| 7 | [prune.Identity](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.Identity.html#torch.nn.utils.prune.Identity) | 否 | +| 8 | [prune.RandomUnstructured](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.RandomUnstructured.html#torch.nn.utils.prune.RandomUnstructured) | 否 | +| 9 | [prune.L1Unstructured](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.L1Unstructured.html#torch.nn.utils.prune.L1Unstructured) | 否 | +| 10 | [prune.RandomStructured](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.RandomStructured.html#torch.nn.utils.prune.RandomStructured) | 否 | +| 11 | [prune.LnStructured](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.LnStructured.html#torch.nn.utils.prune.LnStructured) | 否 | +| 12 | [prune.CustomFromMask](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.CustomFromMask.html#torch.nn.utils.prune.CustomFromMask) | 否 | +| 13 | [prune.identity](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.identity.html#torch.nn.utils.prune.identity) | 否 | +| 14 | [prune.random_unstructured](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.random_unstructured.html#torch.nn.utils.prune.random_unstructured) | 否 | +| 15 | [prune.l1_unstructured](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.l1_unstructured.html#torch.nn.utils.prune.l1_unstructured) | 否 | +| 16 | [prune.random_structured](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.random_structured.html#torch.nn.utils.prune.random_structured) | 否 | +| 17 | [prune.ln_structured](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.ln_structured.html#torch.nn.utils.prune.ln_structured) | 否 | +| 18 | [prune.global_unstructured](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.global_unstructured.html#torch.nn.utils.prune.global_unstructured) | 否 | +| 19 | [prune.custom_from_mask](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.custom_from_mask.html#torch.nn.utils.prune.custom_from_mask) | 否 | +| 20 | [prune.remove](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.remove.html#torch.nn.utils.prune.remove) | 否 | +| 21 | [prune.is_pruned](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.prune.is_pruned.html#torch.nn.utils.prune.is_pruned) | 否 | +| 22 | [weight_norm](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.weight_norm.html#torch.nn.utils.weight_norm) | 否 | +| 23 | [remove_weight_norm](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.remove_weight_norm.html#torch.nn.utils.remove_weight_norm) | 否 | +| 24 | [spectral_norm](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.spectral_norm.html#torch.nn.utils.spectral_norm) | 否 | +| 25 | [remove_spectral_norm](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.remove_spectral_norm.html#torch.nn.utils.remove_spectral_norm) | 否 | + + + +### Utility functions in other modules + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.utils.rnn.PackedSequence](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.rnn.PackedSequence.html#torch.nn.utils.rnn.PackedSequence) | 否 | +| 2 | [nn.utils.rnn.pack_padded_sequence](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.rnn.pack_padded_sequence.html#torch.nn.utils.rnn.pack_padded_sequence) | 否 | +| 3 | [nn.utils.rnn.pad_packed_sequence](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.rnn.pad_packed_sequence.html#torch.nn.utils.rnn.pad_packed_sequence) | 否 | +| 4 | [nn.utils.rnn.pad_sequence](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.rnn.pad_sequence.html#torch.nn.utils.rnn.pad_sequence) | 否 | +| 5 | [nn.utils.rnn.pack_sequence](https://pytorch.org/docs/1.8.1/generated/torch.nn.utils.rnn.pack_sequence.html#torch.nn.utils.rnn.pack_sequence) | 否 | +| 6 | [nn.Flatten](https://pytorch.org/docs/1.8.1/generated/torch.nn.Flatten.html#torch.nn.Flatten) | 否 | +| 7 | [nn.Unflatten](https://pytorch.org/docs/1.8.1/generated/torch.nn.Unflatten.html#torch.nn.Unflatten) | 否 | + +### Lazy Modules Initialization + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [nn.modules.lazy.LazyModuleMixin](https://pytorch.org/docs/1.8.1/generated/torch.nn.modules.lazy.LazyModuleMixin.html#torch.nn.modules.lazy.LazyModuleMixin) | 否 | + + + + + + + + + + + +# Functions(torch.nn.functional) + +## [Convolution functions](https://pytorch.org/docs/1.8.1/nn.functional.html#convolution-functions) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [conv1d](https://pytorch.org/docs/1.8.1/nn.functional.html#conv1d) | 否 | +| 2 | [conv2d](https://pytorch.org/docs/1.8.1/nn.functional.html#conv2d) | 否 | +| 3 | [conv3d](https://pytorch.org/docs/1.8.1/nn.functional.html#conv3d) | 否 | +| 4 | [conv_transpose1d](https://pytorch.org/docs/1.8.1/nn.functional.html#conv-transpose1d) | 否 | +| 5 | [conv_transpose2d](https://pytorch.org/docs/1.8.1/nn.functional.html#conv-transpose2d) | 否 | +| 6 | [conv_transpose3d](https://pytorch.org/docs/1.8.1/nn.functional.html#conv-transpose3d) | 否 | +| 7 | [unfold](https://pytorch.org/docs/1.8.1/nn.functional.html#unfold) | 否 | +| 8 | [fold](https://pytorch.org/docs/1.8.1/nn.functional.html#fold) | 否 | + +## [Pooling functions](https://pytorch.org/docs/1.8.1/nn.functional.html#pooling-functions) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [avg_pool1d](https://pytorch.org/docs/1.8.1/nn.functional.html#avg-pool1d) | 否 | +| 2 | [avg_pool2d](https://pytorch.org/docs/1.8.1/nn.functional.html#avg-pool2d) | 否 | +| 3 | [avg_pool3d](https://pytorch.org/docs/1.8.1/nn.functional.html#avg-pool3d) | 否 | +| 4 | [max_pool1d](https://pytorch.org/docs/1.8.1/nn.functional.html#max-pool1d) | 否 | +| 5 | [max_pool2d](https://pytorch.org/docs/1.8.1/nn.functional.html#max-pool2d) | 否 | +| 6 | [max_pool3d](https://pytorch.org/docs/1.8.1/nn.functional.html#max-pool3d) | 否 | +| 7 | [max_unpool1d](https://pytorch.org/docs/1.8.1/nn.functional.html#max-unpool1d) | 否 | +| 8 | [max_unpool2d](https://pytorch.org/docs/1.8.1/nn.functional.html#max-unpool2d) | 否 | +| 9 | [max_unpool3d](https://pytorch.org/docs/1.8.1/nn.functional.html#max-unpool3d) | 否 | +| 10 | [lp_pool1d](https://pytorch.org/docs/1.8.1/nn.functional.html#lp-pool1d) | 否 | +| 11 | [lp_pool2d](https://pytorch.org/docs/1.8.1/nn.functional.html#lp-pool2d) | 否 | +| 12 | [adaptive_max_pool1d](https://pytorch.org/docs/1.8.1/nn.functional.html#adaptive-max-pool1d) | 否 | +| 13 | [adaptive_max_pool2d](https://pytorch.org/docs/1.8.1/nn.functional.html#adaptive-max-pool2d) | 否 | +| 14 | [adaptive_max_pool3d](https://pytorch.org/docs/1.8.1/nn.functional.html#adaptive-max-pool3d) | 否 | +| 15 | [adaptive_avg_pool1d](https://pytorch.org/docs/1.8.1/nn.functional.html#adaptive-avg-pool1d) | 否 | +| 16 | [adaptive_avg_pool2d](https://pytorch.org/docs/1.8.1/nn.functional.html#adaptive-avg-pool2d) | 否 | +| 17 | [adaptive_avg_pool3d](https://pytorch.org/docs/1.8.1/nn.functional.html#adaptive-avg-pool3d) | 否 | + +## [Non-linear activation functions](https://pytorch.org/docs/1.8.1/nn.functional.html#non-linear-activation-functions) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [threshold](https://pytorch.org/docs/1.8.1/nn.functional.html#threshold) | 否 | +| 2 | [relu](https://pytorch.org/docs/1.8.1/nn.functional.html#relu) | 否 | +| 3 | [hardtanh](https://pytorch.org/docs/1.8.1/nn.functional.html#hardtanh) | 否 | +| 4 | [hardswish](https://pytorch.org/docs/1.8.1/nn.functional.html#hardswish) | 否 | +| 5 | [relu6](https://pytorch.org/docs/1.8.1/nn.functional.html#relu6) | 否 | +| 6 | [elu](https://pytorch.org/docs/1.8.1/nn.functional.html#elu) | 否 | +| 7 | [selu](https://pytorch.org/docs/1.8.1/nn.functional.html#selu) | 否 | +| 8 | [celu](https://pytorch.org/docs/1.8.1/nn.functional.html#celu) | 否 | +| 9 | [leaky_relu](https://pytorch.org/docs/1.8.1/nn.functional.html#leaky-relu) | 否 | +| 10 | [prelu](https://pytorch.org/docs/1.8.1/nn.functional.html#prelu) | 否 | +| 11 | [rrelu](https://pytorch.org/docs/1.8.1/nn.functional.html#rrelu) | 否 | +| 12 | [glu](https://pytorch.org/docs/1.8.1/nn.functional.html#glu) | 否 | +| 13 | [gelu](https://pytorch.org/docs/1.8.1/nn.functional.html#gelu) | 否 | +| 14 | [logsigmoid](https://pytorch.org/docs/1.8.1/nn.functional.html#logsigmoid) | 否 | +| 15 | [hardshrink](https://pytorch.org/docs/1.8.1/nn.functional.html#hardshrink) | 否 | +| 16 | [tanhshrink](https://pytorch.org/docs/1.8.1/nn.functional.html#tanhshrink) | 否 | +| 17 | [softsign](https://pytorch.org/docs/1.8.1/nn.functional.html#softsign) | 否 | +| 18 | [softplus](https://pytorch.org/docs/1.8.1/nn.functional.html#softplus) | 否 | +| 19 | [softmin](https://pytorch.org/docs/1.8.1/nn.functional.html#softmin) | 否 | +| 20 | [softmax](https://pytorch.org/docs/1.8.1/nn.functional.html#softmax) | 否 | +| 21 | [softshrink](https://pytorch.org/docs/1.8.1/nn.functional.html#softshrink) | 否 | +| 22 | [gumbel_softmax](https://pytorch.org/docs/1.8.1/nn.functional.html#gumbel-softmax) | 否 | +| 23 | [log_softmax](https://pytorch.org/docs/1.8.1/nn.functional.html#log-softmax) | 否 | +| 24 | [tanh](https://pytorch.org/docs/1.8.1/nn.functional.html#tanh) | 否 | +| 25 | [sigmoid](https://pytorch.org/docs/1.8.1/nn.functional.html#sigmoid) | 否 | +| 26 | [hardsigmoid](https://pytorch.org/docs/1.8.1/nn.functional.html#hardsigmoid) | 否 | +| 27 | [silu](https://pytorch.org/docs/1.8.1/nn.functional.html#silu) | 否 | + +## [Normalization functions](https://pytorch.org/docs/1.8.1/nn.functional.html#normalization-functions) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [batch_norm](https://pytorch.org/docs/1.8.1/nn.functional.html#batch-norm) | 否 | +| 2 | [instance_norm](https://pytorch.org/docs/1.8.1/nn.functional.html#instance-norm) | 否 | +| 3 | [layer_norm](https://pytorch.org/docs/1.8.1/nn.functional.html#layer-norm) | 否 | +| 4 | [local_response_norm](https://pytorch.org/docs/1.8.1/nn.functional.html#local-response-norm) | 否 | +| 5 | [normalize](https://pytorch.org/docs/1.8.1/nn.functional.html#normalize) | 否 | + +## [Linear functions](https://pytorch.org/docs/1.8.1/nn.functional.html#linear-functions)[Linear functions](https://pytorch.org/docs/1.8.1/nn.functional.html#linear-functions) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [linear](https://pytorch.org/docs/1.8.1/nn.functional.html#linear) | 否 | +| 2 | [bilinear](https://pytorch.org/docs/1.8.1/nn.functional.html#bilinear) | 否 | + +## [Dropout functions](https://pytorch.org/docs/1.8.1/nn.functional.html#dropout-functions) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [dropout](https://pytorch.org/docs/1.8.1/nn.functional.html#dropout) | 否 | +| 2 | [alpha_dropout](https://pytorch.org/docs/1.8.1/nn.functional.html#alpha-dropout) | 否 | +| 3 | [feature_alpha_dropout](https://pytorch.org/docs/1.8.1/nn.functional.html#feature-alpha-dropout) | 否 | +| 4 | [dropout2d](https://pytorch.org/docs/1.8.1/nn.functional.html#dropout2d) | 否 | +| 5 | [dropout3d](https://pytorch.org/docs/1.8.1/nn.functional.html#dropout3d) | 否 | + +## [Sparse functions](https://pytorch.org/docs/1.8.1/nn.functional.html#sparse-functions) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [embedding](https://pytorch.org/docs/1.8.1/nn.functional.html#embedding) | 否 | +| 2 | [embedding_bag](https://pytorch.org/docs/1.8.1/nn.functional.html#embedding-bag) | 否 | +| 3 | [one_hot](https://pytorch.org/docs/1.8.1/nn.functional.html#one-hot) | 否 | + +## [Distance functions](https://pytorch.org/docs/1.8.1/nn.functional.html#distance-functions) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [pairwise_distance](https://pytorch.org/docs/1.8.1/nn.functional.html#pairwise-distance) | 否 | +| 2 | [cosine_similarity](https://pytorch.org/docs/1.8.1/nn.functional.html#cosine-similarity) | 否 | +| 3 | [pdist](https://pytorch.org/docs/1.8.1/nn.functional.html#pdist) | 否 | + +## [Loss functions](https://pytorch.org/docs/1.8.1/nn.functional.html#loss-functions) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [binary_cross_entropy](https://pytorch.org/docs/1.8.1/nn.functional.html#binary-cross-entropy) | 否 | +| 2 | [binary_cross_entropy_with_logits](https://pytorch.org/docs/1.8.1/nn.functional.html#binary-cross-entropy-with-logits) | 否 | +| 3 | [poisson_nll_loss](https://pytorch.org/docs/1.8.1/nn.functional.html#poisson-nll-loss) | 否 | +| 4 | [cosine_embedding_loss](https://pytorch.org/docs/1.8.1/nn.functional.html#cosine-embedding-loss) | 否 | +| 5 | [cross_entropy](https://pytorch.org/docs/1.8.1/nn.functional.html#cross-entropy) | 否 | +| 6 | [ctc_loss](https://pytorch.org/docs/1.8.1/nn.functional.html#ctc-loss) | 否 | +| 7 | [hinge_embedding_loss](https://pytorch.org/docs/1.8.1/nn.functional.html#hinge-embedding-loss) | 否 | +| 8 | [kl_div](https://pytorch.org/docs/1.8.1/nn.functional.html#kl-div) | 否 | +| 9 | [l1_loss](https://pytorch.org/docs/1.8.1/nn.functional.html#l1-loss) | 否 | +| 10 | [mse_loss](https://pytorch.org/docs/1.8.1/nn.functional.html#mse-loss) | 否 | +| 11 | [margin_ranking_loss](https://pytorch.org/docs/1.8.1/nn.functional.html#margin-ranking-loss) | 否 | +| 12 | [multilabel_margin_loss](https://pytorch.org/docs/1.8.1/nn.functional.html#multilabel-margin-loss) | 否 | +| 13 | [multilabel_soft_margin_loss](https://pytorch.org/docs/1.8.1/nn.functional.html#multilabel-soft-margin-loss) | 否 | +| 14 | [multi_margin_loss](https://pytorch.org/docs/1.8.1/nn.functional.html#multi-margin-loss) | 否 | +| 15 | [nll_loss](https://pytorch.org/docs/1.8.1/nn.functional.html#nll-loss) | 否 | +| 16 | [smooth_l1_loss](https://pytorch.org/docs/1.8.1/nn.functional.html#smooth-l1-loss) | 否 | +| 17 | [soft_margin_loss](https://pytorch.org/docs/1.8.1/nn.functional.html#soft-margin-loss) | 否 | +| 18 | [triplet_margin_loss](https://pytorch.org/docs/1.8.1/nn.functional.html#triplet-margin-loss) | 否 | +| 19 | [triplet_margin_with_distance_loss](https://pytorch.org/docs/1.8.1/nn.functional.html#triplet-margin-with-distance-loss) | 否 | + +## [Vision functions](https://pytorch.org/docs/1.8.1/nn.functional.html#vision-functions) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [pixel_shuffle](https://pytorch.org/docs/1.8.1/nn.functional.html#pixel-shuffle) | 否 | +| 2 | [pixel_unshuffle](https://pytorch.org/docs/1.8.1/nn.functional.html#pixel-unshuffle) | 否 | +| 3 | [pad](https://pytorch.org/docs/1.8.1/nn.functional.html#pad) | 否 | +| 4 | [interpolate](https://pytorch.org/docs/1.8.1/nn.functional.html#interpolate) | 否 | +| 5 | [upsample](https://pytorch.org/docs/1.8.1/nn.functional.html#upsample) | 否 | +| 6 | [upsample_nearest](https://pytorch.org/docs/1.8.1/nn.functional.html#upsample-nearest) | 否 | +| 7 | [upsample_bilinear](https://pytorch.org/docs/1.8.1/nn.functional.html#upsample-bilinear) | 否 | +| 8 | [grid_sample](https://pytorch.org/docs/1.8.1/nn.functional.html#grid-sample) | 否 | +| 9 | [affine_grid](https://pytorch.org/docs/1.8.1/nn.functional.html#affine-grid) | 否 | + +## [DataParallel functions (multi-GPU, distributed)](https://pytorch.org/docs/1.8.1/nn.functional.html#dataparallel-functions-multi-gpu-distributed) + +| 序号 | API名称 | 支持情况 | +| ---- | ------------------------------------------------------------ | -------- | +| 1 | [data_parallel](https://pytorch.org/docs/1.8.1/nn.functional.html#data-parallel) | 否 | + +# [torch.distributed](https://pytorch.org/docs/1.8.1/distributed.html) + +| 序号 | API名称 | 支持情况 | +| ---- | ----------------------------------------- | -------- | +| 1 | torch.distributed.is_available | 否 | +| 2 | torch.distributed.init_process_group | 否 | +| 3 | torch.distributed.Backend | 否 | +| 4 | torch.distributed.get_backend | 否 | +| 5 | torch.distributed.get_rank | 否 | +| 6 | torch.distributed.get_world_size | 否 | +| 7 | torch.distributed.is_initialized | 否 | +| 8 | torch.distributed.is_mpi_available | 否 | +| 9 | torch.distributed.is_nccl_available | 否 | +| 10 | torch.distributed.Store | 否 | +| 11 | torch.distributed.TCPStore | 否 | +| 12 | torch.distributed.HashStore | 否 | +| 13 | torch.distributed.FileStore | 否 | +| 14 | torch.distributed.PrefixStore | 否 | +| 15 | torch.distributed.Store.set | 否 | +| 16 | torch.distributed.Store.get | 否 | +| 17 | torch.distributed.Store.add | 否 | +| 18 | torch.distributed.Store.wait | 否 | +| 19 | torch.distributed.Store.num_keys | 否 | +| 20 | torch.distributed.Store.delete_key | 否 | +| 21 | torch.distributed.Store.set_timeout | 否 | +| 22 | torch.distributed.new_group | 否 | +| 23 | torch.distributed.send | 否 | +| 24 | torch.distributed.recv | 否 | +| 25 | torch.distributed.isend | 否 | +| 26 | torch.distributed.irecv | 否 | +| 27 | is_completed | 否 | +| 28 | wait | 否 | +| 29 | torch.distributed.broadcast | 否 | +| 30 | torch.distributed.broadcast_object_list | 否 | +| 31 | torch.distributed.all_reduce | 否 | +| 32 | torch.distributed.reduce | 否 | +| 33 | torch.distributed.all_gather | 否 | +| 34 | torch.distributed.all_gather_object | 否 | +| 35 | torch.distributed.gather | 否 | +| 36 | torch.distributed.gather_object | 否 | +| 37 | torch.distributed.scatter | 否 | +| 38 | torch.distributed.scatter_object_list | 否 | +| 39 | torch.distributed.reduce_scatter | 否 | +| 40 | torch.distributed.all_to_all | 否 | +| 41 | torch.distributed.barrier | 否 | +| 42 | torch.distributed.ReduceOp | 否 | +| 43 | torch.distributed.reduce_op | 否 | +| 44 | torch.distributed.broadcast_multigpu | 否 | +| 45 | torch.distributed.all_reduce_multigpu | 否 | +| 46 | torch.distributed.reduce_multigpu | 否 | +| 47 | torch.distributed.all_gather_multigpu | 否 | +| 48 | torch.distributed.reduce_scatter_multigpu | 否 | +| 49 | torch.distributed.launch | 否 | +| 50 | torch.multiprocessing.spawn | 否 | + +# torch.npu + +| 序号 | API名称 | npu对应API名称 | 是否支持 | +| ---- | ------------------------------------- | ------------------------------------ | -------- | +| 1 | torch.cuda.current_blas_handle | torch.npu.current_blas_handle | 否 | +| 2 | torch.cuda.current_device | torch.npu.current_device | 是 | +| 3 | torch.cuda.current_stream | torch.npu.current_stream | 是 | +| 4 | torch.cuda.default_stream | torch.npu.default_stream | 是 | +| 5 | torch.cuda.device | torch.npu.device | 否 | +| 6 | torch.cuda.device_count | torch.npu.device_count | 是 | +| 7 | torch.cuda.device_of | torch.npu.device_of | 否 | +| 8 | torch.cuda.get_device_capability | torch.npu.get_device_capability | 否 | +| 9 | torch.cuda.get_device_name | torch.npu.get_device_name | 否 | +| 10 | torch.cuda.init | torch.npu.init | 是 | +| 11 | torch.cuda.ipc_collect | torch.npu.ipc_collect | 否 | +| 12 | torch.cuda.is_available | torch.npu.is_available | 是 | +| 13 | torch.cuda.is_initialized | torch.npu.is_initialized | 是 | +| 14 | torch.cuda.set_device | torch.npu.set_device | 部分支持 | +| 15 | torch.cuda.stream | torch.npu.stream | 是 | +| 16 | torch.cuda.synchronize | torch.npu.synchronize | 是 | +| 17 | torch.cuda.get_rng_state | torch.npu.get_rng_state | 否 | +| 18 | torch.cuda.get_rng_state_all | torch.npu.get_rng_state_all | 否 | +| 19 | torch.cuda.set_rng_state | torch.npu.set_rng_state | 否 | +| 20 | torch.cuda.set_rng_state_all | torch.npu.set_rng_state_all | 否 | +| 21 | torch.cuda.manual_seed | torch.npu.manual_seed | 否 | +| 22 | torch.cuda.manual_seed_all | torch.npu.manual_seed_all | 否 | +| 23 | torch.cuda.seed | torch.npu.seed | 否 | +| 24 | torch.cuda.seed_all | torch.npu.seed_all | 否 | +| 25 | torch.cuda.initial_seed | torch.npu.initial_seed | 否 | +| 26 | torch.cuda.comm.broadcast | torch.npu.comm.broadcast | 否 | +| 27 | torch.cuda.comm.broadcast_coalesced | torch.npu.comm.broadcast_coalesced | 否 | +| 28 | torch.cuda.comm.reduce_add | torch.npu.comm.reduce_add | 否 | +| 29 | torch.cuda.comm.scatter | torch.npu.comm.scatter | 否 | +| 30 | torch.cuda.comm.gather | torch.npu.comm.gather | 否 | +| 31 | torch.cuda.Stream | torch.npu.Stream | 是 | +| 32 | torch.cuda.Stream.query | torch.npu.Stream.query | 否 | +| 33 | torch.cuda.Stream.record_event | torch.npu.Stream.record_event | 是 | +| 34 | torch.cuda.Stream.synchronize | torch.npu.Stream.synchronize | 是 | +| 35 | torch.cuda.Stream.wait_event | torch.npu.Stream.wait_event | 是 | +| 36 | torch.cuda.Stream.wait_stream | torch.npu.Stream.wait_stream | 是 | +| 37 | torch.cuda.Event | torch.npu.Event | 是 | +| 38 | torch.cuda.Event.elapsed_time | torch.npu.Event.elapsed_time | 是 | +| 39 | torch.cuda.Event.from_ipc_handle | torch.npu.Event.from_ipc_handle | 否 | +| 40 | torch.cuda.Event.ipc_handle | torch.npu.Event.ipc_handle | 否 | +| 41 | torch.cuda.Event.query | torch.npu.Event.query | 是 | +| 42 | torch.cuda.Event.record | torch.npu.Event.record | 是 | +| 43 | torch.cuda.Event.synchronize | torch.npu.Event.synchronize | 是 | +| 44 | torch.cuda.Event.wait | torch.npu.Event.wait | 是 | +| 45 | torch.cuda.empty_cache | torch.npu.empty_cache | 是 | +| 46 | torch.cuda.memory_stats | torch.npu.memory_stats | 是 | +| 47 | torch.cuda.memory_summary | torch.npu.memory_summary | 是 | +| 48 | torch.cuda.memory_snapshot | torch.npu.memory_snapshot | 是 | +| 49 | torch.cuda.memory_allocated | torch.npu.memory_allocated | 是 | +| 50 | torch.cuda.max_memory_allocated | torch.npu.max_memory_allocated | 是 | +| 51 | torch.cuda.reset_max_memory_allocated | torch.npu.reset_max_memory_allocated | 是 | +| 52 | torch.cuda.memory_reserved | torch.npu.memory_reserved | 是 | +| 53 | torch.cuda.max_memory_reserved | torch.npu.max_memory_reserved | 是 | +| 54 | torch.cuda.memory_cached | torch.npu.memory_cached | 是 | +| 55 | torch.cuda.max_memory_cached | torch.npu.max_memory_cached | 是 | +| 56 | torch.cuda.reset_max_memory_cached | torch.npu.reset_max_memory_cached | 是 | +| 57 | torch.cuda.nvtx.mark | torch.npu.nvtx.mark | 否 | +| 58 | torch.cuda.nvtx.range_push | torch.npu.nvtx.range_push | 否 | +| 59 | torch.cuda.nvtx.range_pop | torch.npu.nvtx.range_pop | 否 | +| 60 | torch.cuda._sleep | torch.npu._sleep | 否 | +| 61 | torch.cuda.Stream.priority_range | torch.npu.Stream.priority_range | 否 | +| 62 | torch.cuda.get_device_properties | torch.npu.get_device_properties | 否 | +| 63 | torch.cuda.amp.GradScaler | torch.npu.amp.GradScaler | 否 | + +# NPU自定义算子 + +| 序号 | 算子名称 | +| ---- | ---------------------------------------------- | +| 1 | npu_convolution_transpose | +| 2 | npu_conv_transpose2d | +| 3 | npu_convolution_transpose_backward | +| 4 | npu_conv_transpose2d_backward | +| 5 | npu_conv_transpose3d_backward | +| 6 | npu_convolution | +| 7 | npu_convolution_backward | +| 8 | npu_convolution_double_backward | +| 9 | npu_conv2d | +| 10 | npu_conv2d.out | +| 11 | npu_conv2d_backward | +| 12 | npu_conv3d | +| 13 | npu_conv3d.out | +| 14 | npu_conv3d_backward | +| 15 | one_ | +| 16 | npu_sort_v2.out | +| 17 | npu_sort_v2 | +| 18 | npu_format_cast | +| 19 | npu_format_cast_.acl_format | +| 20 | npu_format_cast_.src | +| 21 | npu_transpose_to_contiguous | +| 22 | npu_transpose | +| 23 | npu_transpose.out | +| 24 | npu_broadcast | +| 25 | npu_broadcast.out | +| 26 | npu_dtype_cast | +| 27 | npu_dtype_cast_.Tensor | +| 28 | npu_roi_alignbk | +| 29 | empty_with_format | +| 30 | empty_with_format.names | +| 31 | copy_memory_ | +| 32 | npu_one_hot | +| 33 | npu_stride_add | +| 34 | npu_softmax_cross_entropy_with_logits | +| 35 | npu_softmax_cross_entropy_with_logits_backward | +| 36 | npu_ps_roi_pooling | +| 37 | npu_ps_roi_pooling_backward | +| 38 | npu_roi_align | +| 39 | npu_nms_v4 | +| 40 | npu_lstm | +| 41 | npu_lstm_backward | +| 42 | npu_iou | +| 43 | npu_ptiou | +| 44 | npu_nms_with_mask | +| 45 | npu_pad | +| 46 | npu_bounding_box_encode | +| 47 | npu_bounding_box_decode | +| 48 | npu_gru | +| 49 | npu_gru_backward | +| 50 | npu_set_.source_Storage_storage_offset_format | +| 51 | npu_random_choice_with_mask | +| 52 | npu_batch_nms | +| 53 | npu_slice | +| 54 | npu_slice.out | +| 55 | npu_dropoutV2 | +| 56 | npu_dropoutV2_backward | +| 57 | _npu_dropout | +| 58 | _npu_dropout_inplace | +| 59 | npu_dropout_backward | +| 60 | npu_indexing | +| 61 | npu_indexing.out | +| 62 | npu_ifmr | +| 63 | npu_max.dim | +| 64 | npu_max.names_dim | +| 65 | npu_scatter | +| 66 | npu_max_backward | +| 67 | npu_apply_adam | +| 68 | npu_layer_norm_eval | +| 69 | npu_alloc_float_status | +| 70 | npu_get_float_status | +| 71 | npu_clear_float_status | +| 72 | npu_confusion_transpose | +| 73 | npu_confusion_transpose_backward | +| 74 | npu_bmmV2 | +| 75 | fast_gelu | +| 76 | fast_gelu_backward | +| 77 | npu_sub_sample | +| 78 | npu_deformable_conv2d | +| 79 | npu_deformable_conv2dbk | +| 80 | npu_mish | +| 81 | npu_anchor_response_flags | +| 82 | npu_yolo_boxes_encode | +| 83 | npu_grid_assign_positive | +| 84 | npu_mish_backward | +| 85 | npu_normalize_batch | +| 86 | npu_masked_fill_range | +| 87 | npu_linear | +| 88 | npu_linear_backward | +| 89 | npu_bert_apply_adam | +| 90 | npu_giou | +| 91 | npu_giou_backward | + +详细算子接口说明: + +> ``` +> npu_apply_adam(beta1_power, beta2_power, lr, beta1, beta2, epsilon, grad, use_locking, use_nesterov, out = (var, m, v)) +> ``` + +count adam result. + +- Parameters: + - **beta1_power** (Number) - power of beta1. + - **beta2_power** (Number) - power of beta2. + - **lr** (Number) - learning rate. + - **beta1** (Number) - exponential decay rate for the 1st moment estimates. + - **beta2** (Number) - exponential decay rate for the 2nd moment estimates. + - **epsilon** (Number) - term added to the denominator to improve numerical stability. + - **grad** (Tensor) - the gradient. + - **use_locking** (bool) - If `True` use locks for update operations. + - **use_nesterov** (bool) -If `True`, uses the nesterov update. + - **var** (Tensor) - variables to be optimized. + - **m** (Tensor) - mean value of variables. + - **v** (Tensor) - variance of variables. + +- constraints: + + None + +- Examples: + + None + +> npu_bert_apply_adam(var, m, v, lr, beta1, beta2, epsilon, grad, max_grad_norm, global_grad_norm, weight_decay, ) + +count adam result in bert. + +- Parameters: + - **lr** (Number) - learning rate. + - **beta1** (Number) - exponential decay rate for the 1st moment estimates. + - **beta2** (Number) - exponential decay rate for the 2nd moment estimates. + - **epsilon** (Number) - term added to the denominator to improve numerical stability. + - **grad** (Tensor) - the gradient. + - **max_grad_norm** (Number) - maximum norm for the gradients. + - **global_grad_norm** (Number) - L2_norm for the gradients. + - **weight_decay** (Number) - weight decay + - **var** (Tensor) - variables to be optimized. + - **m** (Tensor) -mean value of variables. + - **v** (Tensor) - variance of variables. + +- constraints: + + None + +- Examples: + + ```python + >>> var_in = torch.rand(321538).uniform_(-32.,21.).npu() + >>> var_in + tensor([ 0.6119, 5.8193, 3.0683, ..., -28.5832, 12.9402, -24.0488], + device='npu:0') + >>> m_in = torch.zeros(321538).npu() + >>> v_in = torchzeros(321538).npu() + >>> grad = torch.rand(321538).uniform_(-0.05,0.03).npu() + >>> grad + tensor([-0.0315, -0.0113, -0.0132, ..., 0.0106, -0.0226, -0.0252], + device='npu:0') + >>> max_grad_norm = -1. + >>> beta1 = 0.9 + >>> beta2 = 0.99 + >>> weight_decay = 0. + >>> lr = 0.1 + >>> epsilon = 1e-06 + >>> global_grad_norm = 0. + >>> var_out, m_out, v_out = torch.npu_bert_apply_adam(var_in, m_in, v_in, lr, beta1, beta2, epsilon, grad, max_grad_norm, global_grad_norm, weight_decay) + >>> var_out + tensor([ 0.7118, 5.9192, 3.1682, ..., -28.6831, 13.0402, -23.9489], + device='npu:0') + >>> m_out + tensor([-0.0032, -0.0011, -0.0013, ..., 0.0011, -0.0023, -0.0025], + device='npu:0') + >>> v_out + tensor([9.9431e-06, 1.2659e-06, 1.7328e-06, ..., 1.1206e-06, 5.0933e-06, + 6.3495e-06], device='npu:0') + ``` + + + diff --git "a/docs/zh/PyTorch\345\256\211\350\243\205\346\214\207\345\215\227/PyTorch\345\256\211\350\243\205\346\214\207\345\215\227.md" "b/docs/zh/PyTorch\345\256\211\350\243\205\346\214\207\345\215\227/PyTorch\345\256\211\350\243\205\346\214\207\345\215\227.md" index b9b6722f48b3cf126aa434dafe05dbb3410cf5e6..1fac462fa7702e886bb6ce5baa975636bb80fc62 100644 --- "a/docs/zh/PyTorch\345\256\211\350\243\205\346\214\207\345\215\227/PyTorch\345\256\211\350\243\205\346\214\207\345\215\227.md" +++ "b/docs/zh/PyTorch\345\256\211\350\243\205\346\214\207\345\215\227/PyTorch\345\256\211\350\243\205\346\214\207\345\215\227.md" @@ -36,7 +36,7 @@ - 需完成CANN开发或运行环境的安装,具体操作请参考《CANN 软件安装指南》。 - 需安装3.12.0以上版本的CMake,安装方法请参考[CMake安装方法](#CMake安装方法md)。 - 需确保已安装7.3.0以上版本的gcc,7.3.0版本gcc具体安装及使用方式请参考[安装7.3.0版本gcc](#安装7-3-0版本gccmd)。 -- 需安装python版本为3.7.5或3.8。 +- 需安装python版本为3.7.5、3.8、3.9。 - 需确保环境中已安装patch、git工具,以Ubuntu和CentOS系统为例,命令如下: - Ubuntu系统 @@ -143,10 +143,12 @@ bash build.sh --python=3.7 或 bash build.sh --python=3.8 + 或 + bash build.sh --python=3.9 ``` - + 请指定环境中python版本进行编译。生成的二进制包在当前的dist目录下,即“pytorch/pytorch/dist”文件夹目录下。 - + 5. 安装PyTorch。 进入“pytorch/pytorch/dist“文件夹目录,执行如下命令安装。 diff --git "a/docs/zh/PyTorch\346\250\241\345\236\213\345\244\232\346\234\272\345\244\232\345\215\241\350\256\255\347\273\203\351\200\202\351\205\215\346\214\207\345\215\227.md" "b/docs/zh/PyTorch\346\250\241\345\236\213\345\244\232\346\234\272\345\244\232\345\215\241\350\256\255\347\273\203\351\200\202\351\205\215\346\214\207\345\215\227.md" new file mode 100644 index 0000000000000000000000000000000000000000..5dd8b21b7560fbb9c144f874879211da5eb38c36 --- /dev/null +++ "b/docs/zh/PyTorch\346\250\241\345\236\213\345\244\232\346\234\272\345\244\232\345\215\241\350\256\255\347\273\203\351\200\202\351\205\215\346\214\207\345\215\227.md" @@ -0,0 +1,922 @@ +# 概述 + +用户可以从Ascend ModelZoo获得PyTorch训练模型,但不支持多机多卡训练,需要根据模型的实际代码进行修改。本文帮助用户快速实现Pytorch模型在多机多卡上使用DDP(Distributed Data Parallel)模式训练。 + +# 训练流程 + +PyTorch模型多机多卡训练流程一般包括准备环境、准备模型、修改模型、启动训练四个部分。 + +1. 准备环境。 + + 准备多机多卡训练的软件、硬件、网络环境,包括开发和运行环境搭建、集群组网链接、芯片IP设置、防火墙设置等。 + +2. 准备模型。 + + 准备PyTorch模型、数据加载器、优化器等训练需要的模块,从[开源社区](https://gitee.com/ascend/modelzoo/tree/master/built-in/PyTorch)获取,也可以自行实现。 + +3. 修改模型。 + + 在基础模型上进行修改,添加DDP需要的代码和环境变量,使模型支持在多机多卡训练。 + +4. 启动训练。 + + 实现在多机多卡环境启动模型训练并查看训练日志。 + + + +# 快速上手 + +## 概述 + +通过示例帮助用户快速了解PyTorch模型是如何在多机多卡上训练的。该示例使用自定义模型实现两台计算机8卡训练。两台计算机分别命名为AI Server0、AI Server1,每台计算机上的8个Ascend 910处理器命名为device 0~7。 + +## 准备环境 + +首先您需要具有至少两台装有Ascend 910处理器的计算机,并保证每台计算机都正确的安装NPU固件和驱动。 + +1. 准备开发和运行环境。 + + 在每台计算机上分别完成开发和运行环境准备。 + + - 完成CANN开发和运行环境的安装,请参见《CANN 软件安装指南》,支持5.0.3以后版本。 + + - 安装适配NPU的PyTorch,安装方法请参见《PyTorch安装指南》。 + +2. 准备组网。 + + 通过交换机或光口直连的方式完成计算设备组网搭建,搭建方法请参见《[数据中心训练场景组网](https://support.huawei.com/enterprise/zh/doc/EDOC1100221993/229cc0e4)》。 + + 该示例中采用两台计算机8卡进行训练,故可以采用光口直连的方式准备组网。 + +3. 配置device IP + + 在AI Server0上配置device IP。 + + ```shell + hccn_tool -i 0 -ip -s address 192.168.100.101 netmask 255.255.255.0 + hccn_tool -i 1 -ip -s address 192.168.101.101 netmask 255.255.255.0 + hccn_tool -i 2 -ip -s address 192.168.102.101 netmask 255.255.255.0 + hccn_tool -i 3 -ip -s address 192.168.103.101 netmask 255.255.255.0 + hccn_tool -i 4 -ip -s address 192.168.100.100 netmask 255.255.255.0 + hccn_tool -i 5 -ip -s address 192.168.101.100 netmask 255.255.255.0 + hccn_tool -i 6 -ip -s address 192.168.102.100 netmask 255.255.255.0 + hccn_tool -i 7 -ip -s address 192.168.103.100 netmask 255.255.255.0 + ``` + + 在AI Server1上配置device IP。 + + ```shell + hccn_tool -i 0 -ip -s address 192.168.100.111 netmask 255.255.255.0 + hccn_tool -i 1 -ip -s address 192.168.101.111 netmask 255.255.255.0 + hccn_tool -i 2 -ip -s address 192.168.102.111 netmask 255.255.255.0 + hccn_tool -i 3 -ip -s address 192.168.103.111 netmask 255.255.255.0 + hccn_tool -i 4 -ip -s address 192.168.100.110 netmask 255.255.255.0 + hccn_tool -i 5 -ip -s address 192.168.101.110 netmask 255.255.255.0 + hccn_tool -i 6 -ip -s address 192.168.102.110 netmask 255.255.255.0 + hccn_tool -i 7 -ip -s address 192.168.103.110 netmask 255.255.255.0 + ``` + +4. 配置防火墙 + + - Ubuntu系统防火墙关闭命令 + + ```shell + ufw disable + + - Redhat或CentOS 7系统防火墙关闭命令 + + ```shell + systemctl stop firewalld + +## 准备模型 + +该示例创建一个简单的模型,供用户快速了解多机多卡训练。用户也可以从[开源社区](https://gitee.com/ascend/modelzoo/tree/master/built-in/PyTorch)获取基于Ascned NPU的PyTorch训练模型。 + +1. DDP模型。 + + 实现一个简单的样例main.py用于多机多卡训练。 + + ```python + import argparse + import os + import torch + import torchvision + import torch.nn as nn + import torch.nn.functional as F + import torch.distributed as dist + from torch.nn.parallel import DistributedDataParallel as DDP + + ### 1.基础模块 ### + # 搭建模型 + class ToyModel(nn.Module): + def __init__(self): + super(ToyModel, self).__init__() + self.conv1 = nn.Conv2d(3, 6, 5) + self.pool = nn.MaxPool2d(2, 2) + self.conv2 = nn.Conv2d(6, 16, 5) + self.fc1 = nn.Linear(16 * 5 * 5, 120) + self.fc2 = nn.Linear(120, 84) + self.fc3 = nn.Linear(84, 10) + + def forward(self, x): + x = self.pool(F.relu(self.conv1(x))) + x = self.pool(F.relu(self.conv2(x))) + x = x.view(-1, 16 * 5 * 5) + x = F.relu(self.fc1(x)) + x = F.relu(self.fc2(x)) + x = self.fc3(x) + return x + + # 获取数据集方法 + def get_dataset(): + transform = torchvision.transforms.Compose([ + torchvision.transforms.ToTensor(), + torchvision.transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)) + ]) + my_trainset = torchvision.datasets.CIFAR10(root='./data', train=True, + download=True, transform=transform) + + train_sampler = torch.utils.data.distributed.DistributedSampler(my_trainset) + trainloader = torch.utils.data.DataLoader(my_trainset, + batch_size=16, num_workers=2, sampler=train_sampler) + return trainloader + + + ### 2. 初始化参数、数据、模型、损失函数、优化器 #### + # 获取local_rank和addr参数 + parser = argparse.ArgumentParser() + parser.add_argument("--local_rank", default=-1, type=int) + parser.add_argument("--addr", default='127.0.0.1', type=str, help='master addr') + + FLAGS = parser.parse_args() + local_rank = FLAGS.local_rank + addr = FLAGS.addr + + # 设置系统的Master地址和端口 + os.environ['MASTER_ADDR'] = addr + os.environ['MASTER_PORT'] = '29501' + + # DDP backend初始化 + loc = 'npu:{}'.format(local_rank) + torch.npu.set_device(loc) + dist.init_process_group(backend='hccl') # hccl是NPU设备上的后端 + + + # 准备数据,要在DDP初始化之后进行 + trainloader = get_dataset() + + # 实例化模型 + model = ToyModel().to(loc) + + # 加载模型权重,在构造DDP模型之前,且只需要在master上加载就行了。 + ckpt_path = None + if dist.get_rank() == 0 and ckpt_path is not None: + model.load_state_dict(torch.load(ckpt_path)) + + # 构造DDP model + model = DDP(model, device_ids=[local_rank], output_device=local_rank) + + # 初始化优化器,在构造DDP model之后,用model初始化optimizer。 + optimizer = torch.optim.SGD(model.parameters(), lr=0.001) + + # 初始化损失函数 + loss_func = nn.CrossEntropyLoss().to(loc) + + ### 3. 网络训练 ### + model.train() + iterator = range(100) + for epoch in iterator: + trainloader.sampler.set_epoch(epoch) + for data, label in trainloader: + data, label = data.to(local_rank), label.to(local_rank) + optimizer.zero_grad() + prediction = model(data) + loss = loss_func(prediction, label) + loss.backward() + print("loss = %0.3f \n" % loss) + optimizer.step() + + # 1. save模型的时候,和DP模式一样,有一个需要注意的点:保存的是model.module而不是model。 + # 因为model其实是DDP model,参数是被`model=DDP(model)`包起来的。 + # 2. 只需要在进程0上保存一次就行了,避免多次保存重复的东西。 + if dist.get_rank() == 0: + torch.save(model.module.state_dict(), "%d.ckpt" % epoch) + ``` + +2. 在单机多卡上运行训练,确保模型正确。 + + 1. 用户自行安装模型脚本需要的Python第三方库。 + + 2. 配置NPU环境变量,env_npu.sh脚本请参见附录。 + + ```shell + source env_npu.sh + ``` + + 3. 使用torch.distributed.launch执行main.py如下命令在单机多卡上训练模型。 + + ```shell + python -m torch.distributed.launch --nproc_per_node 8 main.py + ``` + + `--nproc_per_node` 为训练卡的数量。 + + 运行成功后,模型在该设备的8张NPU上进行训练。 + + + +## 修改模型 + +该快速上手提供的示例,已经对多机多卡训练进行了适配,不需要对脚本进行修改。其他模型的多机多卡适配修改,请参考”多机多卡训练“章节。 + +## 启动训练 + +1. 将main.py模型脚本上传至AI Server0和AI Server1任意路径下。 + +2. 查询服务器的host IP: + + ```shell + hostname -I + ``` + + 打印出所有IP,第一个为IP当前服务器的host IP。 + + 比如:AI Server0服务器的host IP为:192.168.xx.22, AI Server1服务器的host IP为:192.168.xx.23。 + +3. 使用AI Server0为master节点,我们现在拉起2 x 8的集群。 + + 在AI server0服务器上启动命令: + + ```shell + # 设置环境变量,env_npu.sh脚本内容从附录获取 + source env_npu.sh + # 关闭HCCL通道白名单 + export HCCL_WHITELIST_DISABLE=1 + # HCCL初始化通信网卡IP,设置为当前服务器的host IP + export HCCL_IF_IP=192.168.xx.22 + # + python3.7 -m torch.distributed.launch --nnodes=2 --node_rank=0 --nproc_per_node 8 --master_addr 192.168.xx.22 --master_port 29501 main.py --addr 192.168.xx.22 + ``` + + 在AI server1服务器上启动命令: + + ```shell + # 设置环境变量,env_npu.sh脚本内容从附录获取 + source env_npu.sh + # 关闭HCCL通道白名单 + export HCCL_WHITELIST_DISABLE=1 + # HCCL初始化通信网卡IP,设置为当前服务器的host IP + export HCCL_IF_IP=192.168.xx.23 + + python3.7 -m torch.distributed.launch --nnodes=2 --node_rank=1 --nproc_per_node 8 --master_addr 192.168.xx.22 --master_port 29501 main.py --addr 192.168.xx.22 + ``` + + 参数说明。 + + --nnode:指定用来分布式训练脚本的节点数。 + + --node_rank:多节点分布式训练时,指定当前节点的 rank。 + + --nproc_per_node:指定当前节点上,使用GPU训练的进程数。 + + --master_addr:master节点(rank为0)的地址,应该为ip地址或者node 0 的 hostname。 + + --master_port:指定分布式训练中,master 节点使用的端口号。 + + --addr:main.py 脚本的入参,输入master节点的host IP。 + +3. host日志查看 + + host日志保存在`~/ascend/log`路径下,用户可以到该路径下查看每个host的device日志。 + +通过该简单的示例您已经完成了多机多卡模型的训练。 + +# 多机多卡训练 + + + +## 常用概念及参数介绍 + +pytorch分布式训练基本概念 + +| 基本概念 | 说明 | +| ---------- | ------------------------------------------------------------ | +| AI Server | 带有Ascend 910处理器的计算机,多台计算机用AI Server0+序号表示,如AI Server0、AI Server1。 | +| device | AI Server上Ascend 910卡,多卡用device 0、device 1……device 7表示。 | +| host | AI Server主机。 | +| master | 在多台AI Server选取一台作为master,作为数据通信的主机。 | +| group | 即进程组。默认情况下,只有一个组,采用用默认的就行。 | +| world size | 表示全局的进程并行数,可通过torch.distributed.get_world_size()获取, 在不同进程里,该值是一样的。 | +| rank | 表示当前进的序号, 用于进程间通讯。比如是2x8的集群,world size 就是16,rank在每个进程里依次是0,1,2,…,15。 | +| local_rank | 每台机子上的进程的序号。机器一上有0,1,2,3,4,5,6,7,机器二上也有0,1,2,3,4,5,6,7。一般情况下,你需要用这个local_rank来设置当前模型是跑在当前机器的哪块GPU/NPU上面的。 | + +使用torch.distributed.launch启动多卡训练时的参数 + +| 参数名称 | 说明 | +| ------------------ | ------------------------------------------------------------ | +| **nnodes** | 指定用来分布式训练脚本的节点数 | +| **node_rank** | 多节点分布式训练时,指定当前节点的 rank | +| **nproc_per_node** | 指定当前节点上,使用GPU训练的进程数。建议将该参数设置为当前节点的GPU数量,这样每个进程都能单独控制一个GPU,效率最高。 | +| **master_addr** | master节点(rank为0)的地址,应该为ip地址或者node 0 的 hostname。对于单节点多进程训练的情况,该参数可以设置为 127.0.0.1。 | +| **master_port**: | 指定分布式训练中,master 节点使用的端口号,必须与其他应用的端口号不冲突。 | + +## 多机多卡训练流程 + +### 准备环境 + +首先您需要具有至少两台AI Server(装有Ascend 910处理器的计算机),并保证每台计算机已安装正确版本的NPU固件和驱动。 + +1. 准备开发和运行环境。 + + 在每台计算机上分别完成开发和运行环境准备。 + + - 完成CANN开发和运行环境的安装,请参见《CANN 软件安装指南》,支持5.0.3以后版本。 + + - 安装适配NPU的PyTorch,安装方法请参见《PyTorch安装指南》。 + +2. 准备组网。 + + 集群训练由多台装有Ascend 910处理器的计算机完成(最多128台),需要配合交换机组成数据面全连接主备网络,支持8 x n卡训练场景,2台机器可以采用光口直连的方式。搭建方法请参见《[数据中心训练场景组网](https://support.huawei.com/enterprise/zh/doc/EDOC1100221993/229cc0e4)》。 + +3. 配置device IP + + 使用hccn_tool工具配置device IP,hccn_tool工具CANN软件以提供。 + + ```shell + hccn_tool -i 0 -ip -s address 192.168.100.111 netmask 255.255.255.0 + ``` + + 配置device IP需遵守以下规则: + + 1. AI Server中的第0/4,1/5,2/6,3/7号device需处于同一网段,第0/1/2/3号device在不同网段,第4/5/6/7号device在不同网段。 + 2. 对于集群场景,各AI Server对应的位置的device需处于同一网段,AI Server0和AI Server1的0号网卡需处于同一网段、1号网卡需要在同一网段 + 3. 每个IP都不能冲突,相同网段下的IP需在最后8位做区分 + + 使用hccn_tool工具验证device IP是否配置正确。 + + - 查询每个device的ip。 + + ```shell + hccn_tool -i 0 -ip –g + ``` + + 打印查询结果: + + > ipaddr:192.168.100.101 + > + > netmask:255.255.255.0 + + - 使用hccn_tool 确保2机器的卡间连通性,从device0 - devcie7 测试8次,确保所有两机间所有卡都连通。 + + ```shell + hccn_tool -i 0 -netdetect -s address xx.xx.xx.xx + + hccn_tool -i 0 -net_health –g + ``` + + -i:device序号 + + -s address:xx.xx.xx.xx是另外一台机器的device i的IP + + 如果返回`success`则表示已经连通。 + +4. 配置防火墙 + + 在进行HCCL通信的时候可能出现防火墙拦截通信端口导致通信超时,因此在运行pytorch的集群训练的时候需要注意将服务器上的防火墙关闭。 + + - Ubuntu系统防火墙关闭命令 + + ```shell + ufw disable + ``` + + - Redhat或CentOS 7系统防火墙关闭命令 + + ```shell + systemctl stop firewalld + ``` + +### 准备模型 + +准备模型阶段主要有两种方式。 + +- 从[开源社区](https://gitee.com/ascend/modelzoo/tree/master/built-in/PyTorch)下载PyTorch训练模型 + + 从开源社区获取的模型已经支持单机多卡训练,请用户参照“修改模型”小节需要修改的项目,根据具体模型完成相应修改。 + +- 手动搭建PyTorch训练模型 + +1. 准备PyTorch训练模型、数据加载器 + + 准备PyTorch模型。 + + ```python + class ToyModel(nn.Module): + def __init__(self): + ... + def forward(self,x): + ... + ``` + + 准备数据获取方法。 + + ```python + def get_dataset(): + transform = torchvision.transforms.Compose([ + torchvision.transforms.ToTensor(), + torchvision.transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)) + ]) + my_trainset = torchvision.datasets.CIFAR10(root='./data', train=True, + download=True, transform=transform) + + trainloader = torch.utils.data.DataLoader(my_trainset,batch_size=16,) + return trainloader + + trainloader=get_dataset() + ``` + +2. 实例化模型 + + ```python + # 实例化模型 + model = ToyModel().to(loc) + + # 加载模型权重 + if ckpt_path is not None: + model.load_state_dict(torch.load(ckpt_path)) + ``` + +3. 准备损失函数和优化器。 + + ```python + # 初始化优化器,在构造DDP model之后,用model初始化optimizer。 + optimizer = torch.optim.SGD(model.parameters(), lr=0.001) + + # 初始化损失函数 + loss_func = nn.CrossEntropyLoss().to(loc) + ``` + +4. 训练模型 + + ```python + ### 3. 网络训练 ### + model.train() + iterator = range(100) + for epoch in iterator: + for data, label in trainloader: + data, label = data.to(local_rank), label.to(local_rank) + optimizer.zero_grad() + prediction = model(data) + loss = loss_func(prediction, label) + loss.backward() + print("loss = %0.3f \n" % loss) + optimizer.step() + + torch.save(model.state_dict(), "%d.ckpt" % epoch) + ``` + + + +### 修改模型 + +模型修改主要涉及以下6项,包括master ip地址和端口的设置,distributed初始化,模型DDP初始化,数据DDP初始化,优化器初始化,DDP模型训练方法修改。请用户结合初始模型代码,灵活修改。 + +1. 设置master ip地址和端口,在NPU进行分布式训练使用HCCL进行通信,在PyTorch中使用的是自动拓扑探测的HCCL通信机制,即不需要使用RANK_TABLE_FLIE,但是其依赖于host侧的网卡进行通信,因此需要在代码中设置环境变量来设置通信网卡。 + + ```python + os.environ['MASTER_ADDR'] = xxx.xxx.xxx.xxx + os.environ['MASTER_PORT'] = 'xxx' + ``` + + MASTER_ADDR:设置为集群中master的IP(任意挑选一台作为master即可) + + MASTER_PORT:设置为master的一个空闲端口 + + master ip地址和端口在模型代码中一般会设置为传参的形式,也有可能某些开源代码中设置为"127.0.0.1",需要进行修改。 + + 上述变量需在调用torch.distributed.init_process_group()之前声明。 + +2. distributed初始化 + + PyTorch中使用`dist.init_process_group(backend='hccl', world_size=world_size, rank=rank)`来初始化线程组其中参数含义如下。 + + `backend`:进行分布式训练的使用的通信协议,在NPU上只能使用"hccl" + + `world_size`:进行训练时使用的device的总数 + + `rank`: 当前初始化的device的rank_id,也就是全局的逻辑ID + + 有两种方法启动多卡训练,分别初始化的方法如下。 + + - 使用torch.distributed.launch启动多卡训练。 + + ```python + import torch.distributed as dist + + dist.init_process_group(backend='hccl') # hccl是NPU设备上的后端 + ``` + + - 使用mp.spawn启动多卡训练。 + + ```python + import torch.distributed as dist + + def main_worker(pid_idx, device_nums_per_node, args): + args.distributed_rank = args.rank * device_nums_per_node + pid_idx + dist.init_process_group(backend=args.dist_backend, world_size=args.distributed_world_size, rank=args.distributed_rank) + ``` + + 其中: + + `pid_idx`:device序号。 + + `device_nums_per_node`:每个AI Server的device数量。 + +3. 模型DDP初始化 + + ```python + # 实例化模型 + model = ToyModel().to(loc) + + # 加载模型权重,在构造DDP模型之前,且只需要在master上加载。 + if dist.get_rank() == 0 and ckpt_path is not None: + model.load_state_dict(torch.load(ckpt_path)) + + # 构造DDP model + model = DDP(model, device_ids=[local_rank], output_device=local_rank) + ``` + +4. 数据DDP初始化 + + ```python + def get_dataset(): + transform = torchvision.transforms.Compose([ + torchvision.transforms.ToTensor(), + torchvision.transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)) + ]) + my_trainset = torchvision.datasets.CIFAR10(root='./data', train=True, + download=True, transform=transform) + + train_sampler = torch.utils.data.distributed.DistributedSampler(my_trainset) + trainloader = torch.utils.data.DataLoader(my_trainset, + batch_size=16, num_workers=2, sampler=train_sampler) + return trainloader + + trainloader = get_dataset() + ``` + +5. 损失方法、优化器。 + + ```python + # 初始化优化器,在构造DDP model之后,用model初始化optimizer。 + optimizer = torch.optim.SGD(model.parameters(), lr=0.001) + + # 初始化损失函数 + loss_func = nn.CrossEntropyLoss().to(loc) + ``` + +6. DDP模型训练 + + ```python + model.train() + iterator = range(100) + for epoch in iterator: + # 设置epoch + trainloader.sampler.set_epoch(epoch) + + for data, label in trainloader: + data, label = data.to(local_rank), label.to(local_rank) + optimizer.zero_grad() + prediction = model(data) + loss = loss_func(prediction, label) + loss.backward() + print("loss = %0.3f \n" % loss) + optimizer.step() + + # 1. save模型的时候,和DP模式一样,有一个需要注意的点:保存的是model.module而不是model。 + # 因为model其实是DDP model,参数是被`model=DDP(model)`包起来的。 + # 2. 只需要在进程0上保存一次就行了,避免多次保存重复的东西。 + if dist.get_rank() == 0: + torch.save(model.module.state_dict(), "%d.ckpt" % epoch) + ``` + +### 启动训练 + +启动训练提供两种方式,手动启动和shell脚本启动 + +- 手动启动(使用torch.distributed.launch方式启动) + + 1. 配置NPU 环境变量,请参考附录提供的env_npu.sh脚本 + + 2. 添加环境变量,多机训练需要增加`HCCL_WHITELIST_DISABLE`和`HCCL_IF_IP`环境变量。 + + - HCCL_WHITELIST_DISABLE:HCCL通道白名单,一般性设置为1表示关闭白名单。 + - HCCL_IF_IP:HCCL初始化通信网卡IP,设置为当前服务器的host网卡IP。 + + 3. 将修改的模型脚本上传至每个AI Server + + 4. 在每个AI Server上安装必要Python库 + + 5. 任选一个AI Server作为masker节点,并查询每个AI Server的IP。 + + 6. 在每个AI server服务器上启动命令 + + ``` + python3 -m torch.distributed.launch --nnodes=${nnodes} --node_rank=i --nproc_per_node 8 --master_addr 192.168.xx.22 --master_port 29501 main.py --addr 192.168.xx.22 + ``` + + 其中: + + --nnodes:用来分布式训练脚本的AI server数。 + + --node_rank:AI server的序号,每个AI server有对应的序号。 + + --nproc_per_node:每个AI server的device数量。 + + --master_addr:作为maskter节点的AI server IP地址。 + + --master_port: 作为maskter节点的AI server 端口号。 + + main.py:请修改为启动脚本名称。 + + --addr :传入启动脚本的参数,master IP地址。 + +- 使用OpenMPI启动 + + 1. 安装 OpenMPI开源库 + + 多机多卡环境下分布式训练部署依赖于OpenMPI开源库,参与模型训练的每台服务器都需要安装OpenMPI开源库。目前OpenMPI开源库的版本要求为4.0.1、4.0.2或4.0.3。 + 执行`mpirun --version`命令检查是否已安装OpenMPI。如果返回`mpirun (Open MPI) 4.0.2 Report bugs to http://www.open-mpi.org/community/help/` ,说明已经安装。如果已安装,且版本为4.0.1、4.0.2或4.0.3其中一个,则无需再安装。 + + 否则请按照如下步骤安装OpenMPI: + + 1. 访问如下链接下载OpenMPI软件包。例如openmpi-4.0.2.tar.bz2。 + https://www.open-mpi.org/software/ompi/v4.0/ + + 2. 以root用户登录安装环境。 + + 3. 将下载的OpenMPI软件包上传到安装环境的某一目录下。 + + 4. 进入软件包所在目录,执行如下命令解压软件包。 + + ```shell + tar -jxvf openmpi-4.0.2.tar.bz2 + ``` + + 5. 进入解压后的目录,执行如下命令配置、编译和安装。 + + ```shell + ./configure --prefix=/usr/local/mpirun4.0.2 + make + make install + ``` + + 其中“--prefix”参数用于指定OpenMPI安装路径,用户根据实际情况进行修改。 + + 6. 执行vi ~/.bashrc命令,打开.bashrc文件,在文件的最后添加如下环境变量。 + + ```shell + export OPENMPI=/usr/local/mpirun4.0.2 + export LD_LIBRARY_PATH=$OPENMPI/lib + export PATH=$OPENMPI/bin:$PATH + ``` + + 其中“/usr/local/mpirun4.0.2”为OpenMPI安装路径,用户需要根据实际进行修改。 + 执行:wq!命令保存文件并退出。 + + 7. 执行如下命令使环境变量生效。 + + ``` + source ~/.bashrc + ``` + + 8. 安装完成之后,执行如下命令查看安装版本,如果返回正确的版本信息,则说明安装成功。 + + ``` + mpirun --version + ``` + + 2. 配置AI Server SSH免密登录 + + 如果使用OpenMPI在多机多卡环境下分布式训练部署,需要在每两台服务器之间配置SSH免密登录,确保服务器之间可以互通。具体操作步骤如下: + + 1. 以root用户登录每台服务器。 + + 2. 配置集群中主机间的可信度。 + + 打开并编辑**/etc/ssh/ssh_config**文件,在文件最后增加如下字段: + + ``` + StrictHostKeyChecking no + UserKnownHostsFile /dev/null + ``` + + 3. 在每台服务器上分别打开**/etc/hosts**文件,在该文件中添加本服务器对应的IP地址和主机名,且需要添加到该文件的首行。如果文件中已添加,则跳过此步骤。添加内容示例如下: + + ``` + 10.90.140.199 ubuntu + ``` + + 其中10.90.140.199为该服务器的IP地址,ubuntu为主机名。 + + 4. 在第一台服务器执行如下命令生成公钥(例如第一台服务器IP为10.90.140.199)。 + + ``` + cd ~/.ssh/ # 若没有该目录,请先执行一次ssh localhost + ssh-keygen -t rsa # 生成秘钥,会出现提示,连续点击3次"Enter"即可 + mv id_rsa.pub authorized_keys # 将生成的秘钥id_rsa.pub重命名为公钥authorized_keys + ``` + + 5. 在其他每台服务器上都生成秘钥,并复制到第一台服务器的authorized_keys文件中。 + + 1. 在其他每台服务器上执行如下命令生成秘钥。 + + cd ~/.ssh/ + ssh-keygen -t rsa + + 2. 将其他每台服务器上生成的秘钥文件id_rsa.pub下载到本地,并复制该文件中的秘钥。 + + 3. 在第一台服务器内执行如下命令打开公钥文件authorized_keys,将[5.b](#li361025101116 "link to:#li361025101116 + ctrl +click to jump")复制的其他每台服务器的秘钥粘贴到第一台服务器的公钥后面。 + + ``` + vi ~/.ssh/authorized_keys + ``` + + 执行**:wq!**保存该文件。 + + 6. 在其他每台服务器上执行如下命令将第一台服务器制作好的公钥复制到其他每台服务器内。 + + cd ~/.ssh/ + scp root@10.90.140.199:~/.ssh/authorized_keys ./ + + 7. 在每台服务器执行如下命令测试免密登录。 + + ``` + ssh 用户名@IP地址 + ``` + + 例如:在第一台服务器10.90.140.199免密登录服务器10.90.140.231,执行**ssh root@10.90.140.231**命令。 + + 若显示类似如下信息,说明已免密登录服务器10.90.140.231。 + + ``` + Linux ubuntu 4.19.28 #1 SMP Tue Jun 23 19:05:23 EDT 2020 x86_64 + + The programs included with the ubuntu GNU/Linux system are free software; + the exact distribution terms for each program are described in the + individual files in /usr/share/doc/*/copyright. + + ubuntu GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent + permitted by applicable law. + Last login: Tue Sep 15 14:37:21 2020 from 10.254.88.75 + ``` + + 执行**exit**命令可以退出登录,若显示类似如下信息,说明已退出登录。 + + ``` + logout + Connection to 10.90.140.231 closed. + ``` + + 3. 使用OpenMPI拉起模型训练。 + + 1. 分别为每一个AI server编写启动脚本,如train.sh,并将启动脚本分别移到相应AI server的同一路径下。 + + ``` + # 配置NPU环境变量,env_npu.sh脚本参见附录 + source env_npu.sh + #关闭HCCL通道白名单 + export HCCL_WHITELIST_DISABLE=1 + # HCCL初始化通信网卡IP,设置为当前服务器的host IP + export HCCL_IF_IP=xxx.xxx.xx.xxx + python3 -m torch.distributed.launch --nnodes=${nnodes} --node_rank=i --nproc_per_node 8 --master_addr xxx.xxx.xx.xxx --master_port 29501 main.py --addr xxx.xxx.xx.xxx + ``` + + 脚本参数请参见手动启动。 + + 2. 编写启动脚本 + + ``` + # 配置mpirun环境变量 + export PATH=$PATH:/usr/local/mpirun4.0.2/bin + # 执行mpirun工具 + mpirun -H xxx.xxx.xxx.xxx:1,xxx.xxx.xxx.xxx:1 \ + --bind-to none -map-by slot \ + --mca btl_tcp_if_exclude lo,docker0,endvnic\ + --allow-run-as-root \ + --prefix /usr/local/mpirun4.0.2/ \ + ./train.sh + ``` + + 其中 + + -H:每个AI server的IP:启动进程数。 + + --bind-to:绑定进程的策略。 + + --mca:特定上下文的MCA参数,arg0为参数名,arg1为参数值。 + + --allow-run-as-root:允许使用root用户运行。 + + --prefix:mpirun4.0.2路径。 + + ./train.sh:各个AI server的启动脚本路径。 + + 4. + +训练成功后可以查看日志信息。 + +host日志保存在`~/ascend/log`路径下,用户可以到该路径下查看每个host的device日志。 + +# 附录 + +NPU环境变量配置脚本env_npu.sh,可使用该脚本进行运行和开发环境变量的配置。 + +```shell +#!/bin/bash +export install_path=/usr/local/Ascend + +if [ -d ${install_path}/toolkit ]; then + export LD_LIBRARY_PATH=/usr/include/hdf5/lib/:/usr/local/:/usr/local/lib/:/usr/lib/:${install_path}/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons:${path_lib}:${LD_LIBRARY_PATH} + export PATH=${install_path}/fwkacllib/ccec_compiler/bin:${install_path}/fwkacllib/bin:$PATH + export PYTHONPATH=${install_path}/fwkacllib/python/site-packages:${install_path}/tfplugin/python/site-packages:${install_path}/toolkit/python/site-packages:$PYTHONPATH + export PYTHONPATH=/usr/local/python3.7.5/lib/python3.7/site-packages:$PYTHONPATH + export ASCEND_OPP_PATH=${install_path}/opp +else + if [ -d ${install_path}/nnae/latest ];then +exportLD_LIBRARY_PATH=/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:${install_path}/nnae/latest/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64_64-linux-gnu:$LD_LIBRARY_PATH + export PATH=$PATH:${install_path}/nnae/latest/fwkacllib/ccec_compiler/bin/:${install_path}/nnae/latest/toolkit/tools/ide_daemon/bin/ + export ASCEND_OPP_PATH=${install_path}/nnae/latest/opp/ + export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so + export PYTHONPATH=${install_path}/nnae/latest/fwkacllib/python/site-packages/:${install_path}/nnae/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:${install_path}/nnae/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH + export ASCEND_AICPU_PATH=${install_path}/nnae/latest + else + export LD_LIBRARY_PATH=/usr/local/:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64-linux-gnu:$LD_LIBRARY_PATH + export PATH=$PATH:${install_path}/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin/:${install_path}/ascend-toolkit/latest/toolkit/tools/ide_daemon/bin/ + export ASCEND_OPP_PATH=${install_path}/ascend-toolkit/latest/opp/ + export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so + export PYTHONPATH=${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/:${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH + export ASCEND_AICPU_PATH=${install_path}/ascend-toolkit/latest + fi +fi + +#将Host日志输出到串口,0-关闭/1-开启 +export ASCEND_SLOG_PRINT_TO_STDOUT=0 +#设置默认日志级别,0-debug/1-info/2-warning/3-error +export ASCEND_GLOBAL_LOG_LEVEL=3 +#设置Event日志开启标志,0-关闭/1-开启 +export ASCEND_GLOBAL_EVENT_ENABLE=0 +#设置是否开启taskque,0-关闭/1-开启 +export TASK_QUEUE_ENABLE=1 +#HCCL白名单开关,1-关闭/0-开启 +export HCCL_WHITELIST_DISABLE=1 + +#设置device侧日志登记为error +${install_path}/driver/tools/msnpureport -g error -d 0 +${install_path}/driver/tools/msnpureport -g error -d 1 +${install_path}/driver/tools/msnpureport -g error -d 2 +${install_path}/driver/tools/msnpureport -g error -d 3 +${install_path}/driver/tools/msnpureport -g error -d 4 +${install_path}/driver/tools/msnpureport -g error -d 5 +${install_path}/driver/tools/msnpureport -g error -d 6 +${install_path}/driver/tools/msnpureport -g error -d 7 +#关闭Device侧Event日志 +${install_path}/driver/tools/msnpureport -e disable + +path_lib=$(python3.7 -c """ +import sys +import re +result='' +for index in range(len(sys.path)): + match_sit = re.search('-packages', sys.path[index]) + if match_sit is not None: + match_lib = re.search('lib', sys.path[index]) + + if match_lib is not None: + end=match_lib.span()[1] + result += sys.path[index][0:end] + ':' + + result+=sys.path[index] + '/torch/lib:' +print(result)""" +) + +echo ${path_lib} + +export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib/:${path_lib}:$LD_LIBRARY_PATH +``` + + + + + + + + + + + + + + + diff --git "a/docs/zh/PyTorch\347\275\221\347\273\234\346\250\241\345\236\213\347\247\273\346\244\215&\350\256\255\347\273\203\346\214\207\345\215\227/PyTorch\347\275\221\347\273\234\346\250\241\345\236\213\347\247\273\346\244\215&\350\256\255\347\273\203\346\214\207\345\215\227.md" "b/docs/zh/PyTorch\347\275\221\347\273\234\346\250\241\345\236\213\347\247\273\346\244\215&\350\256\255\347\273\203\346\214\207\345\215\227/PyTorch\347\275\221\347\273\234\346\250\241\345\236\213\347\247\273\346\244\215&\350\256\255\347\273\203\346\214\207\345\215\227.md" index 73bc72831196654aa71ae22341ed6d63d50f3f9e..bd5c1d664dfa0c6c6321bf95c1044a048df8d198 100644 --- "a/docs/zh/PyTorch\347\275\221\347\273\234\346\250\241\345\236\213\347\247\273\346\244\215&\350\256\255\347\273\203\346\214\207\345\215\227/PyTorch\347\275\221\347\273\234\346\250\241\345\236\213\347\247\273\346\244\215&\350\256\255\347\273\203\346\214\207\345\215\227.md" +++ "b/docs/zh/PyTorch\347\275\221\347\273\234\346\250\241\345\236\213\347\247\273\346\244\215&\350\256\255\347\273\203\346\214\207\345\215\227/PyTorch\347\275\221\347\273\234\346\250\241\345\236\213\347\247\273\346\244\215&\350\256\255\347\273\203\346\214\207\345\215\227.md" @@ -1,8 +1,11 @@ + + # PyTorch网络模型移植&训练指南 - [概述](#概述md) - [约束与限制](#约束与限制md) - [迁移流程](#迁移流程md) +- [快速上手](#快速上手) - [模型移植评估](#模型移植评估md) - [环境准备](#环境准备md) - [模型迁移](#模型迁移md) @@ -73,7 +76,7 @@

模型选取

-

详情请参见模型选取

+

选取需要迁移的模型。

模型移植评估

@@ -134,2435 +137,2489 @@ -

模型移植评估

+## 快速上手 -1. 在选取模型时,尽可能选取权威Pytorch模型实现仓作为标杆,包括但不限于Pytorch\([example](https://github.com/pytorch/examples/tree/master/imagenet)/[vision](https://github.com/pytorch/vision)等\)、facebookresearch\([Detectron](https://github.com/facebookresearch/Detectron)/[detectron2](https://github.com/facebookresearch/detectron2)等\)和open-mmlab\([mmdetection](https://github.com/open-mmlab/mmdetection)/[mmpose](https://github.com/open-mmlab/mmpose)等\)。 -2. 查看算子适配情况。将原始模型及训练脚本迁移到昇腾AI处理器上之前,可以将原始模型及训练脚本在CPU上进行训练,使用dump op方法获取算子信息,与《PyTorch适配算子清单》算子进行比较,查看是否支持。dump op方法参见[dump op方法](#dump-op方法md),当有不支持算子时参见《PyTorch算子开发指南》进行算子开发。 +### 简介 - >![](public_sys-resources/icon-note.gif) **说明:** - >查看算子适配情况也可以先将模型及训练脚本迁移到昇腾AI处理器(迁移方法参见下文)进行训练来查看报错信息。一般会提示不能在昇腾AI处理器的backend下运行某个算子(第一个不支持的算子)。 +对ResNet50模型进行迁移,帮助用户快速了解迁移过程。 +### 模型选取 -

环境准备

+本样例基于PyTorch官网提供的Imagenet数据集训练模型[main.py](https://github.com/pytorch/examples/tree/master/imagenet/main.py)脚本进行适配昇腾910 AI处理器的迁移。 -请参见《PyTorch安装指南》进行PyTorch及混合精度模块安装,并配置环境变量。 +### 模型移植评估 -

模型迁移

+模型是否可以迁移成功主要取决于模型算子是否支持昇腾AI处理器。故需要对模型算子对昇腾AI处理器的支持性进行评估,一般有两种方式评估算子支持性 +- 模型迁移前,使用dump op方法获取算子信息,与《PyTorch适配算子清单》算子进行比较,确定是否支持。 +- 模型迁移后,在昇腾设备上进行运行训练脚本,若存在不支持昇腾AI设备的算子,会提示报错信息。 -

工具迁移

+若存在不支持算子,可以采用修该模型用等价支持的算子替换或者参考《PyTorch算子开发指南》进行算子开发。 -Ascend平台提供了脚本转换工具使用户能通过命令行方式将训练脚本迁移到昇腾AI处理器上进行训练,命令行方式工具详细使用说明参见下文。除命令行方式外,用户也可通过MindStudio中集成的PyTorch GPU2Ascend功能进行迁移,详情请参见《MindStudio 用户指南》。 +ResNet50模型用到的算子已经在昇腾AI处理器上支持。 -

功能介绍

+### 环境准备 -**简介** +请参见《PyTorch安装指南》进行CANN软件安装、PyTorch框架及混合精度模块安装,并配置环境变量。 -昇腾NPU是AI算力的后起之秀,但目前训练和在线推理脚本大多是基于GPU的。由于NPU与GPU的架构差异,基于GPU的训练和在线推理脚本不能直接在NPU上使用,脚本转换工具提供了将基于GPU的脚本转换为基于NPU的脚本的自动化方法,节省了人工手动进行脚本迁移的学习成本与工作量,大幅提升了迁移效率。 +参考PyTorch [examples](https://github.com/pytorch/examples/tree/master/imagenet) 准备模型运行所需要的Python环境及依赖。 ->![](public_sys-resources/icon-note.gif) **说明:** ->- 脚本转换工具根据适配规则,对用户脚本给出修改建议并提供转换功能,大幅度提高了脚本迁移速度,降低了开发者的工作量。除使用[表1](#zh-cn_topic_0000001133095885_table4705239194613)里的脚本转换成功后可直接运行外,其他脚本的转换结果仅供参考,仍需用户根据实际情况做少量适配。 ->- [表1](#zh-cn_topic_0000001133095885_table4705239194613)里的原脚本需要在GPU环境下且基于python3能够跑通。 ->- [表1](#zh-cn_topic_0000001133095885_table4705239194613)里的脚本转换后的执行逻辑与转换前保持一致。 ->- 此脚本转换工具当前仅支持PyTorch训练脚本转换。 +### 模型迁移 -**表 1** 模型支持列表 +在main.py训练脚本的基础上进行修改,实现模型的单卡训练和单机多卡训练迁移。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

序号

-

模型名称

-

1

-

3D AttentionNet

-

2

-

3D Nested_UNet

-

3

-

Advanced East

-

4

-

AlexNet

-

5

-

DeeplabV3+(Xception-JFT)

-

6

-

DeepMar

-

7

-

Densenet121

-

8

-

DenseNet161

-

9

-

DenseNet169

-

10

-

DenseNet201

-

11

-

EAST

-

12

-

FCN

-

13

-

FD-GAN

-

14

-

FOTS

-

15

-

GENet

-

16

-

GoogleNet

-

17

-

GRU

-

18

-

Inception V4

-

19

-

InceptionV2

-

20

-

LPRNet

-

21

-

LSTM

-

22

-

MNASNet0_5

-

23

-

MNASNet0_75

-

24

-

MNASNet1_0

-

25

-

MNASNet1_3

-

26

-

MobileNetV1

-

27

-

MobileNetV2

-

28

-

PNet

-

29

-

PSENet

-

30

-

RAFT

-

31

-

RecVAE

-

32

-

ResNet101

-

33

-

ResNet152

-

34

-

ResNet18

-

35

-

ResNet34

-

36

-

ResNet50

-

37

-

Resnext101_32x8d

-

38

-

Resnext50

-

39

-

RNet

-

40

-

Shufflenetv2

-

41

-

SqueezeNet1_0

-

42

-

SqueezeNet1_1

-

43

-

U-Net

-

44

-

VAE+GAN

-

45

-

VGG11

-

46

-

VGG11_BN

-

47

-

VGG13

-

48

-

VGG13_BN

-

49

-

VGG16

-

50

-

VGG16_BN

-

51

-

VGG19

-

52

-

VGG19_BN

-

53

-

VIT-base

-

54

-

Wide_ResNet101_2

-

55

-

Wide_ResNet50_2

-
-**系统要求** - -脚本转换工具支持Ubuntu 18.04、CentOS 7.6或EulerOS 2.8。 +#### 单卡训练迁移 -**环境准备** +1. 在main.py脚本中导入torch.npu模块。 -详情请参考《CANN 软件安装指南》安装开发环境。 + ```python + import torch.npu + ``` -

操作指南

+2. 在main.py中定义训练设备。 -**参数说明** + ```python + CALCULATE_DEVICE = "npu:0" + ``` -**表 1** 参数说明 +3. 修改参数以及判断选项,使其只在昇腾910 AI处理器上进行训练。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值示例

-

-i

-

--input

-
  • 要进行转换的原始脚本文件所在文件夹路径或文件路径。
  • 必选。
-
  • /home/username/fmktransplt
  • /home/username/fmktransplt.py
-

-o

-

--output

-
  • 脚本转换结果文件输出路径。会在该路径下输出带有msft后缀的文件夹。
  • 必选。
-

/home/username/fmktransplt_output

-

-r

-

--rule

-
  • 用户自定义通用转换规则的json文件路径,主要分为:函数参数修改、函数名称修改和模块名称修改三部分。
  • 可选。
-

/home/username/fmktransplt_rule.json

-

-s

-

--specify-device

-
  • 可以通过环境变量设置指定device作为高级特性,但有可能导致原本脚本中分布式功能失效。
  • 可选。
-

-

-

-sim

-

--similar

-
  • 用功能相似的API替换某些不支持的API,但有可能导致准确性和性能下降。
  • 可选。
-

-

-

distributed

-

将GPU单卡脚本转换为NPU多卡脚本,仅支持使用torch.utils.data.DataLoader方式加载数据的场景,指定此参数时,才可以指定以下两个参数。

-
  • -m,--main:训练脚本的入口python文件,必选。
  • -t,--target model:目标模型变量名,默认为'model',可选。
-

-

-

-h

-

--help

-

显示帮助信息。

-

-

-
-**自定义规则文件** + 代码位置:main.py文件中的main\_worker\(\)函数: -自定义转换规则样例如下: + ```python + def main_worker(gpu, ngpus_per_node, args): + global best_acc1 + # 原代码为使用GPU进行训练,原代码如下: + # args.gpu = gpu + ############## npu modify begin ############# + args.gpu = None + ############## npu modify end ############# + + if args.gpu is not None: + print("Use GPU: {} for training".format(args.gpu)) + + if args.distributed: + if args.dist_url == "env://" and args.rank == -1: + args.rank = int(os.environ["RANK"]) + if args.multiprocessing_distributed: + # For multiprocessing distributed training, rank needs to be the + # global rank among all the processes + args.rank = args.rank * ngpus_per_node + gpu + dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + # create model + if args.pretrained: + print("=> using pre-trained model '{}'".format(args.arch)) + model = models.__dict__[args.arch](pretrained=True) + else: + print("=> creating model '{}'".format(args.arch)) + model = models.__dict__[args.arch]() + # 原代码中需要判断是否在GPU上进行训练,原代码如下: + # if not torch.cuda.is_available(): + # print('using CPU, this will be slow') + # elif args.distributed: + ############## npu modify begin ############# + # 迁移后为直接判断是否进行分布式训练,去掉判断是否在GPU上进行训练 + if args.distributed: + ############## npu modify end ############# + # For multiprocessing distributed, DistributedDataParallel constructor + # should always set the single device scope, otherwise, + # DistributedDataParallel will use all available devices. + if args.gpu is not None: + ...... + ``` -``` -{ - "rules": { - "ArgsModifyRule": [ - { - "func_name": "name1", - "arg_idx": 0, - "arg_new": "agrs0" - }, - { - "func_name": "name2", - "arg_idx": 0, - "arg_new": "agrs0" - } - ], - "FuncNameModifyRule": [ - { - "old_name": "func", - "new_name": "new_func" - } - ], - "ModuleNameModifyRule": [ - { - "old_name": "module", - "new_name": "new_module", - "parent_module":"parent_module" - } - ] - } -} -``` +4. 将模型以及损失函数迁移到昇腾910 AI处理器上进行计算。 + + 代码位置:main.py文件中的main\_worker\(\)函数: + + ```python + elif args.gpu is not None: + torch.cuda.set_device(args.gpu) + model = model.cuda(args.gpu) + else: + # DataParallel will divide and allocate batch_size to all available GPUs + if args.arch.startswith('alexnet') or args.arch.startswith('vgg'): + model.features = torch.nn.DataParallel(model.features) + model.cuda() + else: + # 原代码使用torch.nn.DataParallel()类来用多个GPU加速训练 + # model = torch.nn.DataParallel(model).cuda() + ############## npu modify begin ############# + # 将模型迁移到NPU上进行训练。 + model = model.to(CALCULATE_DEVICE) + ############## npu modify end ############# + # 原代码中损失函数是在GPU上进行计算 + # # define loss function (criterion) and optimizer + # criterion = nn.CrossEntropyLoss().cuda(args.gpu) + ############## npu modify begin ############# + # 将损失函数迁移到NPU上进行计算。 + criterion = nn.CrossEntropyLoss().to(CALCULATE_DEVICE) + ############## npu modify end ############# + ``` -**表 2** 参数说明 +5. 将数据集目标结果target修改成int32类型解决算子报错问题;将数据集迁移到昇腾910 AI处理器上进行计算。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

说明

-

ArgsModifyRule

-

函数参数修改

-

func_name

-

函数名称

-

arg_idx

-

参数的位置

-

arg_new

-

新的参数

-

FuncNameModifyRule

-

函数名称修改

-

ModuleNameModifyRule

-

模块名称修改

-

old_name

-

旧名称

-

new_name

-

新名称

-

parent_module

-

父级模块全名

-

例如torch.cuda.amp,amp的父级模块全名为torch.cuda。

-
-**执行转换** + - 代码位置:main.py文件中的train\(\)函数: -1. 进入脚本转换工具所在路径。 + ```python + for i, (images, target) in enumerate(train_loader): + # measure data loading time + data_time.update(time.time() - end) + + if args.gpu is not None: + images = images.cuda(args.gpu, non_blocking=True) + # 原代码中训练数据集在GPU上进行加载计算,原代码如下: + # if torch.cuda.is_available(): + # target = target.cuda(args.gpu, non_blocking=True) + ############## npu modify begin ############# + # 将数据集迁移到NPU上进行计算并修改target数据类型,以提升性能 + if 'npu' in CALCULATE_DEVICE: + target = target.to(torch.int32) + images, target = images.to(CALCULATE_DEVICE, non_blocking=True), target.to(CALCULATE_DEVICE, non_blocking=True) + ############## npu modify end ############# + ``` - ``` - cd Ascend-cann-toolkit安装目录/ascend-toolkit/{version}/{arch}-linux/toolkit/tools/ms_fmk_transplt - ``` + - 代码位置:main.py文件中的validate\(\)函数: + + ```python + with torch.no_grad(): + end = time.time() + for i, (images, target) in enumerate(val_loader): + if args.gpu is not None: + images = images.cuda(args.gpu, non_blocking=True) + # 原代码中训练数据集在GPU上进行加载计算,原代码如下: + # if torch.cuda.is_available(): + # target = target.cuda(args.gpu, non_blocking=True) + ############## npu modify begin ############# + # 将数据集迁移到NPU上进行计算并修改target数据类型 + if 'npu' in CALCULATE_DEVICE: + target = target.to(torch.int32) + images, target = images.to(CALCULATE_DEVICE, non_blocking=True), target.to(CALCULATE_DEVICE, non_blocking=True) + ############## npu modify end ############# + ``` -2. 执行脚本转换工具。 +6. 设置当前正在使用的device。 - ``` - python3 ms_fmk_transplt.py -i 原始脚本路径 -o 脚本转换结果输出路径 [-r 自定义规则json文件路径] [-s] [-sim] [distributed -m 训练脚本的入口文件 -t 目标模型变量名] - ``` + 代码位置:main.py文件中的主函数入口: - >![](public_sys-resources/icon-note.gif) **说明:** - >distributed及其参数-m、-t在语句最后指定。 + ```python + if __name__ == '__main__': + ############## npu modify begin ############# + if 'npu' in CALCULATE_DEVICE: + torch.npu.set_device(CALCULATE_DEVICE) + ############## npu modify begin ############# + main() + ``` -3. 完成脚本转换。 +#### 单机多卡训练修改 -

结果解析

+1. main.py增加头文件以支持基于PyTorch框架的模型在昇腾910 AI处理器上训练及进行混合精度训练。 -脚本转换完成后,进入脚本转换结果输出路径查看结果文件,以GPU单卡脚本转换为NPU多卡脚本为例。 + ```python + import torch.npu + from apex import amp + ``` -``` -├── xxx_msft // 脚本转换结果输出目录,默认为原始脚本路径。xxx为原始脚本所在文件夹名称。 -│ ├── 生成脚本文件 // 与转换前的脚本文件目录结构一致。 -│ ├── msFmkTranspltlog.txt // 脚本转换过程日志文件。 -│ ├── unsupported_op.xlsx // 不支持算子列表文件。 -│ ├── change_list.csv // 修改记录文件。 -│ ├── run_distributed_npu.sh // 多卡启动shell脚本。 -``` +2. 参数设置增加以下参数,包括指定参与训练的昇腾910 AI处理器以及进行混合精度训练需要的参数。 -

手工迁移

+ ```python + parser.add_argument('--device', default='npu', type=str, help='npu or gpu') + parser.add_argument('--addr', default='10.136.181.115', type=str, help='master addr') + parser.add_argument('--device-list', default='0,1,2,3,4,5,6,7', type=str, help='device id list') + parser.add_argument('--amp', default=False, action='store_true', help='use amp to train the model') + parser.add_argument('--loss-scale', default=1024., type=float, + help='loss scale using in amp, default -1 means dynamic') + parser.add_argument('--opt-level', default='O2', type=str, + help='loss scale using in amp, default -1 means dynamic') + ``` +3. 创建由device\_id到process\_id的映射函数,指定device进行训练。在main.py函数中增加以下接口。 -

单P训练模型迁移

- -当前在线对接方案优点在于保证在昇腾AI处理器上训练与GPU的使用方式和风格保持一致。用户在使用在线对接方案时,**只需在Python侧和Device相关操作中,指定device为昇腾AI处理器**,即可完成用昇腾AI处理器在PyTorch对网络的开发、训练以及调试。针对单P模型训练,主要迁移改动如下。 - -迁移前GPU代码: + ```python + def device_id_to_process_device_map(device_list): + devices = device_list.split(",") + devices = [int(x) for x in devices] + devices.sort() + + process_device_map = dict() + for process_id, device_id in enumerate(devices): + process_device_map[process_id] = device_id + + return process_device_map + ``` -``` - CALCULATE_DEVICE = “gpu:0” - torch.cuda.set_device(CALCULATE_DEVICE) - # 放到device的两种方法 - model = model.cuda() # 写法1 - model = model.to(CALCULATE_DEVICE) # 写法2 - # 将输入也从host放到device - images = images.to(CALCULATE_DEVICE) - target = target.to(CALCULATE_DEVICE) -``` +4. 指定训练服务器的ip和端口。 -迁移到昇腾AI处理器上代码为: + 代码位置:main.py文件中的主函数main\(\)(修改部分为字体加粗部分)。 -``` - CALCULATE_DEVICE = “npu:0” - torch.npu.set_device(CALCULATE_DEVICE) - # 放到device的两种方法 - model = model.npu() # 写法1 - model = model.to(CALCULATE_DEVICE) # 写法2 - # 将输入也从host放到device - images = images.to(CALCULATE_DEVICE) - target = target.to(CALCULATE_DEVICE) -``` + ```python + def main(): + args = parser.parse_args() + ############## npu modify begin ############# + os.environ['MASTER_ADDR'] = args.addr + os.environ['MASTER_PORT'] = '29688' + ############## npu modify end ############# + ``` -更多迁移细节请参见[单P训练修改](#单P训练修改md)。 +5. 创建由device\_id到process\_id的映射参数,获取单节点昇腾910 AI处理器数量。 -

多P训练模型迁移

+ 代码位置:main.py文件中的主函数main\(\)。 -多P训练模型迁移除了需在**Python侧和Device相关操作中,指定device为昇腾AI处理器**外,依然通过PyTorch的DistributedDataParallel方式来进行分布式训练,即在模型初始化阶段执行init\_process\_group,再将模型初始化为DistributedDataParallel模型。但须注意的是在初始化init\_process\_group时需要将**backend**配置为**hccl**并屏蔽掉初始化方式。 + ```python + args.distributed = args.world_size > 1 or args.multiprocessing_distributed + ############## npu modify begin ############# + args.process_device_map = device_id_to_process_device_map(args.device_list) + if args.device == 'npu': + ngpus_per_node = len(args.process_device_map) + else: + ngpus_per_node = torch.cuda.device_count() + ############## npu modify end ############# + # 原代码如下: + # ngpus_per_node = torch.cuda.device_count() + ``` -PyTorch分布式训练代码示例(部分代码省略): +6. 获取进程process\_id对应的昇腾910 AI处理器编号,指定在对应的昇腾910 AI处理器上进行训练。 -``` -import torch -import torch.distributed as dist -import torch.nn.parallel -def main(): - args = parser.parse_args() - # 需屏蔽掉初始化方式 - dist.init_process_group(backend='hccl',# init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu]) # model需要下发到npu上 - train_loader = torch.utils.data.DataLoader( - train_dataset, batch_size=args.batch_size, shuffle=(train_sampler is None), - num_workers=args.workers, pin_memory=True, sampler=train_sampler) - for epoch in range(args.start_epoch, args.epochs): - acc1 = train(train_loader, model, criterion, optimizer, epoch, args,ngpus_per_node, - lr_scheduler) -``` + 代码位置:main.py文件中的main\_worker\(\)。 -更多迁移细节请参见[分布式训练修改](#分布式训练修改md)。 + ```python + def main_worker(gpu, ngpus_per_node, args): + global best_acc1 + ############## npu modify begin ############# + args.gpu = args.process_device_map[gpu] + ############## npu modify end ############# + # 原代码如下: + # args.gpu = gpu + ``` -

PyTorch接口替换

+7. 初始化进程组,屏蔽掉初始化方式。 -1. 为了使昇腾AI处理器使用PyTorch框架的能力,需要对原生的PyTorch框架进行一定Device层面的适配,对外呈现是需要将跟cpu和cuda相关的接口进行切换;在进行网络迁移时,需要将某些设备相关的接口转换成跟昇腾AI处理器相关的接口,当前适配的设备相关接口请参见[表1](#table1922064517344): + 代码位置:main.py文件中的main\_worker\(\)。 - **表 1** 设备接口替换 + ```python + ############## npu modify begin ############# + if args.device == 'npu': + dist.init_process_group(backend=args.dist_backend, #init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + else: + dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + ############## npu modify begin ############# + # 原代码如下: + # dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, + # world_size=args.world_size, rank=args.rank) + ``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

PyTorch原始接口

-

适配昇腾AI处理器后的接口

-

说明

-

torch.cuda.is_available()

-

torch.npu.is_available()

-

判断当前环境上设备是否可用(不代表最后结果)。

-

torch.cuda.current_device()

-

torch.npu.current_device()

-

获取当前正在使用的device。

-

torch.cuda.device_count()

-

torch.npu.device_count()

-

获取当前环境上的设备数量。

-

torch.cuda.set_device()

-

torch.npu.set_device()

-

设置当前正在使用的device。

-

torch.tensor([1,2,3]).is_cuda

-

torch.tensor([1,2,3]).is_npu

-

判断某个tensor是否是cuda/npu设备上的格式。

-

torch.tensor([1,2,3]).cuda()

-

torch.tensor([1,2,3]).npu()

-

将某个tensor转换成cuda/npu格式。

-

torch.tensor([1,2,3]).to("cuda")

-

torch.tensor([1,2,3]).to('npu')

-

将某个tensor转换成cuda/npu格式。

-

torch.cuda.synchronize()

-

torch.npu.synchronize()

-

同步等待事件完成。

-

torch.cuda.device

-

torch.npu.device

-

生成一个device类,可以执行device相关操作。

-

torch.cuda.Stream(device)

-

torch.npu.Stream(device)

-

生成一个stream对象。

-

torch.cuda.stream(Stream)

-

torch.npu.stream(Stream)

-

多用于作用域限定。

-

torch.cuda.current_stream()

-

torch.npu.current_stream()

-

获取当前stream。

-

torch.cuda.default_stream()

-

torch.npu.default_stream()

-

获取默认stream。

-

device = torch.device("cuda:0")

-

device = torch.device("npu:0")

-

指定一个设备。

-

torch.autograd.profiler.profile

-

(use_cuda=True)

-

torch.autograd.profiler.profile

-

(use_npu=True)

-

指定执行profiler过程中使用cuda/npu。

-

torch.cuda.Event()

-

torch.npu.Event()

-

返回某个设备上的事件。

-
+8. 要进行分布式训练且需要引入混合精度模块,并且需要将模型迁移到昇腾AI处理器上,因此需要屏蔽掉原始代码中判断是否为分布式训练以及模型是否在GPU上进行训练的代码部分。 -2. 用户在构建网络或进行网络迁移时,需要创建指定数据类型的tensor,在昇腾AI处理器上创建的tensor如下。 + 代码位置:main.py文件中的main\_worker\(\)。 - **表 2** tensor创建接口替换 + ```python + # create model + if args.pretrained: + print("=> using pre-trained model '{}'".format(args.arch)) + model = models.__dict__[args.arch](pretrained=True) + else: + print("=> creating model '{}'".format(args.arch)) + model = models.__dict__[args.arch]() + ############## npu modify begin ############# + # 代码中添加如下内容 + # 指定训练设备为昇腾AI处理器 + loc = 'npu:{}'.format(args.gpu) + torch.npu.set_device(loc) + # 计算用于训练的batch_size和workers + args.batch_size = int(args.batch_size / ngpus_per_node) + args.workers = int((args.workers + ngpus_per_node - 1) / ngpus_per_node) + ############## npu modify end ############# + # 原始代码如下,需屏蔽掉,已注释 + # if not torch.cuda.is_available(): + # print('using CPU, this will be slow') + # elif args.distributed: + # # For multiprocessing distributed, DistributedDataParallel constructor + # # should always set the single device scope, otherwise, + # # DistributedDataParallel will use all available devices. + # if args.gpu is not None: + # torch.cuda.set_device(args.gpu) + # model.cuda(args.gpu) + # # When using a single GPU per process and per + # # DistributedDataParallel, we need to divide the batch size + # # ourselves based on the total number of GPUs we have + # args.batch_size = int(args.batch_size / ngpus_per_node) + # args.workers = int((args.workers + ngpus_per_node - 1) / ngpus_per_node) + # model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu]) + # else: + # model.cuda() + # # DistributedDataParallel will divide and allocate batch_size to all + # # available GPUs if device_ids are not set + # model = torch.nn.parallel.DistributedDataParallel(model) + # elif args.gpu is not None: + # torch.cuda.set_device(args.gpu) + # model = model.cuda(args.gpu) + # else: + # # DataParallel will divide and allocate batch_size to all available GPUs + # if args.arch.startswith('alexnet') or args.arch.startswith('vgg'): + # model.features = torch.nn.DataParallel(model.features) + # model.cuda() + # else: + # model = torch.nn.DataParallel(model).cuda() + ``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

GPU tensor

-

适配昇腾AI处理器后的接口

-

torch.tensor([1,2,3],dtype=torch.long,device='cuda')

-

torch.tensor([1,2,3],dtype=torch.long,device='npu')

-

torch.tensor([1,2,3],dtype=torch.int,device='cuda')

-

torch.tensor([1,2,3],dtype=torch.int,device='npu')

-

torch.tensor([1,2,3],dtype=torch.half,device='cuda')

-

torch.tensor([1,2,3],dtype=torch.half,device='npu')

-

torch.tensor([1,2,3],dtype=torch.float,device='cuda')

-

torch.tensor([1,2,3],dtype=torch.float,device='npu')

-

torch.tensor([1,2,3],dtype=torch.bool,device='cuda')

-

torch.tensor([1,2,3],dtype=torch.bool,device='npu')

-

torch.cuda.BoolTensor([1,2,3])

-

torch.npu.BoolTensor([1,2,3])

-

torch.cuda.FloatTensor([1,2,3])

-

torch.npu.FloatTensor([1,2,3])

-

torch.cuda.IntTensor([1,2,3])

-

torch.npu.IntTensor([1,2,3])

-

torch.cuda.LongTensor([1,2,3])

-

torch.npu.LongTensor([1,2,3])

-

torch.cuda.HalfTensor([1,2,3])

-

torch.npu.HalfTensor([1,2,3])

-
+9. 屏蔽掉损失函数、优化器和断点训练部分,将这部分在后面与混合精度训练结合起来。 + 代码位置:main.py文件中的main\_worker\(\)。 -更多接口请参见《PyTorch API支持清单》。 + ```python + # 屏蔽掉原始代码,已注释 + # # define loss function (criterion) and optimizer + # criterion = nn.CrossEntropyLoss().cuda(args.gpu) + # + # optimizer = torch.optim.SGD(model.parameters(), args.lr, + # momentum=args.momentum, + # weight_decay=args.weight_decay) + # + # # optionally resume from a checkpoint + # if args.resume: + # if os.path.isfile(args.resume): + # print("=> loading checkpoint '{}'".format(args.resume)) + # if args.gpu is None: + # checkpoint = torch.load(args.resume) + # else: + # # Map model to be loaded to specified single gpu. + # loc = 'cuda:{}'.format(args.gpu) + # checkpoint = torch.load(args.resume, map_location=loc) + # args.start_epoch = checkpoint['epoch'] + # best_acc1 = checkpoint['best_acc1'] + # if args.gpu is not None: + # # best_acc1 may be from a checkpoint from a different GPU + # best_acc1 = best_acc1.to(args.gpu) + # model.load_state_dict(checkpoint['state_dict']) + # optimizer.load_state_dict(checkpoint['optimizer']) + # print("=> loaded checkpoint '{}' (epoch {})" + # .format(args.resume, checkpoint['epoch'])) + # else: + # print("=> no checkpoint found at '{}'".format(args.resume)) + # + # cudnn.benchmark = True + ``` -

混合精度

+10. 数据加载器,结合了数据集和取样器,并且可以提供多个线程处理数据集。使用昇腾AI处理器进行训练,需要将**pin\_memory**设置为**False**;由于当前仅支持固定shape下的训练,数据流中剩余的样本数可能小于batch大小,因此需要将**drop\_last**设置为**True**;另外需要将验证部分数据集**shuffle**设置为**True**。 -**概述** + 代码位置:main.py文件中的main\_worker\(\)。 -基于NPU芯片的架构特性,会涉及到混合精度训练,即混合使用float16和float32数据类型的应用场景。使用float16代替float32有如下好处: + ```python + ############## npu modify begin ############# + train_loader = torch.utils.data.DataLoader( + train_dataset, batch_size=args.batch_size, shuffle=(train_sampler is None), + num_workers=args.workers, pin_memory=False, sampler=train_sampler, drop_last=True) + + val_loader = torch.utils.data.DataLoader( + datasets.ImageFolder(valdir, transforms.Compose([ + transforms.Resize(256), + transforms.CenterCrop(224), + transforms.ToTensor(), + normalize, + ])), + batch_size=args.batch_size, shuffle=True, + num_workers=args.workers, pin_memory=False, drop_last=True) + ############## npu modify end ############# + ``` -- 对于中间变量的内存占用更少,节省内存的使用。 -- 因内存使用会减少,所以数据传出的时间也会相应减少。 -- float16的计算单元可以提供更快的计算性能。 +11. 进行损失函数及优化器构建,将模型、损失函数迁移到昇腾AI处理器上;将优化器、模型与混合精度模块进行结合以支持混合精度训练;将断点训练部分与混合精度模块结合以支持混合精度训练。 -但是,混合精度训练受限于float16表达的精度范围,单纯将float32转换成float16会影响训练收敛情况,为了保证部分计算使用float16来进行加速的同时能保证训练收敛,这里采用混合精度模块Apex来达到以上效果。混合精度模块Apex是一个集优化性能、精度收敛于一身的综合优化库。 + 代码位置:main.py文件中的main\_worker\(\)中验证数据加载后。 -适配昇腾AI处理器的混合精度模块Apex除了上述优点外,还能提升运算性能。具体如下: + ```python + val_loader = torch.utils.data.DataLoader( + datasets.ImageFolder(valdir, transforms.Compose([ + transforms.Resize(256), + transforms.CenterCrop(224), + transforms.ToTensor(), + normalize, + ])), + batch_size=args.batch_size, shuffle=True, + num_workers=args.workers, pin_memory=False, drop_last=True) + + ############## npu modify begin ############# + model = model.to(loc) + # define loss function (criterion) and optimizer + criterion = nn.CrossEntropyLoss().to(loc) + optimizer = torch.optim.SGD(model.parameters(), args.lr, + momentum=args.momentum, + weight_decay=args.weight_decay) + + if args.amp: + model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, loss_scale=args.loss_scale) + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu]) + + # optionally resume from a checkpoint + if args.resume: + if os.path.isfile(args.resume): + print("=> loading checkpoint '{}'".format(args.resume)) + checkpoint = torch.load(args.resume, map_location=loc) + args.start_epoch = checkpoint['epoch'] + best_acc1 = checkpoint['best_acc1'] + model.load_state_dict(checkpoint['state_dict']) + optimizer.load_state_dict(checkpoint['optimizer']) + if args.amp: + amp.load_state_dict(checkpoint['amp']) + print("=> loaded checkpoint '{}' (epoch {})" + .format(args.resume, checkpoint['epoch'])) + else: + print("=> no checkpoint found at '{}'".format(args.resume)) + + cudnn.benchmark = True + ############## npu modify end ############# + ``` -- Apex在混合精度运算过程中,会对模型的grad进行运算。开启combine\_grad开关,可以加速这些运算。具体为将amp.initialize\(\)接口参数combine\_grad设置为True; -- 适配后的Apex针对adadelta/adam/sgd/lamb做了昇腾AI处理器亲和性优化,得到的NPU融合优化器与原生算法保持一致,但运算速度更快。使用时只需将原有优化器替换为apex.optimizers.\*(“\*”为优化器名称,例如NpuFusedSGD)。 +12. 断点checkpoint保存需要与混合精度训练结合,修改如下。 -**特性支持** + 代码位置:main.py文件中的main\_worker\(\)(修改部分为字体加粗部分)。 -混合精度模块功能和优化描述如[表1](#table10717173813332)所示。 + ```python + # remember best acc@1 and save checkpoint + is_best = acc1 > best_acc1 + best_acc1 = max(acc1, best_acc1) + + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + ############## npu modify begin ############# + if args.amp: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': args.arch, + 'state_dict': model.state_dict(), + 'best_acc1': best_acc1, + 'optimizer' : optimizer.state_dict(), + 'amp': amp.state_dict(), + }, is_best) + else: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': args.arch, + 'state_dict': model.state_dict(), + 'best_acc1': best_acc1, + 'optimizer' : optimizer.state_dict(), + }, is_best) + ############## npu modify end ############# + ``` -**表 1** 混合精度模块功能 +13. 训练时,需要将数据集迁移到昇腾AI处理器上,修改如下: - - - - - - - - - - - - - - - - - - -

功能

-

描述

-

O1配置模式

-

Conv,Matmul等使用float16计算,其他如Softmax、BN使用float32。

-

O2配置模式

-

除了BN使用float32外,其他绝大部分使用float16。

-

静态Loss Scale功能

-

静态设置参数确保混合精度训练收敛。

-

动态Loss Scale功能

-

动态计算loss Scale值并判断是否溢出。

-
+ 代码位置:main.py文件中的train\(\)(修改部分为字体加粗部分)。 ->![](public_sys-resources/icon-note.gif) **说明:** ->- 当前版本的实现方式主要为python实现,不支持AscendCL或者CUDA优化。 ->- 当前昇腾AI设备暂不支持原始Apex的FusedLayerNorm接口模块,如果模型原始脚本文件使用了FusedLayerNorm接口模块,需要在模型迁移过程中将脚本头文件“from apex.normalization import FusedLayerNorm“替换为“from torch.nn import LayerNorm“。 + ```python + for i, (images, target) in enumerate(train_loader): + # measure data loading time + data_time.update(time.time() - end) + ############## npu modify begin ############# + loc = 'npu:{}'.format(args.gpu) + target = target.to(torch.int32) + images, target = images.to(loc, non_blocking=False), target.to(loc, non_blocking=False) + ############## npu modify end ############# + # 原模型代码如下: + # if args.gpu is not None: + # images = images.cuda(args.gpu, non_blocking=True) + # if torch.cuda.is_available(): + # target = target.cuda(args.gpu, non_blocking=True) + ``` -**将混合精度模块集成到PyTorch模型中** +14. 标记反向传播.backward\(\)发生的位置,这样混合精度模块就可以进行Loss Scaling并清除每次迭代的状态,代码如下: -1. 使用apex混合精度模块需要首先从apex库中导入amp,代码如下: + 代码位置:main.py文件中的train\(\)(修改部分为字体加粗部分)。 - ``` - from apex import amp + ```python + optimizer.zero_grad() + ############## npu modify begin ############# + if args.amp: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + ############## npu modify end ############# + # 原代码如下注释部分: + # loss.backward() + optimizer.step() ``` -2. 导入amp模块后,需要初始化amp,使其能对模型、优化器以及PyTorch内部函数进行必要的改动,初始化代码如下: +15. 验证时,需要将验证数据集迁移到昇腾AI处理器上,修改如下: - ``` - model, optimizer = amp.initialize(model, optimizer,combine_grad=True) + 代码位置:main.py文件中的validate\(\)。 + + ```python + with torch.no_grad(): + end = time.time() + for i, (images, target) in enumerate(val_loader): + ############## npu modify begin ############# + loc = 'npu:{}'.format(args.gpu) + target = target.to(torch.int32) + images, target = images.to(loc, non_blocking=False), target.to(loc, non_blocking=False) + ############## npu modify end ############# + # 原模型代码如下注释部分: + # if args.gpu is not None: + # images = images.cuda(args.gpu, non_blocking=True) + # if torch.cuda.is_available(): + # target = target.cuda(args.gpu, non_blocking=True) ``` -3. 标记反向传播.backward\(\)发生的位置,这样Amp就可以进行Loss Scaling并清除每次迭代的状态,代码如下: +### 模型训练 - 原始代码: +**准备数据集** - ``` - loss = criterion(…) - loss.backward() - optimizer.step() - ``` +准备数据集并上传到运行环境的目录下,例如:/home/data/resnet50/imagenet。 - 修改以支持loss scaling后的代码: +**执行命令** - ``` - loss = criterion(…) - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - optimizer.step() - ``` +单卡训练: +```shell +python3 main.py /home/data/resnet50/imagenet --batch-size 128 \ # 训练批次大小 + --lr 0.1 \ # 学习率 + --epochs 90 \ # 训练迭代轮数 + --arch resnet50 \ # 模型架构 + --world-size 1 \ + --rank 0 \ + --workers 40 \ # 加载数据进程数 + --momentum 0.9 \ # 动量 + --weight-decay 1e-4 # 权重衰减 +``` -

模型训练

+分布式训练: -训练脚本迁移完成后,需要参见[配置环境变量](#zh-cn_topic_0000001144082004md)设置环境变量,然后执行**python3** _xxx_进行模型训练。具体样例请参考[脚本执行](#脚本执行md)。 +```shell +python3 main.py /home/data/resnet50/imagenet --addr='1.1.1.1' \ # 示例IP地址,请根据实际修改 + --seed 49 \ # 随机种子 + --workers 160 \ # 加载数据进程数 + --lr 0.8 \ + --print-freq 1 \ + --arch resnet50 \ # 模型架构 + --dist-url 'tcp://127.0.0.1:50000' \ + --dist-backend 'hccl' \ + --multiprocessing-distributed \ # 使用多卡训练 + --world-size 1 \ + --batch-size 2048 \ # 训练批次大小 + --epochs 90 \ # 训练迭代轮数 + --rank 0 \ + --device-list '0,1,2,3,4,5,6,7' \ + --amp # 使用混合精度训练 +``` >![](public_sys-resources/icon-note.gif) **说明:** ->执行“python3 xxx“命令时,须将python3软链接到与当前pytorch适配版本的python安装路径。 +>dist-backend需配置成hccl以支持在昇腾AI设备上进行分布式训练。 -

性能调优和分析

+

模型移植评估

-

前提条件

+1. 在选取模型时,尽可能选取权威Pytorch模型实现仓作为标杆,包括但不限于Pytorch\([example](https://github.com/pytorch/examples/tree/master/imagenet)/[vision](https://github.com/pytorch/vision)等\)、facebookresearch\([Detectron](https://github.com/facebookresearch/Detectron)/[detectron2](https://github.com/facebookresearch/detectron2)等\)和open-mmlab\([mmdetection](https://github.com/open-mmlab/mmdetection)/[mmpose](https://github.com/open-mmlab/mmpose)等\)。 +2. 查看算子适配情况。将原始模型及训练脚本迁移到昇腾AI处理器上之前,可以将原始模型及训练脚本在CPU上进行训练,使用dump op方法获取算子信息,与《PyTorch适配算子清单》算子进行比较,查看是否支持。dump op方法参见[dump op方法](#dump-op方法md),当有不支持算子时参见《PyTorch算子开发指南》进行算子开发。 -1. 参见[样例说明](#样例说明md)改造开源代码,使模型能够正常运行,包括数据预处理,前向计算,loss计算,混合精度,反向计算,参数更新等。 -2. 模型迁移阶段优先关注模型是否能跑通,现有算子是否能满足,如果遇到不满足的算子需参见《PyTorch算子开发指南》进行算子适配开发。 -3. 优先打通单卡功能,再打通多卡功能。 + >![](public_sys-resources/icon-note.gif) **说明:** + >查看算子适配情况也可以先将模型及训练脚本迁移到昇腾AI处理器(迁移方法参见下文)进行训练来查看报错信息。一般会提示不能在昇腾AI处理器的backend下运行某个算子(第一个不支持的算子)。 -

调测过程

-- **[总体思路](#总体思路md)** +

环境准备

-- **[采集训练过程相关数据](#采集训练过程相关数据md)** +请参见《PyTorch安装指南》进行PyTorch及混合精度模块安装,并配置环境变量。 -- **[host侧性能优化](#host侧性能优化md)** +

模型迁移

-- **[训练过程性能优化](#训练过程性能优化md)** +

工具迁移

-

总体思路

+Ascend平台提供了脚本转换工具使用户能通过命令行方式将训练脚本迁移到昇腾AI处理器上进行训练,命令行方式工具详细使用说明参见下文。除命令行方式外,用户也可通过MindStudio中集成的PyTorch GPU2Ascend功能进行迁移,详情请参见《MindStudio 用户指南》。 -1. 通过训练执行结果,判断吞吐量指标是否达到预期要求。 -2. 当吞吐量指标不达标时,需要找出制约性能瓶颈的原因,主要为以下几个方面: - - 算子瓶颈,在某个算子上执行过慢。 - - copy瓶颈,非连续转连续时进行copy带来的瓶颈。 - - 框架瓶颈,由于算子格式转换带来了额外操作。 - - 编译瓶颈,由于shape或属性来回变化造成反复编译。 +

功能介绍

-3. 针对以上制约性能瓶颈的原因进行分析与优化。 +**简介** -

采集训练过程相关数据

+昇腾NPU是AI算力的后起之秀,但目前训练和在线推理脚本大多是基于GPU的。由于NPU与GPU的架构差异,基于GPU的训练和在线推理脚本不能直接在NPU上使用,脚本转换工具提供了将基于GPU的脚本转换为基于NPU的脚本的自动化方法,节省了人工手动进行脚本迁移的学习成本与工作量,大幅提升了迁移效率。 -**Profiling数据采集** - -当模型训练过程中吞吐量指标不达标时,可以通过采集训练过程中的profiling数据,分析哪个环节、哪个算子导致的性能消耗。Profiling数据采集分为PyTorch层面和CANN层面的采集,PyTorch层面采集的是PyTorch API的数据,CANN层面采集的是TBE算子的数据。 - -请参见以下方式进行profiling数据的获取,并根据实际情况选择需要的数据采集方式。 - -- PyTorch层面Profiling数据采集。 - 1. 获取chrome\_trace文件。 - - 使用profile接口对原始代码的loss计算和优化过程进行改造。 - - ``` - # 使用ascend-pytorch适配的profile接口,即可获得,推荐只运行一个step - with torch.autograd.profiler.profile(use_npu=True) as prof: - out = model(input_tensor) - loss=loss_func(out) - loss.backward() - optimizer.zero_grad() - optimizer.step() - # 打印profiler结果信息 - print(prof) - # 导出chrome_trace文件到指定路径 - output_path = '/home/HwHiAiUser/profile_data.json' - prof.export_chrome_trace(output_path) - ``` - - 2. 运行成功后会打印出profiler结果信息。 - - 打印结果包含CPU和NPU的耗时等相关信息,详细信息参见表2 。 - - **表2** profiler结果字段表 - - | Name | Self CPU % | Self CPU | CPU total % | CPU total | CPU time avg | Self NPU % | Self NPU | NPU total | NPU time avg | # of Calls | - | ---- | ---------- | -------- | ----------- | --------- | ------------ | ---------- | -------- | --------- | ------------ | :--------: | - - 3. 查看chrome\_trace文件。 - - chrome\_trace文件可以通过以下方式打开查看:在Chrome浏览器 中输入“chrome://tracing“地址,然后将落盘文件拖到空白处即可打开文件内容,通过键盘W、A、S、D键,可以对profiler的结果进行缩放和移动。 - - 4. profiler其他功能。 - - 获取算子输入tensor的shape信息。 - - ```python - # 添加record_shapes参数,获取算子输入tensor的shape信息 - with torch.autograd.profiler.profile(use_npu=True, record_shapes=True) as prof: - # 添加模型计算过程 - print(prof) - ``` - - 打印结果中增加了每个算子的`Input Shape`信息。 - - - 获取使用NPU的内存信息。 - - ```python - # 添加profile参数,获取算子内存占用信息 - with torch.autograd.profiler.profile(use_npu=True, profile_memory=True) as prof: - # 添加模型计算过程 - print(prof) - ``` - - 打印结果中增加了每个算子的`CPU Mem`、`Self CPU Mem`、`NPU Mem`、`Self NPU Mem`信息。 - - >![](public_sys-resources/icon-note.gif) **说明:** - > - >该功能仅支持PyTorch1.8版本以上。 - - - 获取简洁的算子性能信息。 - - 该功能只打印每个算子栈最底层的算子信息,使分析结果更简洁。 - - ```python - # 添加use_npu_simple参数,获取简洁的算子信息 - with torch.autograd.profiler.profile(use_npu=True, use_npu_simple=True) as prof: - # 添加模型计算过程 - # 导出chrome_trace文件到指定路径 - output_path = '/home/HwHiAiUser/profile_data.json' - prof.export_chrome_trace(output_path) - ``` - - 在Chrome浏览器中打开chrome\_trace结果文件,可查看简洁的算子性能信息。 - -- CANN层面Profiling数据采集。 - - 1. 获取性能数据文件。 - - ``` - profiler_result_path = "/home/profiling_data" # profiling 数据保存的文件夹,需提前手动创建,请根据实际指定。 - with torch.npu.profile(profiler_result_path): - out = model(input_tensor) - loss=loss_func(out,target) - loss.backward() - optimizer.zero_grad() - optimizer.step() - ``` +>![](public_sys-resources/icon-note.gif) **说明:** +>- 脚本转换工具根据适配规则,对用户脚本给出修改建议并提供转换功能,大幅度提高了脚本迁移速度,降低了开发者的工作量。除使用[表1](#zh-cn_topic_0000001133095885_table4705239194613)里的脚本转换成功后可直接运行外,其他脚本的转换结果仅供参考,仍需用户根据实际情况做少量适配。 +>- [表1](#zh-cn_topic_0000001133095885_table4705239194613)里的原脚本需要在GPU环境下且基于python3能够跑通。 +>- [表1](#zh-cn_topic_0000001133095885_table4705239194613)里的脚本转换后的执行逻辑与转换前保持一致。 +>- 此脚本转换工具当前仅支持PyTorch训练脚本转换。 - >![](public_sys-resources/icon-note.gif) **说明:** - >获取性能数据文件时,model、input\_tensor、target需要下发到npu上。 +**表 1** 模型支持列表 - 2. 解析性能数据文件。 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

序号

+

模型名称

+

1

+

3D AttentionNet

+

2

+

3D Nested_UNet

+

3

+

Advanced East

+

4

+

AlexNet

+

5

+

DeeplabV3+(Xception-JFT)

+

6

+

DeepMar

+

7

+

Densenet121

+

8

+

DenseNet161

+

9

+

DenseNet169

+

10

+

DenseNet201

+

11

+

EAST

+

12

+

FCN

+

13

+

FD-GAN

+

14

+

FOTS

+

15

+

GENet

+

16

+

GoogleNet

+

17

+

GRU

+

18

+

Inception V4

+

19

+

InceptionV2

+

20

+

LPRNet

+

21

+

LSTM

+

22

+

MNASNet0_5

+

23

+

MNASNet0_75

+

24

+

MNASNet1_0

+

25

+

MNASNet1_3

+

26

+

MobileNetV1

+

27

+

MobileNetV2

+

28

+

PNet

+

29

+

PSENet

+

30

+

RAFT

+

31

+

RecVAE

+

32

+

ResNet101

+

33

+

ResNet152

+

34

+

ResNet18

+

35

+

ResNet34

+

36

+

ResNet50

+

37

+

Resnext101_32x8d

+

38

+

Resnext50

+

39

+

RNet

+

40

+

Shufflenetv2

+

41

+

SqueezeNet1_0

+

42

+

SqueezeNet1_1

+

43

+

U-Net

+

44

+

VAE+GAN

+

45

+

VGG11

+

46

+

VGG11_BN

+

47

+

VGG13

+

48

+

VGG13_BN

+

49

+

VGG16

+

50

+

VGG16_BN

+

51

+

VGG19

+

52

+

VGG19_BN

+

53

+

VIT-base

+

54

+

Wide_ResNet101_2

+

55

+

Wide_ResNet50_2

+
+**系统要求** - 请参见《CANN 开发辅助工具指南》中“Profiling工具使用指南(训练)”章节。 +脚本转换工具支持Ubuntu 18.04、CentOS 7.6或EulerOS 2.8。 +**环境准备** +详情请参考《CANN 软件安装指南》安装开发环境。 -**获取算子信息OP\_INFO** +

操作指南

-网络模型最终是以OP执行的,通过OPInfo日志,我们可以获取实际执行时的算子及其属性。通过get\_ascend\_op\_info.py脚本获取。 +**参数说明** -1. 编写get\_ascend\_op\_info.py脚本获取算子信息,脚本内容如下。 +**表 1** 参数说明 - ``` - # -*- coding: utf-8 -*- - """用于导出OPINFO - """ - import os - import sys - import argparse - - def func(host_log_folder): - """ - :param host_log_folder: where host_log_folder addr is. - :return: - """ - host_log_files = os.listdir(host_log_folder) - result = {} - - for host_log in host_log_files: - if not host_log.endswith('.log') or host_log.endswith('.out'): - continue - with open(os.path.join(host_log_folder, host_log), 'r')as f: - host_log_lines = f.readlines() - for line in host_log_lines: - if line.startswith('[INFO] ASCENDCL') and "aclopCompile::aclOp" in line: - op_info = line.split('OpType: ')[1][:-2] - op_type = op_info.split(',')[0] - op_param = op_info[len(op_type) + 2:] - if op_type not in result.keys(): - result[op_type] = [op_param] - else: - result[op_type].append(op_param) - - with open('ascend_op_info_summary.txt', 'w')as f: - for k, v in result.items(): - v_set = set(v) - for info in v_set: - f.write(k + " " + info + "\n") - - if __name__ == "__main__": - parser = argparse.ArgumentParser(description='trans the log') - parser.add_argument('--host_log_folder', default="./", - help="input the dir name, trans the current dir with default") - ags = parser.parse_args() - func(ags.host_log_folder) - ``` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

参数

+

参数说明

+

取值示例

+

-i

+

--input

+
  • 要进行转换的原始脚本文件所在文件夹路径或文件路径。
  • 必选。
+
  • /home/username/fmktransplt
  • /home/username/fmktransplt.py
+

-o

+

--output

+
  • 脚本转换结果文件输出路径。会在该路径下输出带有msft后缀的文件夹。
  • 必选。
+

/home/username/fmktransplt_output

+

-r

+

--rule

+
  • 用户自定义通用转换规则的json文件路径,主要分为:函数参数修改、函数名称修改和模块名称修改三部分。
  • 可选。
+

/home/username/fmktransplt_rule.json

+

-s

+

--specify-device

+
  • 可以通过环境变量设置指定device作为高级特性,但有可能导致原本脚本中分布式功能失效。
  • 可选。
+

-

+

-sim

+

--similar

+
  • 用功能相似的API替换某些不支持的API,但有可能导致准确性和性能下降。
  • 可选。
+

-

+

distributed

+

将GPU单卡脚本转换为NPU多卡脚本,仅支持使用torch.utils.data.DataLoader方式加载数据的场景,指定此参数时,才可以指定以下两个参数。

+
  • -m,--main:训练脚本的入口python文件,必选。
  • -t,--target model:目标模型变量名,默认为'model',可选。
+

-

+

-h

+

--help

+

显示帮助信息。

+

-

+
+**自定义规则文件** -2. 设置环境变量,将host日志打屏。 +自定义转换规则样例如下: - ``` - export ASCEND_SLOG_PRINT_TO_STDOUT=1 - ``` +``` +{ + "rules": { + "ArgsModifyRule": [ + { + "func_name": "name1", + "arg_idx": 0, + "arg_new": "agrs0" + }, + { + "func_name": "name2", + "arg_idx": 0, + "arg_new": "agrs0" + } + ], + "FuncNameModifyRule": [ + { + "old_name": "func", + "new_name": "new_func" + } + ], + "ModuleNameModifyRule": [ + { + "old_name": "module", + "new_name": "new_module", + "parent_module":"parent_module" + } + ] + } +} +``` -3. 设置日志级别为info,参考《CANN 日志参考》设置日志级别。 -4. 执行训练脚本,进行模型训练,训练完成后获取host侧日志,默认位置为$HOME/ascend/log/plog目录下,$HOME表示Host侧用户根目录。 -5. 解析host侧日志会在当前目录下得到OPInfo信息ascend\_op\_info\_summary.txt。 +**表 2** 参数说明 - ``` - python3 get_ascend_op_info.py --host_log_folder $HOME/ascend/log/plog - ``` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

参数

+

说明

+

ArgsModifyRule

+

函数参数修改

+

func_name

+

函数名称

+

arg_idx

+

参数的位置

+

arg_new

+

新的参数

+

FuncNameModifyRule

+

函数名称修改

+

ModuleNameModifyRule

+

模块名称修改

+

old_name

+

旧名称

+

new_name

+

新名称

+

parent_module

+

父级模块全名

+

例如torch.cuda.amp,amp的父级模块全名为torch.cuda。

+
+**执行转换** -6. 分析TaskInfo中额外的task,尤其关注transdata。 +1. 进入脚本转换工具所在路径。 -

host侧性能优化

+ ``` + cd Ascend-cann-toolkit安装目录/ascend-toolkit/{version}/{arch}-linux/toolkit/tools/ms_fmk_transplt + ``` -- **[概述](#概述-0md)** +2. 执行脚本转换工具。 -- **[修改CPU性能模式(X86服务器)](#修改CPU性能模式X86服务器md)** + ``` + python3 ms_fmk_transplt.py -i 原始脚本路径 -o 脚本转换结果输出路径 [-r 自定义规则json文件路径] [-s] [-sim] [distributed -m 训练脚本的入口文件 -t 目标模型变量名] + ``` -- **[修改CPU性能模式(ARM服务器)](#修改CPU性能模式ARM服务器md)** + >![](public_sys-resources/icon-note.gif) **说明:** + >distributed及其参数-m、-t在语句最后指定。 -- **[安装高性能pillow库(X86服务器)](#安装高性能pillow库X86服务器md)** +3. 完成脚本转换。 -- **[(可选)安装指定版本OpenCV库](#可选安装指定版本OpenCV库md)** +

结果解析

+脚本转换完成后,进入脚本转换结果输出路径查看结果文件,以GPU单卡脚本转换为NPU多卡脚本为例。 -
概述
+``` +├── xxx_msft // 脚本转换结果输出目录,默认为原始脚本路径。xxx为原始脚本所在文件夹名称。 +│ ├── 生成脚本文件 // 与转换前的脚本文件目录结构一致。 +│ ├── msFmkTranspltlog.txt // 脚本转换过程日志文件。 +│ ├── unsupported_op.xlsx // 不支持算子列表文件。 +│ ├── change_list.csv // 修改记录文件。 +│ ├── run_distributed_npu.sh // 多卡启动shell脚本。 +``` -在进行PyTorch模型迁移训练时,部分网络模型会出现FPS较低、性能不达标的情况。可以考虑对服务器进行以下优化尝试提高训练性能。 +

手工迁移

-- 修改CPU性能模式。 -- 安装高性能pillow库。 -- (可选)安装指定版本OpenCV库。 -
修改CPU性能模式(X86服务器)
+

单P训练模型迁移

-**设置电源策略为高性能模式** +当前在线对接方案优点在于保证在昇腾AI处理器上训练与GPU的使用方式和风格保持一致。用户在使用在线对接方案时,**只需在Python侧和Device相关操作中,指定device为昇腾AI处理器**,即可完成用昇腾AI处理器在PyTorch对网络的开发、训练以及调试。针对单P模型训练,主要迁移改动如下。 -提升网络性能需要在X86服务器BIOS设置中将电源策略设为高性能模式,具体操作如下。 +迁移前GPU代码: -1. 登录iBMC界面,启动虚拟控制台,远程控制选择HTML5集成远程控制台,如[图1](#fig15869135420288)。 +``` + CALCULATE_DEVICE = “gpu:0” + torch.cuda.set_device(CALCULATE_DEVICE) + # 放到device的两种方法 + model = model.cuda() # 写法1 + model = model.to(CALCULATE_DEVICE) # 写法2 + # 将输入也从host放到device + images = images.to(CALCULATE_DEVICE) + target = target.to(CALCULATE_DEVICE) +``` - **图 1** 远程登录控制台 - ![](figures/远程登录控制台.png "远程登录控制台") +迁移到昇腾AI处理器上代码为: -2. 在虚拟界面工具栏中,单击启动项工具![](figures/zh-cn_image_0000001144241932.png),弹出启动项配置界面,如[图2](#fig744814574243)。 +``` + CALCULATE_DEVICE = “npu:0” + torch.npu.set_device(CALCULATE_DEVICE) + # 放到device的两种方法 + model = model.npu() # 写法1 + model = model.to(CALCULATE_DEVICE) # 写法2 + # 将输入也从host放到device + images = images.to(CALCULATE_DEVICE) + target = target.to(CALCULATE_DEVICE) +``` - **图 2** 启动项工具 - ![](figures/启动项工具.png "启动项工具") +更多迁移细节请参见[单P训练修改](#单P训练修改md)。 -3. 在启动项配置界面选择,选择“BIOS设置”,然后在虚拟界面工具栏中单击重启工具![](figures/zh-cn_image_0000001190201999.png),重启服务器。 -4. 系统重启后进入BIOS配置界面,依次选择“Advanced”\>“Socket Configuration”,如[图3](#fig4546303814)所示。 +

多P训练模型迁移

- **图 3** Socket Configuration - ![](figures/Socket-Configuration.png "Socket-Configuration") +多P训练模型迁移除了需在**Python侧和Device相关操作中,指定device为昇腾AI处理器**外,依然通过PyTorch的DistributedDataParallel方式来进行分布式训练,即在模型初始化阶段执行init\_process\_group,再将模型初始化为DistributedDataParallel模型。但须注意的是在初始化init\_process\_group时需要将**backend**配置为**hccl**并屏蔽掉初始化方式。 -5. 进入Advanced Power Mgmt. Configuration,设置Power Policy为Performance。如[图4](#fig15501111014442)。 +PyTorch分布式训练代码示例(部分代码省略): - **图 4** 设置电源策略 - ![](figures/设置电源策略.png "设置电源策略") +``` +import torch +import torch.distributed as dist +import torch.nn.parallel +def main(): + args = parser.parse_args() + # 需屏蔽掉初始化方式 + dist.init_process_group(backend='hccl',# init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu]) # model需要下发到npu上 + train_loader = torch.utils.data.DataLoader( + train_dataset, batch_size=args.batch_size, shuffle=(train_sampler is None), + num_workers=args.workers, pin_memory=True, sampler=train_sampler) + for epoch in range(args.start_epoch, args.epochs): + acc1 = train(train_loader, model, criterion, optimizer, epoch, args,ngpus_per_node, + lr_scheduler) +``` -6. 按下“F10”保存配置并重启服务器。 +更多迁移细节请参见[分布式训练修改](#分布式训练修改md)。 -**将CPU设置为performance模式** +

PyTorch接口替换

-请使用root用户执行如下操作。 +1. 为了使昇腾AI处理器使用PyTorch框架的能力,需要对原生的PyTorch框架进行一定Device层面的适配,对外呈现是需要将跟cpu和cuda相关的接口进行切换;在进行网络迁移时,需要将某些设备相关的接口转换成跟昇腾AI处理器相关的接口,当前适配的设备相关接口请参见[表1](#table1922064517344): -1. 使用如下命令查看当前CPU模式。 + **表 1** 设备接口替换 - ``` - cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor - ``` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

PyTorch原始接口

+

适配昇腾AI处理器后的接口

+

说明

+

torch.cuda.is_available()

+

torch.npu.is_available()

+

判断当前环境上设备是否可用(不代表最后结果)。

+

torch.cuda.current_device()

+

torch.npu.current_device()

+

获取当前正在使用的device。

+

torch.cuda.device_count()

+

torch.npu.device_count()

+

获取当前环境上的设备数量。

+

torch.cuda.set_device()

+

torch.npu.set_device()

+

设置当前正在使用的device。

+

torch.tensor([1,2,3]).is_cuda

+

torch.tensor([1,2,3]).is_npu

+

判断某个tensor是否是cuda/npu设备上的格式。

+

torch.tensor([1,2,3]).cuda()

+

torch.tensor([1,2,3]).npu()

+

将某个tensor转换成cuda/npu格式。

+

torch.tensor([1,2,3]).to("cuda")

+

torch.tensor([1,2,3]).to('npu')

+

将某个tensor转换成cuda/npu格式。

+

torch.cuda.synchronize()

+

torch.npu.synchronize()

+

同步等待事件完成。

+

torch.cuda.device

+

torch.npu.device

+

生成一个device类,可以执行device相关操作。

+

torch.cuda.Stream(device)

+

torch.npu.Stream(device)

+

生成一个stream对象。

+

torch.cuda.stream(Stream)

+

torch.npu.stream(Stream)

+

多用于作用域限定。

+

torch.cuda.current_stream()

+

torch.npu.current_stream()

+

获取当前stream。

+

torch.cuda.default_stream()

+

torch.npu.default_stream()

+

获取默认stream。

+

device = torch.device("cuda:0")

+

device = torch.device("npu:0")

+

指定一个设备。

+

torch.autograd.profiler.profile

+

(use_cuda=True)

+

torch.autograd.profiler.profile

+

(use_npu=True)

+

指定执行profiler过程中使用cuda/npu。

+

torch.cuda.Event()

+

torch.npu.Event()

+

返回某个设备上的事件。

+
- 执行以上命令会输出当前CPU模式,CPU模式说明请参见[表1](#table354392019384)。如果当前CPU模式不是performance模式,请执行以下操作设置CPU为performance模式。否则请跳过以下步骤。 +2. 用户在构建网络或进行网络迁移时,需要创建指定数据类型的tensor,在昇腾AI处理器上创建的tensor如下。 - **表 1** CPU模式 + **表 2** tensor创建接口替换 - -

调速器

+ + - - - - - - - - - - - - - + + + + + + + + + + + +

GPU tensor

描述

+

适配昇腾AI处理器后的接口

performance

+

torch.tensor([1,2,3],dtype=torch.long,device='cuda')

运行于最大频率。

+

torch.tensor([1,2,3],dtype=torch.long,device='npu')

powersave

+

torch.tensor([1,2,3],dtype=torch.int,device='cuda')

运行于最小频率。

+

torch.tensor([1,2,3],dtype=torch.int,device='npu')

userspace

+

torch.tensor([1,2,3],dtype=torch.half,device='cuda')

运行于用户指定的频率。

+

torch.tensor([1,2,3],dtype=torch.half,device='npu')

ondemand

+

torch.tensor([1,2,3],dtype=torch.float,device='cuda')

按需快速动态调整CPU频率,一有CPU计算量的任务,就会立即达到最大频率运行,空闲时间增加就降低频率。

+

torch.tensor([1,2,3],dtype=torch.float,device='npu')

conservative

+

torch.tensor([1,2,3],dtype=torch.bool,device='cuda')

按需快速动态调整CPU频率,比ondemand的调整更保守。

+

torch.tensor([1,2,3],dtype=torch.bool,device='npu')

schedutil

+

torch.cuda.BoolTensor([1,2,3])

基于调度程序调整 CPU 频率。

+

torch.npu.BoolTensor([1,2,3])

+

torch.cuda.FloatTensor([1,2,3])

+

torch.npu.FloatTensor([1,2,3])

+

torch.cuda.IntTensor([1,2,3])

+

torch.npu.IntTensor([1,2,3])

+

torch.cuda.LongTensor([1,2,3])

+

torch.npu.LongTensor([1,2,3])

+

torch.cuda.HalfTensor([1,2,3])

+

torch.npu.HalfTensor([1,2,3])

-2. 安装工具,使用如下命令安装。 - - 以“ubuntu/debian“系统为例。 - - ``` - apt-get install linux-tools-$(uname -r) - ``` - - 以“centos/bclinux/euler“系统为例: +更多接口请参见《PyTorch API支持清单》。 - ``` - yum install kernel-tools -y - systemctl daemon-reload - systemctl enable cpupower - systemctl start cpupower - ``` +

混合精度

-3. 设置CPU为performance模式。 +**概述** - ``` - cpupower frequency-set -g performance - ``` +基于NPU芯片的架构特性,会涉及到混合精度训练,即混合使用float16和float32数据类型的应用场景。使用float16代替float32有如下好处: -4. 再次执行[步骤1](#li158435131344)查看当前CPU模式是否已设置为performance模式。 +- 对于中间变量的内存占用更少,节省内存的使用。 +- 因内存使用会减少,所以数据传出的时间也会相应减少。 +- float16的计算单元可以提供更快的计算性能。 -
修改CPU性能模式(ARM服务器)
+但是,混合精度训练受限于float16表达的精度范围,单纯将float32转换成float16会影响训练收敛情况,为了保证部分计算使用float16来进行加速的同时能保证训练收敛,这里采用混合精度模块Apex来达到以上效果。混合精度模块Apex是一个集优化性能、精度收敛于一身的综合优化库。 -**设置电源策略为高性能模式** +适配昇腾AI处理器的混合精度模块Apex除了上述优点外,还能提升运算性能。具体如下: -在某些对Host侧CPU要求较高的模型中,例如目标检测类模型,需要进行较为复杂的图像预处理,开启电源高性能模式能一定程度上提高性能和稳定性。ARM服务器提升网络性能需要在BIOS设置中将电源策略设为高性能模式,具体操作如下。 +- Apex在混合精度运算过程中,会对模型的grad进行运算。开启combine\_grad开关,可以加速这些运算。具体为将amp.initialize\(\)接口参数combine\_grad设置为True; +- 适配后的Apex针对adadelta/adam/sgd/lamb做了昇腾AI处理器亲和性优化,得到的NPU融合优化器与原生算法保持一致,但运算速度更快。使用时只需将原有优化器替换为apex.optimizers.\*(“\*”为优化器名称,例如NpuFusedSGD)。 -1. 登录ibmc界面,启动虚拟控制台,远程控制选择HTML5集成远程控制台,如[图1](#fig15869135420288)。 +**特性支持** - **图 1** 远程登录控制台 - ![](figures/远程登录控制台-0.png "远程登录控制台-0") +混合精度模块功能和优化描述如[表1](#table10717173813332)所示。 -2. 在虚拟界面工具栏中,单击启动项工具![](figures/zh-cn_image_0000001190202013.png),弹出启动项配置界面,如[图2](#fig744814574243)。 +**表 1** 混合精度模块功能 - **图 2** 启动项工具 - ![](figures/启动项工具-1.png "启动项工具-1") + + + + + + + + + + + + + + + + + + +

功能

+

描述

+

O1配置模式

+

Conv,Matmul等使用float16计算,其他如Softmax、BN使用float32。

+

O2配置模式

+

除了BN使用float32外,其他绝大部分使用float16。

+

静态Loss Scale功能

+

静态设置参数确保混合精度训练收敛。

+

动态Loss Scale功能

+

动态计算loss Scale值并判断是否溢出。

+
-3. 在启动项配置界面选择,选择“BIOS设置”,然后在虚拟界面工具栏中单击重启工具![](figures/zh-cn_image_0000001144082138.png),重启服务器。 -4. 系统重启后进入BIOS配置界面,依次选择“Advanced”\>“ Performance Config”,如[图3](#fig4546303814)所示。 +>![](public_sys-resources/icon-note.gif) **说明:** +>- 当前版本的实现方式主要为python实现,不支持AscendCL或者CUDA优化。 +>- 当前昇腾AI设备暂不支持原始Apex的FusedLayerNorm接口模块,如果模型原始脚本文件使用了FusedLayerNorm接口模块,需要在模型迁移过程中将脚本头文件“from apex.normalization import FusedLayerNorm“替换为“from torch.nn import LayerNorm“。 - **图 3** Performance Config - ![](figures/Performance-Config.png "Performance-Config") +**将混合精度模块集成到PyTorch模型中** -5. 进入“Performance Config”,设置Power Policy为Performance。如[图4](#fig15501111014442)。 +1. 使用apex混合精度模块需要首先从apex库中导入amp,代码如下: - **图 4** 设置电源策略 - ![](figures/设置电源策略-2.png "设置电源策略-2") + ``` + from apex import amp + ``` -6. 按下“F10”保存配置并重启服务器。 +2. 导入amp模块后,需要初始化amp,使其能对模型、优化器以及PyTorch内部函数进行必要的改动,初始化代码如下: -
安装高性能pillow库(X86服务器)
+ ``` + model, optimizer = amp.initialize(model, optimizer,combine_grad=True) + ``` -1. 安装高性能pillow库相关依赖,命令如下。 +3. 标记反向传播.backward\(\)发生的位置,这样Amp就可以进行Loss Scaling并清除每次迭代的状态,代码如下: - ubuntu/debian: + 原始代码: ``` - apt-get install libtiff5-dev libjpeg8-dev libopenjp2-7-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk libharfbuzz-dev libfribidi-dev libxcb1-dev + loss = criterion(…) + loss.backward() + optimizer.step() ``` - centos/bclinux/euler: + 修改以支持loss scaling后的代码: ``` - yum install libtiff-devel libjpeg-devel openjpeg2-devel zlib-devel freetype-devel lcms2-devel libwebp-devel tcl-devel tk-devel harfbuzz-devel fribidi-devel libraqm-devel libimagequant-devel libxcb-devel + loss = criterion(…) + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + optimizer.step() ``` -2. 安装高性能pillow库。 - 1. 执行如下命令卸载原生pillow。 - - ``` - pip3.7 uninstall -y pillow - ``` - 2. 安装SSE4版本pillow-simd。 +

模型训练

- 使用root用户安装,执行如下命令,若使用非root用户安装,需在命令结尾加上--user。 +训练脚本迁移完成后,需要参见[配置环境变量](#zh-cn_topic_0000001144082004md)设置环境变量,然后执行**python3** _xxx_进行模型训练。具体样例请参考[脚本执行](#脚本执行md)。 - ``` - pip3.7 install pillow-simd - ``` +>![](public_sys-resources/icon-note.gif) **说明:** +>执行“python3 xxx“命令时,须将python3软链接到与当前pytorch适配版本的python安装路径。 - >![](public_sys-resources/icon-note.gif) **说明:** - >如果CPU支持AVX2指令集,可安装AVX2版本pillow-simd,命令如下: - >``` - >CC="cc -mavx2" pip3.7 install -U --force-reinstall pillow-simd - >``` +

性能调优和分析

-3. 修改torchvision代码解决pillow-simd缺少PILLOW\_VERSION问题。torchvision安装参见[样例获取](#样例获取md)。 +

前提条件

- 将/usr/local/python3.x.x/lib/python3.x/site-packages/torchvision/transforms/functional.py第5行代码修改如下: +1. 参见[样例说明](#样例说明md)改造开源代码,使模型能够正常运行,包括数据预处理,前向计算,loss计算,混合精度,反向计算,参数更新等。 +2. 模型迁移阶段优先关注模型是否能跑通,现有算子是否能满足,如果遇到不满足的算子需参见《PyTorch算子开发指南》进行算子适配开发。 +3. 优先打通单卡功能,再打通多卡功能。 - ``` - try: - from PIL import Image, ImageOps, ImageEnhance,PILLOW_VERSION - except: - from PIL import Image, ImageOps, ImageEnhance - PILLOW_VERSION="7.0.0" - ``` +

调测过程

+- **[总体思路](#总体思路md)** -
(可选)安装指定版本OpenCV库
+- **[采集训练过程相关数据](#采集训练过程相关数据md)** -如模型依赖OpenCV,基于训练性能考虑,建议安装OpenCV-3.4.10版本。 +- **[host侧性能优化](#host侧性能优化md)** -1. 获取源码:[获取地址](https://opencv.org/releases/)。 -2. 安装指导:[获取地址](https://docs.opencv.org/3.4.10/d7/d9f/tutorial_linux_install.html)。 +- **[训练过程性能优化](#训练过程性能优化md)** -

训练过程性能优化

-**算子瓶颈优化** +

总体思路

-1. 获取训练过程中的Profiling数据,参见[Profiling数据采集](#采集训练过程相关数据md)。 -2. 分析Profiling数据,得到耗时较大的算子。 -3. 参见[单算子样例编写说明](#单算子样例编写说明md)构建耗时较大算子的单算子样例,通过与CPU或GPU运行单算子样例时间进行对比,若发现性能不足,则有以下两种方案解决。 - - 规避方案:使用同等语义其他高效算子替代。 - - 解决方案:改进算子性能。 +1. 通过训练执行结果,判断吞吐量指标是否达到预期要求。 +2. 当吞吐量指标不达标时,需要找出制约性能瓶颈的原因,主要为以下几个方面: + - 算子瓶颈,在某个算子上执行过慢。 + - copy瓶颈,非连续转连续时进行copy带来的瓶颈。 + - 框架瓶颈,由于算子格式转换带来了额外操作。 + - 编译瓶颈,由于shape或属性来回变化造成反复编译。 -**copy瓶颈优化** +3. 针对以上制约性能瓶颈的原因进行分析与优化。 -1. 获取训练过程中的Profiling数据,参见[Profiling数据采集](#采集训练过程相关数据md)。 -2. 分析Profiling数据分析整网中的D2DCopywithStreamSynchronize/PTCopy/format\_contiguous的耗时。 -3. 若发现耗时较大,则需参照以下两种方案解决。 - - 方案一:(规避方案)PyTorch中View类型框架类算子会导致非连续转连续操作。优化思路为尽量使用计算类算子代替View类框架算子,常见的View类框架算子如View、Permute、Transpose等。更多View类框架算子可参考[https://pytorch.org/docs/stable/tensor\_view.html](https://pytorch.org/docs/stable/tensor_view.html)。 - - 方案二:(解决方案)加速转连续操作。 +

采集训练过程相关数据

-**框架瓶颈优化** +**Profiling数据采集** -1. 获取训练过程中算子信息OP\_INFO,参见[获取算子信息OP\_INFO](#采集训练过程相关数据md)。 -2. 分析OP\_INFO中算子的规格和调用关系,定位是否插入了多余的算子,重点关注transdata是否合理。 -3. 优化方案:通过指定部分算子初始化格式,对多余的格式转换算子进行消除。 -4. 在pytorch/torch/nn/modules/module.py中,在cast\_weight中指定算子初始化格式,如下图。 +当模型训练过程中吞吐量指标不达标时,可以通过采集训练过程中的profiling数据,分析哪个环节、哪个算子导致的性能消耗。Profiling数据采集分为PyTorch层面和CANN层面的采集,PyTorch层面采集的是PyTorch API的数据,CANN层面采集的是TBE算子的数据。 - ![](figures/指定算子初始化方式.png) +请参见以下方式进行profiling数据的获取,并根据实际情况选择需要的数据采集方式。 - 格式设置原则可参考如下规则: +- PyTorch层面Profiling数据采集。 + 1. 获取chrome\_trace文件。 - - Conv2D相关:Weight 可设置为FZ格式,如第424行。 - - Linear相关的参数,可设置为NZ格式,如第409行。 + 使用profile接口对原始代码的loss计算和优化过程进行改造。 -**编译瓶颈优化** + ``` + # 使用ascend-pytorch适配的profile接口,即可获得,推荐只运行一个step + with torch.autograd.profiler.profile(use_npu=True) as prof: + out = model(input_tensor) + loss=loss_func(out) + loss.backward() + optimizer.zero_grad() + optimizer.step() + # 打印profiler结果信息 + print(prof) + # 导出chrome_trace文件到指定路径 + output_path = '/home/HwHiAiUser/profile_data.json' + prof.export_chrome_trace(output_path) + ``` -1. 获取训练过程中算子信息OP\_INFO,参见[获取算子信息OP\_INFO](#采集训练过程相关数据md)。 -2. 查看INFO日志,观察第一个step以后的aclopCompile::aclOp关键字,如果后续接了Match op inputs/type failed或To compile op则说明该算子存在动态编译,需要优化。 -3. 需参照以下两种方案解决。 - - 规避方案:在理解模型语义和相关API基础上,使用固定Shape的方式代替动态Shape。 - - 解决方案:减少编译或不需要编译该算子。 - - 优化算子编译配置请参见[编译选项设置](#编译选项设置md)。 + 2. 运行成功后会打印出profiler结果信息。 + 打印结果包含CPU和NPU的耗时等相关信息,详细信息参见表2 。 + + **表2** profiler结果字段表 + + | Name | Self CPU % | Self CPU | CPU total % | CPU total | CPU time avg | Self NPU % | Self NPU | NPU total | NPU time avg | # of Calls | + | ---- | ---------- | -------- | ----------- | --------- | ------------ | ---------- | -------- | --------- | ------------ | :--------: | + + 3. 查看chrome\_trace文件。 -

亲和库

+ chrome\_trace文件可以通过以下方式打开查看:在Chrome浏览器 中输入“chrome://tracing“地址,然后将落盘文件拖到空白处即可打开文件内容,通过键盘W、A、S、D键,可以对profiler的结果进行缩放和移动。 + 4. profiler其他功能。 + - 获取算子输入tensor的shape信息。 -

来源介绍

+ ```python + # 添加record_shapes参数,获取算子输入tensor的shape信息 + with torch.autograd.profiler.profile(use_npu=True, record_shapes=True) as prof: + # 添加模型计算过程 + print(prof) + ``` -针对公版模型中常见的网络结构和函数,我们针对性地对其进行了优化,使得运算性能大幅度提升,同时,将其集成到Pytorch框架中,便于模型性能调优中使用。 + 打印结果中增加了每个算子的`Input Shape`信息。 -

功能介绍

+ - 获取使用NPU的内存信息。 - - - - - - - - - - - - - - - - - - - - - - - -

函数名

-

位置

-

功能说明

-

pairwise_iou

-

torch.contrib.npu.optimized_lib

-

计算两个目标框的IOU。

-

fast_rcnn_inference_single_image

-

torch.contrib.npu.optimized_lib

-

Maskrcnn和Fasterrcnn模型的推理接口。

-

ChannelShuffle

-

torch.contrib.npu.optimized_lib

-

提供NPU亲和的channelshuffle操作,适用于shufflenetv2等模型。

-

PreLoader

-

torch.contrib.npu.optimized_lib

-

提供针对昇腾AI处理器加速的数据加载方法。

-
+ ```python + # 添加profile参数,获取算子内存占用信息 + with torch.autograd.profiler.profile(use_npu=True, profile_memory=True) as prof: + # 添加模型计算过程 + print(prof) + ``` ->![](public_sys-resources/icon-note.gif) **说明:** ->该部分调优内容会随着版本不断增强和更新,请以实际PyTorch版本中对应路径下的内容为准。 + 打印结果中增加了每个算子的`CPU Mem`、`Self CPU Mem`、`NPU Mem`、`Self NPU Mem`信息。 -

精度调测

+ >![](public_sys-resources/icon-note.gif) **说明:** + > + >该功能仅支持PyTorch1.8版本以上。 + - 获取简洁的算子性能信息。 -

前提条件

+ 该功能只打印每个算子栈最底层的算子信息,使分析结果更简洁。 -优先在同等语义和超参下,跑一定的epoch(推荐完整epoch数的20%),使精度,loss等对齐GPU相应水平,完成后再对齐最终精度。 + ```python + # 添加use_npu_simple参数,获取简洁的算子信息 + with torch.autograd.profiler.profile(use_npu=True, use_npu_simple=True) as prof: + # 添加模型计算过程 + # 导出chrome_trace文件到指定路径 + output_path = '/home/HwHiAiUser/profile_data.json' + prof.export_chrome_trace(output_path) + ``` -

调测过程

+ 在Chrome浏览器中打开chrome\_trace结果文件,可查看简洁的算子性能信息。 -- **[总体思路](#总体思路-4md)** +- CANN层面Profiling数据采集。 -- **[精度调优方法](#精度调优方法md)** + 1. 获取性能数据文件。 + ``` + profiler_result_path = "/home/profiling_data" # profiling 数据保存的文件夹,需提前手动创建,请根据实际指定。 + with torch.npu.profile(profiler_result_path): + out = model(input_tensor) + loss=loss_func(out,target) + loss.backward() + optimizer.zero_grad() + optimizer.step() + ``` -

总体思路

+ >![](public_sys-resources/icon-note.gif) **说明:** + >获取性能数据文件时,model、input\_tensor、target需要下发到npu上。 -精度问题排查需要找出是哪一步出现的问题,主要以下几个方面: + 2. 解析性能数据文件。 -1. 模型网络计算错误。 - - 定位思路:在网络中加入hook进行排查判断是哪个地方有较大嫌疑,然后构建[单算子用例](#单算子样例编写说明md)逐渐缩小错误范围,证明该算子在当前网络场景下计算有误,可以对比CPU或GPU结果证明。 + 请参见《CANN 开发辅助工具指南》中“Profiling工具使用指南(训练)”章节。 - - 规避方案:使用同等语义其他算子替代。 - - 解决方案:改进算子精度或功能问题。 -2. loss计算错误。 - - 定位思路:由于Loss的特殊性和可以自定义,在判断Loss计算错误后建议dump网络中的loss的输入来测试而非随机同shape tensor,这样才能更好地复现证明。 +**获取算子信息OP\_INFO** - - 规避方案:使用同等语义其他算子替代。 +网络模型最终是以OP执行的,通过OPInfo日志,我们可以获取实际执行时的算子及其属性。通过get\_ascend\_op\_info.py脚本获取。 - - 解决方案:改进算子精度或功能问题(loss也是由算子构成)。 +1. 编写get\_ascend\_op\_info.py脚本获取算子信息,脚本内容如下。 -3. 参数更新错误。 + ``` + # -*- coding: utf-8 -*- + """用于导出OPINFO + """ + import os + import sys + import argparse + + def func(host_log_folder): + """ + :param host_log_folder: where host_log_folder addr is. + :return: + """ + host_log_files = os.listdir(host_log_folder) + result = {} + + for host_log in host_log_files: + if not host_log.endswith('.log') or host_log.endswith('.out'): + continue + with open(os.path.join(host_log_folder, host_log), 'r')as f: + host_log_lines = f.readlines() + for line in host_log_lines: + if line.startswith('[INFO] ASCENDCL') and "aclopCompile::aclOp" in line: + op_info = line.split('OpType: ')[1][:-2] + op_type = op_info.split(',')[0] + op_param = op_info[len(op_type) + 2:] + if op_type not in result.keys(): + result[op_type] = [op_param] + else: + result[op_type].append(op_param) + + with open('ascend_op_info_summary.txt', 'w')as f: + for k, v in result.items(): + v_set = set(v) + for info in v_set: + f.write(k + " " + info + "\n") + + if __name__ == "__main__": + parser = argparse.ArgumentParser(description='trans the log') + parser.add_argument('--host_log_folder', default="./", + help="input the dir name, trans the current dir with default") + ags = parser.parse_args() + func(ags.host_log_folder) + ``` - - 定位思路:在每个optim.step\(\)前对网络中的参数逐个打印其grad进行排查判断是哪个地方有较大嫌疑,然后构建单算子用例逐渐缩小错误范围,证明该算子在当前网络场景下梯度计算有误,可以对比CPU或GPU结果证明。该项优先级应低于[1.](#li17755175510322)与[2.](#li25281726103316),因为1与2的错误同样可以造成grad异常。 +2. 设置环境变量,将host日志打屏。 - - 规避方案:使用同等语义其他算子替代。 + ``` + export ASCEND_SLOG_PRINT_TO_STDOUT=1 + ``` + +3. 设置日志级别为info,参考《CANN 日志参考》设置日志级别。 +4. 执行训练脚本,进行模型训练,训练完成后获取host侧日志,默认位置为$HOME/ascend/log/plog目录下,$HOME表示Host侧用户根目录。 +5. 解析host侧日志会在当前目录下得到OPInfo信息ascend\_op\_info\_summary.txt。 + + ``` + python3 get_ascend_op_info.py --host_log_folder $HOME/ascend/log/plog + ``` - - 解决方案:改进计算grad的算子精度或功能问题。 +6. 分析TaskInfo中额外的task,尤其关注transdata。 -4. 多卡计算错误。 +

host侧性能优化

- - 定位思路:在保证单卡精度OK的前提下,稳定复现多卡不收敛。 +- **[概述](#概述-0md)** - - 解决方案:建议联系华为方支撑人员,提供稳定复现的单P和多P脚本。 +- **[修改CPU性能模式(X86服务器)](#修改CPU性能模式X86服务器md)** +- **[修改CPU性能模式(ARM服务器)](#修改CPU性能模式ARM服务器md)** +- **[安装高性能pillow库(X86服务器)](#安装高性能pillow库X86服务器md)** -

精度调优方法

+- **[(可选)安装指定版本OpenCV库](#可选安装指定版本OpenCV库md)** -模型出现精度问题一般有:因算子溢出导致的训练loss不收敛或者精度不达标问题,整个网络训练引起的性能不达标问题。用户可通过单算子溢出检测和整网调测适度解决模型精度不达标问题。 -- **[单算子溢出检测](#单算子溢出检测md)** +
概述
-- **[整网调测](#整网调测md)** +在进行PyTorch模型迁移训练时,部分网络模型会出现FPS较低、性能不达标的情况。可以考虑对服务器进行以下优化尝试提高训练性能。 +- 修改CPU性能模式。 +- 安装高性能pillow库。 +- (可选)安装指定版本OpenCV库。 -
单算子溢出检测
+
修改CPU性能模式(X86服务器)
-用户通过算子溢出检测功能检测算子是否有溢出,然后采集溢出算子的数据,从而帮助开发人员快速定位并解决算子精度问题。 +**设置电源策略为高性能模式** -约束说明: +提升网络性能需要在X86服务器BIOS设置中将电源策略设为高性能模式,具体操作如下。 -- 需要安装hdf5工具以支持算子dump功能,安装详情请参见[编译安装hdf5](#编译安装hdf5md)。 -- 本功能只提供IR级别的算子溢出检测,且只支持AICORE,不支持Atomic。 -- 须在PyTorch源代码“build.sh“文件中添加“USE\_DUMP=1”字段。 +1. 登录iBMC界面,启动虚拟控制台,远程控制选择HTML5集成远程控制台,如[图1](#fig15869135420288)。 - ``` - 修改前: DEBUG=0 USE_DISTRIBUTED=1 USE_HCCL=1 USE_MKLDNN=0 USE_CUDA=0 USE_NPU=1 BUILD_TEST=0 USE_NNPACK=0 python3 setup.py build bdist_wheel - 修改后: DEBUG=0 USE_DISTRIBUTED=1 USE_HCCL=1 USE_MKLDNN=0 USE_CUDA=0 USE_NPU=1 BUILD_TEST=0 USE_NNPACK=0 USE_DUMP=1 python3 setup.py build - ``` + **图 1** 远程登录控制台 + ![](figures/远程登录控制台.png "远程登录控制台") - 并参见《PyTorch安装指南》的“手动编译安装”章节重新编译并安装PyTorch。 +2. 在虚拟界面工具栏中,单击启动项工具![](figures/zh-cn_image_0000001144241932.png),弹出启动项配置界面,如[图2](#fig744814574243)。 -- 使用单算子溢出检测功能时,请不要同时开启apex的动态loss scale模式和使用tensor融合功能。 + **图 2** 启动项工具 + ![](figures/启动项工具.png "启动项工具") -采集溢出算子数据: +3. 在启动项配置界面选择,选择“BIOS设置”,然后在虚拟界面工具栏中单击重启工具![](figures/zh-cn_image_0000001190201999.png),重启服务器。 +4. 系统重启后进入BIOS配置界面,依次选择“Advanced”\>“Socket Configuration”,如[图3](#fig4546303814)所示。 -``` -# check_overflow为溢出检测控制开关 -# dump_path为dump文件保存路径 -with torch.utils.dumper(check_overflow=check_overflow, dump_path=dump_path, load_file_path='') as dump: - # 需要检测算子溢出的代码片段 -``` + **图 3** Socket Configuration + ![](figures/Socket-Configuration.png "Socket-Configuration") -运行一个step,模型运行过程中,如果有算子溢出,会打印出相应IR的名字。 +5. 进入Advanced Power Mgmt. Configuration,设置Power Policy为Performance。如[图4](#fig15501111014442)。 -查看Dump数据: + **图 4** 设置电源策略 + ![](figures/设置电源策略.png "设置电源策略") -如果训练过程中采集到了Dump数据,则会在\{dump\_path\}路径下生成dump数据的.h5文件,用户可进入路径自行查看。 +6. 按下“F10”保存配置并重启服务器。 -解决方法: +**将CPU设置为performance模式** -1. 将采集到的.h5文件映射到TBE算子,映射方法请参见[IR与TBE算子映射](#IR与TBE算子映射)。 +请使用root用户执行如下操作。 -2. 请将算子溢出的打印截图及映射后的TBE算子输入输出文件通过Issue附件形式反馈给华为开发人员。 +1. 使用如下命令查看当前CPU模式。 -**IR与TBE算子映射** + ``` + cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + ``` -前提条件: + 执行以上命令会输出当前CPU模式,CPU模式说明请参见[表1](#table354392019384)。如果当前CPU模式不是performance模式,请执行以下操作设置CPU为performance模式。否则请跳过以下步骤。 -- 开启PyTorch框架dump功能。 + **表 1** CPU模式 - 在PyTorch源代码 “build.sh“ 文件中添加“USE\_DUMP=1”字段,编译安装PyTorch框架。 + + + + + + + + + + + + + + + + + + + + + + + + +

调速器

+

描述

+

performance

+

运行于最大频率。

+

powersave

+

运行于最小频率。

+

userspace

+

运行于用户指定的频率。

+

ondemand

+

按需快速动态调整CPU频率,一有CPU计算量的任务,就会立即达到最大频率运行,空闲时间增加就降低频率。

+

conservative

+

按需快速动态调整CPU频率,比ondemand的调整更保守。

+

schedutil

+

基于调度程序调整 CPU 频率。

+
-- 需要安装hdf5工具以支持算子dump功能,安装详情请参见[编译安装hdf5](#编译安装hdf5md)。 -- 设置环境变量`export ACL_DUMP_DATA=0`。 -- 在脚本中避免使用`torch.npu.init.dump()`和`torch.npu.set.dump()`接口。 +2. 安装工具,使用如下命令安装。 + - 以“ubuntu/debian“系统为例。 -操作步骤: + ``` + apt-get install linux-tools-$(uname -r) + ``` -1. 准备好需要映射的算子.h5文件。 + - 以“centos/bclinux/euler“系统为例: - - 算子溢出检测场景下,单算子溢出检测已生成需要映射的算子.h5文件。 + ``` + yum install kernel-tools -y + systemctl daemon-reload + systemctl enable cpupower + systemctl start cpupower + ``` - - 精度对比场景下,需根据精度对比结果,参照下面命令提取需要映射的算子.h5文件。 +3. 设置CPU为performance模式。 - ``` - h5copy -pv -i "./input.h5" -o "./output.h5" -s "/op1/seqid/" -d "/op1/seqid/" - ``` + ``` + cpupower frequency-set -g performance + ``` - -i 为输入精度对比文件 +4. 再次执行[步骤1](#li158435131344)查看当前CPU模式是否已设置为performance模式。 - -o 为输出需要映射的算子.h5文件路径 +
修改CPU性能模式(ARM服务器)
- -s 为需要提取的源算子名称及seqid +**设置电源策略为高性能模式** - -d 为需要提取的目的算子名称及seqid +在某些对Host侧CPU要求较高的模型中,例如目标检测类模型,需要进行较为复杂的图像预处理,开启电源高性能模式能一定程度上提高性能和稳定性。ARM服务器提升网络性能需要在BIOS设置中将电源策略设为高性能模式,具体操作如下。 - 若需要提取多个算子,则修改-s、-d参数,多次执行该命令,可以把多算子追加提取到output.h5中。 +1. 登录ibmc界面,启动虚拟控制台,远程控制选择HTML5集成远程控制台,如[图1](#fig15869135420288)。 - 该命令需-s和-d参数相同。 + **图 1** 远程登录控制台 + ![](figures/远程登录控制台-0.png "远程登录控制台-0") - 示例: +2. 在虚拟界面工具栏中,单击启动项工具![](figures/zh-cn_image_0000001190202013.png),弹出启动项配置界面,如[图2](#fig744814574243)。 - ``` - h5copy -pv -i "./dump_npu.h5" -o "./output.h5" -s "/numpy_T/1/" -d "/numpy_T/1/" - ``` + **图 2** 启动项工具 + ![](figures/启动项工具-1.png "启动项工具-1") - 该示例表示从“./dump_npu.h5”中抽取seqid为1的numpy_T算子的输入、输出数据到"./output.h5"文件中。 +3. 在启动项配置界面选择,选择“BIOS设置”,然后在虚拟界面工具栏中单击重启工具![](figures/zh-cn_image_0000001144082138.png),重启服务器。 +4. 系统重启后进入BIOS配置界面,依次选择“Advanced”\>“ Performance Config”,如[图3](#fig4546303814)所示。 -2. 配置acl.json文件。 + **图 3** Performance Config + ![](figures/Performance-Config.png "Performance-Config") - 在模型目录下创建acl dump功能所需的的配置文件acl.json +5. 进入“Performance Config”,设置Power Policy为Performance。如[图4](#fig15501111014442)。 - ``` - { - "dump": - { - "dump_list":[] - "dump_path":"./output_IR2TBE"# 映射结果输出路径 - "dump_mode":"all" - "dump_op_switch":"on" - } - - } - ``` + **图 4** 设置电源策略 + ![](figures/设置电源策略-2.png "设置电源策略-2") - 需将`dump_path`修改为结果输出路径,其他字段不需要修改。 +6. 按下“F10”保存配置并重启服务器。 -3. 修改训练脚本。 +
安装高性能pillow库(X86服务器)
- 在训练脚本中添加`with`语句开启IR映射TBE功能。 +1. 安装高性能pillow库相关依赖,命令如下。 - ```python - with torch.utils.dumper(use_load=True, dump_path="./",load_file_path="./output.h5", load_with_acl_dump=True) as dump: - # 模型计算代码,需用户自己添加 - # x = model(input_data) - ``` + ubuntu/debian: -4. 模型运行。 + ``` + apt-get install libtiff5-dev libjpeg8-dev libopenjp2-7-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk libharfbuzz-dev libfribidi-dev libxcb1-dev + ``` - 运行一步完整的模型计算过程,在计算过程中load遇到output.h5中的数据后,自动开启acl dump功能,执行IR,并dump出IR相对应的TBE算子的输入输出数据,IR执行结束,acl dump结束。 + centos/bclinux/euler: -5. 获得映射文件。 + ``` + yum install libtiff-devel libjpeg-devel openjpeg2-devel zlib-devel freetype-devel lcms2-devel libwebp-devel tcl-devel tk-devel harfbuzz-devel fribidi-devel libraqm-devel libimagequant-devel libxcb-devel + ``` - 运行成功后,在acl.json配置文件中的`dump_path`路径下查看输出结果文件。 +2. 安装高性能pillow库。 + 1. 执行如下命令卸载原生pillow。 -
整网调测
+ ``` + pip3.7 uninstall -y pillow + ``` -用户也可通过分析整个网络的方式来进行网络模型的精度调测。 + 2. 安装SSE4版本pillow-simd。 -1. 通过对比CPU和昇腾AI处理器的结果,判断在昇腾AI处理器上计算是否正确。 + 使用root用户安装,执行如下命令,若使用非root用户安装,需在命令结尾加上--user。 - 代码样例(本样例只体现基本方法,禁止直接复制)如下: + ``` + pip3.7 install pillow-simd + ``` - ``` - # 固定入参,保证模型与输入数据在CPU和昇腾AI处理器上相同 - input_tensor_cpu = torch.Tensor() - model_cpu = build_model() - # 将输入数据迁移到昇腾AI处理器上 - input_tensor_npu = input_tensor_cpu.npu() - # 将模型迁移到昇腾AI处理器上 - model_npu = model_cpu.npu() - - # 运算结果对比 - output_cpu = model_cpu(input_tensor_cpu) - output_npu = model_npu(input_tensor_npu) - compute_result = (output_cpu - output_npu).abs().mean()) - print(compute_result) - ``` + >![](public_sys-resources/icon-note.gif) **说明:** + >如果CPU支持AVX2指令集,可安装AVX2版本pillow-simd,命令如下: + >``` + >CC="cc -mavx2" pip3.7 install -U --force-reinstall pillow-simd + >``` - 因昇腾AI处理器硬件架构与cpu不同,计算结果会略有不同。若运算结果较为接近(一般不高于1e-4),则认为运算结果正常。 -2. 通过Pytorch的hook机制来打印正向反向传播中module的输入和输出来分析。 +3. 修改torchvision代码解决pillow-simd缺少PILLOW\_VERSION问题。torchvision安装参见[样例获取](#样例获取md)。 - 代码样例(本样例只体现基本方法,禁止直接复制)如下: + 将/usr/local/python3.x.x/lib/python3.x/site-packages/torchvision/transforms/functional.py第5行代码修改如下: ``` - # 设置hook func - def hook_func(name, module): - def hook_function(module, inputs, outputs): - print(name+' inputs', inputs) - print(name+' outputs', outputs) - return hook_function - - # 注册正反向hook - for name, module in model.named_modules(): - module.register_forward_hook(hook_func('[forward]: '+name, module)) - module.register_backward_hook(hook_func('[backward]: '+name, module)) - - # 运行 - model(input_tensor) + try: + from PIL import Image, ImageOps, ImageEnhance,PILLOW_VERSION + except: + from PIL import Image, ImageOps, ImageEnhance + PILLOW_VERSION="7.0.0" ``` - 通过分析打印正向反向传播中的inputs, outputs来确定。 -3. 通过直接获取module的grad, running\_mean, running\_var等参数来分析更新量。 +
(可选)安装指定版本OpenCV库
- 代码样例(本样例只体现基本方法,禁止直接复制)如下: +如模型依赖OpenCV,基于训练性能考虑,建议安装OpenCV-3.4.10版本。 - ``` - # 例如获取梯度和BN的均值方法来排查 - for name, module in model.named_modules(): - if isinstance(module, nn._BatchNorm): - print("[BN_buffer]: "+name, module.running_mean, module.running_var) - print("[grad]: "+name, module.grad) - ``` +1. 获取源码:[获取地址](https://opencv.org/releases/)。 +2. 安装指导:[获取地址](https://docs.opencv.org/3.4.10/d7/d9f/tutorial_linux_install.html)。 +

训练过程性能优化

-

模型保存与转换

+**算子瓶颈优化** -- **[简介](#简介md)** +1. 获取训练过程中的Profiling数据,参见[Profiling数据采集](#采集训练过程相关数据md)。 +2. 分析Profiling数据,得到耗时较大的算子。 +3. 参见[单算子样例编写说明](#单算子样例编写说明md)构建耗时较大算子的单算子样例,通过与CPU或GPU运行单算子样例时间进行对比,若发现性能不足,则有以下两种方案解决。 + - 规避方案:使用同等语义其他高效算子替代。 + - 解决方案:改进算子性能。 -- **[模型保存](#模型保存md)** +**copy瓶颈优化** -- **[导出ONNX模型](#导出ONNX模型md)** +1. 获取训练过程中的Profiling数据,参见[Profiling数据采集](#采集训练过程相关数据md)。 +2. 分析Profiling数据分析整网中的D2DCopywithStreamSynchronize/PTCopy/format\_contiguous的耗时。 +3. 若发现耗时较大,则需参照以下两种方案解决。 + - 方案一:(规避方案)PyTorch中View类型框架类算子会导致非连续转连续操作。优化思路为尽量使用计算类算子代替View类框架算子,常见的View类框架算子如View、Permute、Transpose等。更多View类框架算子可参考[https://pytorch.org/docs/stable/tensor\_view.html](https://pytorch.org/docs/stable/tensor_view.html)。 + - 方案二:(解决方案)加速转连续操作。 +**框架瓶颈优化** -

简介

+1. 获取训练过程中算子信息OP\_INFO,参见[获取算子信息OP\_INFO](#采集训练过程相关数据md)。 +2. 分析OP\_INFO中算子的规格和调用关系,定位是否插入了多余的算子,重点关注transdata是否合理。 +3. 优化方案:通过指定部分算子初始化格式,对多余的格式转换算子进行消除。 +4. 在pytorch/torch/nn/modules/module.py中,在cast\_weight中指定算子初始化格式,如下图。 -模型训练完成后,通过Pytorch提供的接口保存模型文件并导出ONNX模型,然后通过ATC工具将其转换为适配昇腾AI处理器的.om文件用于离线推理。 + ![](figures/指定算子初始化方式.png) -本章主要介绍如何将训练好的pth文件pth.tar文件转换为ONNX模型,将ONNX模型转换为适配昇腾AI处理器的.om文件流程请参考《CANN 开发辅助工具指南》手册中“ATC工具使用指南”章节。 + 格式设置原则可参考如下规则: -如果想使用Auto Tune优化功能,请参考《CANN 开发辅助工具指南》手册中“Auto Tune工具使用指导”章节。 + - Conv2D相关:Weight 可设置为FZ格式,如第424行。 + - Linear相关的参数,可设置为NZ格式,如第409行。 -离线推理应用构建请参考《CANN 应用软件开发指南\(C&C++, 推理\)》。整体流程如下: +**编译瓶颈优化** -![](figures/zh-cn_image_0000001144082132.png) +1. 获取训练过程中算子信息OP\_INFO,参见[获取算子信息OP\_INFO](#采集训练过程相关数据md)。 +2. 查看INFO日志,观察第一个step以后的aclopCompile::aclOp关键字,如果后续接了Match op inputs/type failed或To compile op则说明该算子存在动态编译,需要优化。 +3. 需参照以下两种方案解决。 + - 规避方案:在理解模型语义和相关API基础上,使用固定Shape的方式代替动态Shape。 + - 解决方案:减少编译或不需要编译该算子。 + - 优化算子编译配置请参见[编译选项设置](#编译选项设置md)。 -

模型保存

-Pytorch在训练过程中,通常使用torch.save\(\)来保存Checkpoint文件,根据模型文件的后续用途会保存为两种格式的模型文件: +

亲和库

-- .pth或.pt扩展名的文件:用于在线推理或导出ONNX格式模型,仅保存模型参数,不保存模型结构,以便压缩文件的体积,可以用Netron等可视化工具打开,一般如[图1 .pth文件](#fig315704722610)所示。 - **图 1** .pth文件 - ![](figures/pth文件.jpg "pth文件") +

来源介绍

- 通过**state\_dict**来保存和加载模型,示例如下: +针对公版模型中常见的网络结构和函数,我们针对性地对其进行了优化,使得运算性能大幅度提升,同时,将其集成到Pytorch框架中,便于模型性能调优中使用。 - 1. 保存模型。 +

功能介绍

- ``` - # 创建保存路径 - PATH = "state_dict_model.pt" - # 保存模型 - torch.save(net.state_dict(), PATH) - ``` + + + + + + + + + + + + + + + + + + + + + + + +

函数名

+

位置

+

功能说明

+

pairwise_iou

+

torch.contrib.npu.optimized_lib

+

计算两个目标框的IOU。

+

fast_rcnn_inference_single_image

+

torch.contrib.npu.optimized_lib

+

Maskrcnn和Fasterrcnn模型的推理接口。

+

ChannelShuffle

+

torch.contrib.npu.optimized_lib

+

提供NPU亲和的channelshuffle操作,适用于shufflenetv2等模型。

+

PreLoader

+

torch.contrib.npu.optimized_lib

+

提供针对昇腾AI处理器加速的数据加载方法。

+
- 2. 加载模型以用于在线推理,示例如下,详情请参见《PyTorch在线推理指南》。 +>![](public_sys-resources/icon-note.gif) **说明:** +>该部分调优内容会随着版本不断增强和更新,请以实际PyTorch版本中对应路径下的内容为准。 - ``` - # 模型文件保存路径 - PATH = "state_dict_model.pt" - model = TheModelClass(*args, **kwargs) - # 加载模型 - model.load_state_dict(torch.load(PATH)) - model.eval() - ``` +

精度调测

- >![](public_sys-resources/icon-notice.gif) **须知:** - >保存.pth或.pt文件扩展名的文件时要提供模型定义文件,否则无法部署。 -- .pth.tar扩展名的文件:可用于在线推理或重新加载后继续训练。保存多个组件,以字典形式保存,常见的组件包括模型和优化器的state\_dict、停止时的epoch、最新记录的训练损失以及外部的torch.nn.Embedding层等。如果仅用于部署推理模型,推荐只在.pth.tar扩展名的文件中保存权重信息即模型的state\_dict。 +

前提条件

- 保存和加载模型示例如下: +优先在同等语义和超参下,跑一定的epoch(推荐完整epoch数的20%),使精度,loss等对齐GPU相应水平,完成后再对齐最终精度。 - 1. 保存模型。 +

调测过程

- ``` - PATH = "checkpoint.pth.tar" - torch.save({ - 'epoch': epoch, - 'loss': loss, - 'state_dict': model.state_dict(), - 'optimizer' : optimizer.state_dict(), - ... - }, PATH) - ``` +- **[总体思路](#总体思路-4md)** - 2. 加载模型用于推理或恢复训练。 +- **[精度调优方法](#精度调优方法md)** - ``` - model = TheModelClass(*args, **kwargs) - optimizer = TheOptimizerClass(*args, **kwargs) - - checkpoint = torch.load(PATH) - model.load_state_dict(checkpoint['model_state_dict']) - optimizer.load_state_dict(checkpoint['optimizer_state_dict']) - epoch = checkpoint['epoch'] - loss = checkpoint['loss'] - - model.eval() - # - or - - model.train() - ``` +

总体思路

+精度问题排查需要找出是哪一步出现的问题,主要以下几个方面: ->![](public_sys-resources/icon-notice.gif) **须知:** ->通常情况下,训练图和推理图中对同一个算子处理方式不同(例如BatchNorm和dropout等算子),在输入格式上也有差别,因此在运行推理或导出ONNX模型之前,必须调用model.eval\(\) 来将dropout和batch normalization层设置为推理模式。 +1. 模型网络计算错误。 + - 定位思路:在网络中加入hook进行排查判断是哪个地方有较大嫌疑,然后构建[单算子用例](#单算子样例编写说明md)逐渐缩小错误范围,证明该算子在当前网络场景下计算有误,可以对比CPU或GPU结果证明。 -

导出ONNX模型

+ - 规避方案:使用同等语义其他算子替代。 -**简介** + - 解决方案:改进算子精度或功能问题。 -昇腾AI处理器Pytorch模型的部署策略是基于Pytorch官方支持的ONNX模块实现的。ONNX是业内目前比较主流的模型格式,广泛用于模型交流及部署。本节主要介绍如何将Checkpoint文件通过torch.onnx.export\(\)接口导出为ONNX模型。 +2. loss计算错误。 + - 定位思路:由于Loss的特殊性和可以自定义,在判断Loss计算错误后建议dump网络中的loss的输入来测试而非随机同shape tensor,这样才能更好地复现证明。 -**.pth或.pt文件导出ONNX模型** + - 规避方案:使用同等语义其他算子替代。 -保存的.pth或.pt文件可以通过Pytorch构建模型再加载权重的方法恢复,然后导出ONNX模型,样例如下。 + - 解决方案:改进算子精度或功能问题(loss也是由算子构成)。 -``` -import torch -import torch.onnx -import torchvision.models as models -# 设置使用CPU导出模型 -device = torch.device("cpu") - -def convert(): - # 模型定义来自于torchvision,样例生成的模型文件是基于resnet50模型 - model = models.resnet50(pretrained = False) - resnet50_model = torch.load('resnet50.pth', map_location='cpu') - model.load_state_dict(resnet50_model) - - batch_size = 1 #批处理大小 - input_shape = (3, 224, 224) #输入数据,改成自己的输入shape +3. 参数更新错误。 - # 模型设置为推理模式 - model.eval() + - 定位思路:在每个optim.step\(\)前对网络中的参数逐个打印其grad进行排查判断是哪个地方有较大嫌疑,然后构建单算子用例逐渐缩小错误范围,证明该算子在当前网络场景下梯度计算有误,可以对比CPU或GPU结果证明。该项优先级应低于[1.](#li17755175510322)与[2.](#li25281726103316),因为1与2的错误同样可以造成grad异常。 - dummy_input = torch.randn(batch_size, *input_shape) # 定义输入shape - torch.onnx.export(model, - dummy_input, - "resnet50_official.onnx", - input_names = ["input"], # 构造输入名 - output_names = ["output"], # 构造输出名 - opset_version=11, # ATC工具目前仅支持opset_version=11 - dynamic_axes={"input":{0:"batch_size"}, "output":{0:"batch_size"}}) #支持输出动态轴 - ) - -if __name__ == "__main__": - convert() -``` + - 规避方案:使用同等语义其他算子替代。 ->![](public_sys-resources/icon-note.gif) **说明:** ->- 在导出ONNX模型之前,必须调用model.eval\(\) 来将dropout和batch normalization层设置为推理模式。 ->- 样例脚本中的model来自于torchvision模块中的定义,用户使用自己的模型时需自行指定。 ->- 构造输入输出需要对应训练时的输入输出,否则无法正常推理。 + - 解决方案:改进计算grad的算子精度或功能问题。 -**.pth.tar文件导出ONNX模型** +4. 多卡计算错误。 -.pth.tar在导出ONNX模型时需要先确定保存时的信息,有时保存的节点名称和模型定义中的节点会有差异,例如会多出前缀和后缀。在进行转换的时候,可以对节点名称进行修改。转换代码样例如下。 + - 定位思路:在保证单卡精度OK的前提下,稳定复现多卡不收敛。 -``` -import torch -import torch.onnx -from collections import OrderedDict -import mobilenet + - 解决方案:建议联系华为方支撑人员,提供稳定复现的单P和多P脚本。 -# 本样例中的pth.tar文件保存时节点名加了前缀module,通过遍历删除 -def proc_nodes_module(checkpoint, AttrName): - new_state_dict = OrderedDict() - for key, value in checkpoint[AttrName].items(): - if key == "module.features.0.0.weight": - print(value) - if(key[0:7] == "module."): - name = key[7:] - else: - name = key[0:] +

精度调优方法

- new_state_dict[name] = value - return new_state_dict +模型出现精度问题一般有:因算子溢出导致的训练loss不收敛或者精度不达标问题,整个网络训练引起的性能不达标问题。用户可通过单算子溢出检测和整网调测适度解决模型精度不达标问题。 -def convert(): - checkpoint = torch.load("./mobilenet_cpu.pth.tar", map_location=torch.device('cpu')) - checkpoint['state_dict'] = proc_nodes_module(checkpoint,'state_dict') - model = mobilenet.mobilenet_v2(pretrained = False) - model.load_state_dict(checkpoint['state_dict']) - model.eval() - input_names = ["actual_input_1"] - output_names = ["output1"] - dummy_input = torch.randn(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, "mobilenetV2_npu.onnx", input_names = input_names, output_names = output_names, opset_version=11) +- **[环境准备](#环境准备md)** +- **[模型算子精度对比](模型算子精度对比)** +- **[单算子溢出检测](#单算子溢出检测md)** +- **[IR与TBE算子映射](IR与TBE算子映射)** +- **[NPU与GPU算子映射](NPU与GPU算子映射)** +- **[整网调测](#整网调测md)** -if __name__ == "__main__": - convert() -``` +##### 环境准备 + +- 安装hdf5工具以支持算子dump功能,安装详情请参见[编译安装hdf5](#编译安装hdf5md)。 + + 若使用模型算子精度对比功能,需要同时在NPU和GPU环境安装hdf5。否则,仅在NPU环境安装hdf5即可。 -

样例说明

+- 安装支持dump功能的Ascend PyTorch框架,编译前请修改build.sh脚本,其余操作请参见《PyTorch安装指南》。 -- **[ResNet50模型迁移示例](#ResNet50模型迁移示例md)** + - 在NPU环境PyTorch安装 -- **[ShuffleNet模型调优示例](#ShuffleNet模型调优示例md)** + 编译前修改build.sh脚本,在脚本中增加`USE_DUMP=1`字段。 + ```bash + DEBUG=0 USE_DISTRIBUTED=1 USE_HCCL=1 USE_MKLDNN=0 USE_CUDA=0 USE_NPU=1 BUILD_TEST=0 USE_NNPACK=0 USE_DUMP=1 python"${PY_VERSION}" setup.py build bdist_wheel + ``` + + - (可选)在GPU环境PyTorch安装,若对模型算子精度对比,请执行此操作,否则请忽略。 -

ResNet50模型迁移示例

+ 编译前修改build.sh,在脚本中增加`USE_DUMP=1`、`USE_NCCL=0`字段,将 `USE_HCCL`、`USE_NPU`字段的值修改为0,将`USE_CUDA`字段的值修改为1。 + + ```bash + DEBUG=0 USE_DISTRIBUTED=1 USE_HCCL=0 USE_NCCL=0 USE_MKLDNN=0 USE_CUDA=1 USE_NPU=0 BUILD_TEST=0 USE_NNPACK=0 USE_DUMP=1 python"${PY_VERSION}" setup.py build bdist_wheel + ``` -- **[样例获取](#样例获取md)** +##### 模型算子精度对比 -- **[训练脚本迁移](#训练脚本迁移md)** +用户使用精度对比工具,在相同输入的情况下,获取模型在GPU和NPU进行训练时模型内算子输出的精度差异,从而帮助开发者实现算子精度问题定位。 -- **[脚本执行](#脚本执行md)** +约束说明: +- 建议使用小batchsize,一般设置为8及以下。 -

样例获取

+ 由于每个算子输入、输出数据会存储在硬盘中,会占用较大空间,故建议使用小batchsize节省硬盘空间。 -样例获取 +- 建议仅dump一个step的数据进行精度对比。 -1. 本样例基于PyTorch官网提供的Imagenet数据集训练模型进行适配昇腾910 AI处理器的迁移改造,样例获取路径为[https://github.com/pytorch/examples/tree/master/imagenet](https://github.com/pytorch/examples/tree/master/imagenet)。 -2. 本样例依赖torchvision,需要安装torchvision依赖,如果使用非root用户安装, 则需在命令末尾加上**--user**。 +- 目前支持精度为fp32、O1或O2训练过程的算子精度对比。 - 当服务器运行环境为X86架构时,安装命令如下: +对比模式: - ``` - pip3.7 install torchvision==0.6.0 --no-deps - ``` +- GPU的输入和输出为已知数据,将GPU的输入数据加载到NPU上执行得到输出数据,NPU与GPU输出数据对比。 +- NPU的输入和输出为已知数据,将NPU的输入数据加载到GPU上执行得到输出数据,NPU与GPU输出数据对比。 - 当服务器运行环境为ARM架构时,安装命令如下: +操作步骤: - ``` - pip3.7 install torchvision==0.2.2.post3 --no-deps - ``` +1. 在GPU或NPU环境,使用dumper工具获取GPU或NPU的模型输入和算子输出数据。 -3. Resnet50模型参考PyTorch官网模型[https://pytorch.org/hub/pytorch\_vision\_resnet/](https://pytorch.org/hub/pytorch_vision_resnet/),实际使用有如下两种方式。 - 1. 直接调用对应接口,例如: + 修改训练代码,增加数据dump功能。在模型训练代码的正向、反向计算位置使用`with`语句增加`torch.utils.dumper()`方法dump数据。例如,在GPU环境下修改示例: - ``` - import torchvision.models as models - model = models.resnet50() - ``` + ```python + for i, data in enumerate(dataloader): + with torch.utils.dumper(use_dump=True, dump_path="./model_gpu.h5") as dump: + # 模型训练代码 + xxx # forward code + xxx # backward code + exit() + xxx # optimizer code + ``` - >![](public_sys-resources/icon-note.gif) **说明:** - >Resnet50为PyTorch内置模型,了解更多内置模型请前往[Pytorch官网](https://pytorch.org/)。 + dump_path参数为dump数据保存文件路径及名称。建议仅dump一个step的数据用于精度对比,同时参数更新代码放在with语句外。 - 2. 在脚本执行中直接指定参数arch为resnet50,内容如下,本样例迁移采用该种方式,请参见[脚本执行](#脚本执行md)。 +2. 将在GPU(NPU)环境dump的数据model_gpu.h5拷贝到NPU(GPU)环境。 - ``` - --arch resnet50 - ``` +3. 在NPU或NPU环境,使用dumper工具加载已经dump出的数据,并获取算子输出数据。 + 修改训练代码,增加数据load、dump功能。在模型训练代码的正向、反向计算位置使用`with`语句增加`torch.utils.dumper()`方法load、dump数据。例如,在NPU环境下修改示例: + ```python + for i, data in enumerate(dataloader): + with torch.utils.dumper(use_dump=True, load_file_path="./model_gpu.h5", dump_path="./model_npu.h5") as dump: + # 模型训练代码 + xxx # forward code + xxx # backward code + exit() + xxx # optimizer code + ``` -目录结构 + load_file_path参数为从GPU或NPU获取的dump数据路径,dump_path参数为dump数据保存文件路径及名称。建议仅dump一个step的数据用于精度对比,同时参数更新代码放在with语句外。 -主要文件目录结构如下所示: +4. 使用msaccucmp.py对算子输出数据对比。 -``` -├──main.py -``` + 1. ascend-toolkit提供了msaccucmp.py工具脚本用具精度对比。 -

训练脚本迁移

+ - 该脚本路径为:"/user/local/Ascend/ascend-toolkit/latest/tools/operator_cmp/compare/msaccucmp.py", -- **[单P训练修改](#单P训练修改md)** + 路径仅供参考,请以ascend-toolkit实际安装路径为准。 -- **[分布式训练修改](#分布式训练修改md)** + - 也可以使用如下命令查找msaccucmp.py路径。 + ```linux + find / -name msaccucmp.py + ``` -
单P训练修改
+ 2. 执行msaccucmp.py脚本,进行精度对比。 -1. main.py增加头文件以支持基于PyTorch框架的模型在昇腾910 AI处理器上训练: + ``` + python3 /user/local/Ascend/ascend-toolkit/latest/tools/operator_cmp/compare/msaccucmp.py compare -m ./model_npu.h5 -g ./model_gpu.h5 + ``` - ``` - import torch.npu - ``` + 参数说明: -2. 在main.py文件中头文件后添加参数以指定使用昇腾910 AI处理器进行训练: + `-g`参数传入使用GPU获得的dump数据文件路径。 - ``` - CALCULATE_DEVICE = "npu:1" - ``` + `-m`参数传入使用NPU获得的dump数据文件路径。 -3. 修改参数以及判断选项,使其只在昇腾910 AI处理器上进行训练。 - 代码位置:main.py文件中的main\_worker\(\)函数(修改部分为字体加粗部分): +
单算子溢出检测
- ``` - def main_worker(gpu, ngpus_per_node, args): - global best_acc1 - # 原代码为使用GPU进行训练,原代码如下: - # args.gpu = gpu - ############## npu modify begin ############# - args.gpu = None - ############## npu modify end ############# - if args.gpu is not None: - print("Use GPU: {} for training".format(args.gpu)) - - if args.distributed: - if args.dist_url == "env://" and args.rank == -1: - args.rank = int(os.environ["RANK"]) - if args.multiprocessing_distributed: - # For multiprocessing distributed training, rank needs to be the - # global rank among all the processes - args.rank = args.rank * ngpus_per_node + gpu - dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - # create model - if args.pretrained: - print("=> using pre-trained model '{}'".format(args.arch)) - model = models.__dict__[args.arch](pretrained=True) - else: - print("=> creating model '{}'".format(args.arch)) - model = models.__dict__[args.arch]() - # 原代码中需要判断是否在GPU上进行训练,原代码如下: - # if not torch.cuda.is_available(): - # print('using CPU, this will be slow') - # elif args.distributed: - ############## npu modify begin ############# - # 迁移后为直接判断是否进行分布式训练,去掉判断是否在GPU上进行训练 - if args.distributed: - ############## npu modify end ############# - # For multiprocessing distributed, DistributedDataParallel constructor - # should always set the single device scope, otherwise, - # DistributedDataParallel will use all available devices. - if args.gpu is not None: - ...... - ``` +用户通过算子溢出检测功能检测算子是否有溢出,然后采集溢出算子的数据,从而帮助开发人员快速定位并解决算子精度问题。 -4. 将模型以及损失函数迁移到昇腾910 AI处理器上进行计算。 +约束说明: - 代码位置:main.py文件中的main\_worker\(\)函数(修改部分为字体加粗部分): +- 本功能只提供IR级别的算子溢出检测,且只支持AICORE,不支持Atomic。 +- 使用单算子溢出检测功能时,请不要同时开启apex的动态loss scale模式和使用tensor融合功能。 - ``` - elif args.gpu is not None: - torch.cuda.set_device(args.gpu) - model = model.cuda(args.gpu) - else: - # DataParallel will divide and allocate batch_size to all available GPUs - if args.arch.startswith('alexnet') or args.arch.startswith('vgg'): - model.features = torch.nn.DataParallel(model.features) - model.cuda() - else: - # 原代码使用torch.nn.DataParallel()类来用多个GPU加速训练 - # model = torch.nn.DataParallel(model).cuda() - ############## npu modify begin ############# - # 将模型迁移到NPU上进行训练。 - model = model.to(CALCULATE_DEVICE) - ############## npu modify end ############# - # 原代码中损失函数是在GPU上进行计算 - # # define loss function (criterion) and optimizer - # criterion = nn.CrossEntropyLoss().cuda(args.gpu) - ############## npu modify begin ############# - # 将损失函数迁移到NPU上进行计算。 - criterion = nn.CrossEntropyLoss().to(CALCULATE_DEVICE) - ############## npu modify end ############# - ``` +采集溢出算子数据: -5. 将数据集目标结果target修改成int32类型解决算子报错问题;将数据集迁移到昇腾910 AI处理器上进行计算。 - - 代码位置:main.py文件中的train\(\)函数(修改部分为字体加粗部分): +``` +# check_overflow为溢出检测控制开关 +# dump_path为dump文件保存路径 +with torch.utils.dumper(check_overflow=check_overflow, dump_path=dump_path, load_file_path='') as dump: + # 需要检测算子溢出的代码片段 +``` - ``` - for i, (images, target) in enumerate(train_loader): - # measure data loading time - data_time.update(time.time() - end) - - if args.gpu is not None: - images = images.cuda(args.gpu, non_blocking=True) - # 原代码中训练数据集在GPU上进行加载计算,原代码如下: - # if torch.cuda.is_available(): - # target = target.cuda(args.gpu, non_blocking=True) - ############## npu modify begin ############# - # 将数据集迁移到NPU上进行计算并修改target数据类型,以提升性能 - if 'npu' in CALCULATE_DEVICE: - target = target.to(torch.int32) - images, target = images.to(CALCULATE_DEVICE, non_blocking=True), target.to(CALCULATE_DEVICE, non_blocking=True) - ############## npu modify end ############# - ``` +运行一个step,模型运行过程中,如果有算子溢出,会打印出相应IR的名字。 - - 代码位置:main.py文件中的validate\(\)函数(修改部分为字体加粗部分): +查看Dump数据: - ``` - with torch.no_grad(): - end = time.time() - for i, (images, target) in enumerate(val_loader): - if args.gpu is not None: - images = images.cuda(args.gpu, non_blocking=True) - # 原代码中训练数据集在GPU上进行加载计算,原代码如下: - # if torch.cuda.is_available(): - # target = target.cuda(args.gpu, non_blocking=True) - ############## npu modify begin ############# - # 将数据集迁移到NPU上进行计算并修改target数据类型 - if 'npu' in CALCULATE_DEVICE: - target = target.to(torch.int32) - images, target = images.to(CALCULATE_DEVICE, non_blocking=True), target.to(CALCULATE_DEVICE, non_blocking=True) - ############## npu modify end ############# - ``` +如果训练过程中采集到了Dump数据,则会在\{dump\_path\}路径下生成dump数据的.h5文件,用户可进入路径自行查看。 -6. 设置当前正在使用的device。 +解决方法: - 代码位置:main.py文件中的主函数入口(修改部分为字体加粗部分): +1. 将采集到的.h5文件映射到TBE算子,映射方法请参见[IR与TBE算子映射](#IR与TBE算子映射)。 - ``` - if __name__ == '__main__': - ############## npu modify begin ############# - if 'npu' in CALCULATE_DEVICE: - torch.npu.set_device(CALCULATE_DEVICE) - ############## npu modify begin ############# - main() - ``` +2. 请将算子溢出的打印截图及映射后的TBE算子输入输出文件通过Issue附件形式反馈给华为开发人员。 +##### IR与TBE算子映射 -
分布式训练修改
+前提条件: -1. main.py增加头文件以支持基于PyTorch框架的模型在昇腾910 AI处理器上训练及进行混合精度训练。 +- 设置环境变量`export ACL_DUMP_DATA=0`。 +- 在脚本中避免使用`torch.npu.init.dump()`和`torch.npu.set.dump()`接口。 - ``` - import torch.npu - from apex import amp - ``` +操作步骤: -2. 参数设置增加以下参数,包括指定参与训练的昇腾910 AI处理器以及进行混合精度训练需要的参数。 +1. 准备好需要映射的算子.h5文件。 - ``` - parser.add_argument('--device', default='npu', type=str, help='npu or gpu') - parser.add_argument('--addr', default='10.136.181.115', type=str, help='master addr') - parser.add_argument('--device-list', default='0,1,2,3,4,5,6,7', type=str, help='device id list') - parser.add_argument('--amp', default=False, action='store_true', help='use amp to train the model') - parser.add_argument('--loss-scale', default=1024., type=float, - help='loss scale using in amp, default -1 means dynamic') - parser.add_argument('--opt-level', default='O2', type=str, - help='loss scale using in amp, default -1 means dynamic') - ``` + - 算子溢出检测场景下,单算子溢出检测已生成需要映射的算子.h5文件。 -3. 创建由device\_id到process\_id的映射函数,指定device进行训练。在main.py函数中增加以下接口。 + - 精度对比场景下,需根据精度对比结果,参照下面命令提取需要映射的算子.h5文件。 - ``` - def device_id_to_process_device_map(device_list): - devices = device_list.split(",") - devices = [int(x) for x in devices] - devices.sort() - - process_device_map = dict() - for process_id, device_id in enumerate(devices): - process_device_map[process_id] = device_id - - return process_device_map - ``` + ``` + h5copy -pv -i "./input.h5" -o "./output.h5" -s "/op1/seqid/" -d "/op1/seqid/" + ``` -4. 指定训练服务器的ip和端口。 + -i 为输入精度对比文件 - 代码位置:main.py文件中的主函数main\(\)(修改部分为字体加粗部分)。 + -o 为输出需要映射的算子.h5文件路径 - ``` - def main(): - args = parser.parse_args() - ############## npu modify begin ############# - os.environ['MASTER_ADDR'] = args.addr - os.environ['MASTER_PORT'] = '29688' - ############## npu modify end ############# - ``` + -s 为需要提取的源算子名称及seqid -5. 创建由device\_id到process\_id的映射参数,获取单节点昇腾910 AI处理器数量。 + -d 为需要提取的目的算子名称及seqid - 代码位置:main.py文件中的主函数main\(\)(修改部分为字体加粗部分)。 + 若需要提取多个算子,则修改-s、-d参数,多次执行该命令,可以把多算子追加提取到output.h5中。 - ``` - args.distributed = args.world_size > 1 or args.multiprocessing_distributed - ############## npu modify begin ############# - args.process_device_map = device_id_to_process_device_map(args.device_list) - if args.device == 'npu': - ngpus_per_node = len(args.process_device_map) - else: - ngpus_per_node = torch.cuda.device_count() - ############## npu modify end ############# - # 原代码如下: - # ngpus_per_node = torch.cuda.device_count() - ``` + 该命令需-s和-d参数相同。 -6. 获取进程process\_id对应的昇腾910 AI处理器编号,指定在对应的昇腾910 AI处理器上进行训练。 + 示例: - 代码位置:main.py文件中的main\_worker\(\)(修改部分为字体加粗部分)。 + ``` + h5copy -pv -i "./dump_npu.h5" -o "./output.h5" -s "/numpy_T/1/" -d "/numpy_T/1/" + ``` - ``` - def main_worker(gpu, ngpus_per_node, args): - global best_acc1 - ############## npu modify begin ############# - args.gpu = args.process_device_map[gpu] - ############## npu modify end ############# - # 原代码如下: - # args.gpu = gpu - ``` + 该示例表示从“./dump_npu.h5”中抽取seqid为1的numpy_T算子的输入、输出数据到"./output.h5"文件中。 -7. 初始化进程组,屏蔽掉初始化方式。 +2. 配置acl.json文件。 - 代码位置:main.py文件中的main\_worker\(\)(修改部分为字体加粗部分)。 + 在模型目录下创建acl dump功能所需的的配置文件acl.json - ``` - ############## npu modify begin ############# - if args.device == 'npu': - dist.init_process_group(backend=args.dist_backend, #init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - else: - dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - ############## npu modify begin ############# - # 原代码如下: - # dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - ``` + ``` + { + "dump": + { + "dump_list":[] + "dump_path":"./output_IR2TBE"# 映射结果输出路径 + "dump_mode":"all" + "dump_op_switch":"on" + } + + } + ``` -8. 要进行分布式训练且需要引入混合精度模块,并且需要将模型迁移到昇腾AI处理器上,因此需要屏蔽掉原始代码中判断是否为分布式训练以及模型是否在GPU上进行训练的代码部分。 + 需将`dump_path`修改为结果输出路径,其他字段不需要修改。 - 代码位置:main.py文件中的main\_worker\(\)(修改部分为字体加粗部分)。 +3. 修改训练脚本。 - ``` - # create model - if args.pretrained: - print("=> using pre-trained model '{}'".format(args.arch)) - model = models.__dict__[args.arch](pretrained=True) - else: - print("=> creating model '{}'".format(args.arch)) - model = models.__dict__[args.arch]() - ############## npu modify begin ############# - # 代码中添加如下内容 - # 指定训练设备为昇腾AI处理器 - loc = 'npu:{}'.format(args.gpu) - torch.npu.set_device(loc) - # 计算用于训练的batch_size和workers - args.batch_size = int(args.batch_size / ngpus_per_node) - args.workers = int((args.workers + ngpus_per_node - 1) / ngpus_per_node) - ############## npu modify end ############# - # 原始代码如下,需屏蔽掉,已注释 - # if not torch.cuda.is_available(): - # print('using CPU, this will be slow') - # elif args.distributed: - # # For multiprocessing distributed, DistributedDataParallel constructor - # # should always set the single device scope, otherwise, - # # DistributedDataParallel will use all available devices. - # if args.gpu is not None: - # torch.cuda.set_device(args.gpu) - # model.cuda(args.gpu) - # # When using a single GPU per process and per - # # DistributedDataParallel, we need to divide the batch size - # # ourselves based on the total number of GPUs we have - # args.batch_size = int(args.batch_size / ngpus_per_node) - # args.workers = int((args.workers + ngpus_per_node - 1) / ngpus_per_node) - # model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu]) - # else: - # model.cuda() - # # DistributedDataParallel will divide and allocate batch_size to all - # # available GPUs if device_ids are not set - # model = torch.nn.parallel.DistributedDataParallel(model) - # elif args.gpu is not None: - # torch.cuda.set_device(args.gpu) - # model = model.cuda(args.gpu) - # else: - # # DataParallel will divide and allocate batch_size to all available GPUs - # if args.arch.startswith('alexnet') or args.arch.startswith('vgg'): - # model.features = torch.nn.DataParallel(model.features) - # model.cuda() - # else: - # model = torch.nn.DataParallel(model).cuda() - ``` + 在训练脚本中添加`with`语句开启IR映射TBE功能。 -9. 屏蔽掉损失函数、优化器和断点训练部分,将这部分在后面与混合精度训练结合起来。 + ```python + with torch.utils.dumper(use_load=True, dump_path="./",load_file_path="./output.h5", load_with_acl_dump=True) as dump: + # 模型计算代码,需用户自己添加 + # x = model(input_data) + ``` - 代码位置:main.py文件中的main\_worker\(\)(修改部分为字体加粗部分)。 +4. 模型运行。 - ``` - # 屏蔽掉原始代码,已注释 - # # define loss function (criterion) and optimizer - # criterion = nn.CrossEntropyLoss().cuda(args.gpu) - # - # optimizer = torch.optim.SGD(model.parameters(), args.lr, - # momentum=args.momentum, - # weight_decay=args.weight_decay) - # - # # optionally resume from a checkpoint - # if args.resume: - # if os.path.isfile(args.resume): - # print("=> loading checkpoint '{}'".format(args.resume)) - # if args.gpu is None: - # checkpoint = torch.load(args.resume) - # else: - # # Map model to be loaded to specified single gpu. - # loc = 'cuda:{}'.format(args.gpu) - # checkpoint = torch.load(args.resume, map_location=loc) - # args.start_epoch = checkpoint['epoch'] - # best_acc1 = checkpoint['best_acc1'] - # if args.gpu is not None: - # # best_acc1 may be from a checkpoint from a different GPU - # best_acc1 = best_acc1.to(args.gpu) - # model.load_state_dict(checkpoint['state_dict']) - # optimizer.load_state_dict(checkpoint['optimizer']) - # print("=> loaded checkpoint '{}' (epoch {})" - # .format(args.resume, checkpoint['epoch'])) - # else: - # print("=> no checkpoint found at '{}'".format(args.resume)) - # - # cudnn.benchmark = True - ``` + 运行一步完整的模型计算过程,在计算过程中load遇到output.h5中的数据后,自动开启acl dump功能,执行IR,并dump出IR相对应的TBE算子的输入输出数据,IR执行结束,acl dump结束。 -10. 数据加载器,结合了数据集和取样器,并且可以提供多个线程处理数据集。使用昇腾AI处理器进行训练,需要将**pin\_memory**设置为**False**;由于当前仅支持固定shape下的训练,数据流中剩余的样本数可能小于batch大小,因此需要将**drop\_last**设置为**True**;另外需要将验证部分数据集**shuffle**设置为**True**。 +5. 获得映射文件。 - 代码位置:main.py文件中的main\_worker\(\)(修改部分为字体加粗部分)。 + 运行成功后,在acl.json配置文件中的`dump_path`路径下查看输出结果文件。 - ``` - ############## npu modify begin ############# - train_loader = torch.utils.data.DataLoader( - train_dataset, batch_size=args.batch_size, shuffle=(train_sampler is None), - num_workers=args.workers, pin_memory=False, sampler=train_sampler, drop_last=True) - - val_loader = torch.utils.data.DataLoader( - datasets.ImageFolder(valdir, transforms.Compose([ - transforms.Resize(256), - transforms.CenterCrop(224), - transforms.ToTensor(), - normalize, - ])), - batch_size=args.batch_size, shuffle=True, - num_workers=args.workers, pin_memory=False, drop_last=True) - ############## npu modify end ############# - ``` +##### NPU与GPU算子映射 -11. 进行损失函数及优化器构建,将模型、损失函数迁移到昇腾AI处理器上;将优化器、模型与混合精度模块进行结合以支持混合精度训练;将断点训练部分与混合精度模块结合以支持混合精度训练。 +请参见《开发辅助工具指南》中 ”精度对比工具使用指南(训练)“中 “数据准备章节” 中的 “[准备以PyTorch为原始训练网络的精度比对数据文件](https://support.huawei.com/enterprise/zh/doc/EDOC1100219269/2324edc8#ZH-CN_TOPIC_0000001162580808)”。 - 代码位置:main.py文件中的main\_worker\(\)中验证数据加载**后**(修改部分为字体加粗部分)。 +
整网调测
- ``` - val_loader = torch.utils.data.DataLoader( - datasets.ImageFolder(valdir, transforms.Compose([ - transforms.Resize(256), - transforms.CenterCrop(224), - transforms.ToTensor(), - normalize, - ])), - batch_size=args.batch_size, shuffle=True, - num_workers=args.workers, pin_memory=False, drop_last=True) - - ############## npu modify begin ############# - model = model.to(loc) - # define loss function (criterion) and optimizer - criterion = nn.CrossEntropyLoss().to(loc) - optimizer = torch.optim.SGD(model.parameters(), args.lr, - momentum=args.momentum, - weight_decay=args.weight_decay) - - if args.amp: - model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, loss_scale=args.loss_scale) - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu]) - - # optionally resume from a checkpoint - if args.resume: - if os.path.isfile(args.resume): - print("=> loading checkpoint '{}'".format(args.resume)) - checkpoint = torch.load(args.resume, map_location=loc) - args.start_epoch = checkpoint['epoch'] - best_acc1 = checkpoint['best_acc1'] - model.load_state_dict(checkpoint['state_dict']) - optimizer.load_state_dict(checkpoint['optimizer']) - if args.amp: - amp.load_state_dict(checkpoint['amp']) - print("=> loaded checkpoint '{}' (epoch {})" - .format(args.resume, checkpoint['epoch'])) - else: - print("=> no checkpoint found at '{}'".format(args.resume)) - - cudnn.benchmark = True - ############## npu modify end ############# - ``` +用户也可通过分析整个网络的方式来进行网络模型的精度调测。 -12. 断点checkpoint保存需要与混合精度训练结合,修改如下。 +1. 通过对比CPU和昇腾AI处理器的结果,判断在昇腾AI处理器上计算是否正确。 - 代码位置:main.py文件中的main\_worker\(\)(修改部分为字体加粗部分)。 + 代码样例(本样例只体现基本方法,禁止直接复制)如下: ``` - # remember best acc@1 and save checkpoint - is_best = acc1 > best_acc1 - best_acc1 = max(acc1, best_acc1) + # 固定入参,保证模型与输入数据在CPU和昇腾AI处理器上相同 + input_tensor_cpu = torch.Tensor() + model_cpu = build_model() + # 将输入数据迁移到昇腾AI处理器上 + input_tensor_npu = input_tensor_cpu.npu() + # 将模型迁移到昇腾AI处理器上 + model_npu = model_cpu.npu() - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - ############## npu modify begin ############# - if args.amp: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': args.arch, - 'state_dict': model.state_dict(), - 'best_acc1': best_acc1, - 'optimizer' : optimizer.state_dict(), - 'amp': amp.state_dict(), - }, is_best) - else: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': args.arch, - 'state_dict': model.state_dict(), - 'best_acc1': best_acc1, - 'optimizer' : optimizer.state_dict(), - }, is_best) - ############## npu modify end ############# + # 运算结果对比 + output_cpu = model_cpu(input_tensor_cpu) + output_npu = model_npu(input_tensor_npu) + compute_result = (output_cpu - output_npu).abs().mean()) + print(compute_result) ``` -13. 训练时,需要将数据集迁移到昇腾AI处理器上,修改如下: + 因昇腾AI处理器硬件架构与cpu不同,计算结果会略有不同。若运算结果较为接近(一般不高于1e-4),则认为运算结果正常。 + +2. 通过Pytorch的hook机制来打印正向反向传播中module的输入和输出来分析。 - 代码位置:main.py文件中的train\(\)(修改部分为字体加粗部分)。 + 代码样例(本样例只体现基本方法,禁止直接复制)如下: ``` - for i, (images, target) in enumerate(train_loader): - # measure data loading time - data_time.update(time.time() - end) - ############## npu modify begin ############# - loc = 'npu:{}'.format(args.gpu) - target = target.to(torch.int32) - images, target = images.to(loc, non_blocking=False), target.to(loc, non_blocking=False) - ############## npu modify end ############# - # 原模型代码如下: - # if args.gpu is not None: - # images = images.cuda(args.gpu, non_blocking=True) - # if torch.cuda.is_available(): - # target = target.cuda(args.gpu, non_blocking=True) + # 设置hook func + def hook_func(name, module): + def hook_function(module, inputs, outputs): + print(name+' inputs', inputs) + print(name+' outputs', outputs) + return hook_function + + # 注册正反向hook + for name, module in model.named_modules(): + module.register_forward_hook(hook_func('[forward]: '+name, module)) + module.register_backward_hook(hook_func('[backward]: '+name, module)) + + # 运行 + model(input_tensor) ``` -14. 标记反向传播.backward\(\)发生的位置,这样混合精度模块就可以进行Loss Scaling并清除每次迭代的状态,代码如下: + 通过分析打印正向反向传播中的inputs, outputs来确定。 - 代码位置:main.py文件中的train\(\)(修改部分为字体加粗部分)。 +3. 通过直接获取module的grad, running\_mean, running\_var等参数来分析更新量。 + + 代码样例(本样例只体现基本方法,禁止直接复制)如下: ``` - optimizer.zero_grad() - ############## npu modify begin ############# - if args.amp: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - # 原代码如下注释部分: - # loss.backward() - ############## npu modify end ############# - optimizer.step() + # 例如获取梯度和BN的均值方法来排查 + for name, module in model.named_modules(): + if isinstance(module, nn._BatchNorm): + print("[BN_buffer]: "+name, module.running_mean, module.running_var) + print("[grad]: "+name, module.grad) ``` -15. 验证时,需要将验证数据集迁移到昇腾AI处理器上,修改如下: - 代码位置:main.py文件中的validate\(\)(修改部分为字体加粗部分)。 +

模型保存与转换

- ``` - with torch.no_grad(): - end = time.time() - for i, (images, target) in enumerate(val_loader): - ############## npu modify begin ############# - loc = 'npu:{}'.format(args.gpu) - target = target.to(torch.int32) - images, target = images.to(loc, non_blocking=False), target.to(loc, non_blocking=False) - ############## npu modify end ############# - # 原模型代码如下注释部分: - # if args.gpu is not None: - # images = images.cuda(args.gpu, non_blocking=True) - # if torch.cuda.is_available(): - # target = target.cuda(args.gpu, non_blocking=True) - ``` +- **[简介](#简介md)** + +- **[模型保存](#模型保存md)** + +- **[导出ONNX模型](#导出ONNX模型md)** + + +

简介

+ +模型训练完成后,通过Pytorch提供的接口保存模型文件并导出ONNX模型,然后通过ATC工具将其转换为适配昇腾AI处理器的.om文件用于离线推理。 + +本章主要介绍如何将训练好的pth文件pth.tar文件转换为ONNX模型,将ONNX模型转换为适配昇腾AI处理器的.om文件流程请参考《CANN 开发辅助工具指南》手册中“ATC工具使用指南”章节。 + +如果想使用Auto Tune优化功能,请参考《CANN 开发辅助工具指南》手册中“Auto Tune工具使用指导”章节。 + +离线推理应用构建请参考《CANN 应用软件开发指南\(C&C++, 推理\)》。整体流程如下: + +![](figures/zh-cn_image_0000001144082132.png) + +

模型保存

+ +Pytorch在训练过程中,通常使用torch.save\(\)来保存Checkpoint文件,根据模型文件的后续用途会保存为两种格式的模型文件: + +- .pth或.pt扩展名的文件:用于在线推理或导出ONNX格式模型,仅保存模型参数,不保存模型结构,以便压缩文件的体积,可以用Netron等可视化工具打开,一般如[图1 .pth文件](#fig315704722610)所示。 + + **图 1** .pth文件 + ![](figures/pth文件.jpg "pth文件") + + 通过**state\_dict**来保存和加载模型,示例如下: + + 1. 保存模型。 + + ``` + # 创建保存路径 + PATH = "state_dict_model.pt" + # 保存模型 + torch.save(net.state_dict(), PATH) + ``` + + 2. 加载模型以用于在线推理,示例如下,详情请参见《PyTorch在线推理指南》。 + + ``` + # 模型文件保存路径 + PATH = "state_dict_model.pt" + model = TheModelClass(*args, **kwargs) + # 加载模型 + model.load_state_dict(torch.load(PATH)) + model.eval() + ``` + + >![](public_sys-resources/icon-notice.gif) **须知:** + >保存.pth或.pt文件扩展名的文件时要提供模型定义文件,否则无法部署。 + +- .pth.tar扩展名的文件:可用于在线推理或重新加载后继续训练。保存多个组件,以字典形式保存,常见的组件包括模型和优化器的state\_dict、停止时的epoch、最新记录的训练损失以及外部的torch.nn.Embedding层等。如果仅用于部署推理模型,推荐只在.pth.tar扩展名的文件中保存权重信息即模型的state\_dict。 + + 保存和加载模型示例如下: + + 1. 保存模型。 + + ``` + PATH = "checkpoint.pth.tar" + torch.save({ + 'epoch': epoch, + 'loss': loss, + 'state_dict': model.state_dict(), + 'optimizer' : optimizer.state_dict(), + ... + }, PATH) + ``` + + 2. 加载模型用于推理或恢复训练。 + ``` + model = TheModelClass(*args, **kwargs) + optimizer = TheOptimizerClass(*args, **kwargs) + + checkpoint = torch.load(PATH) + model.load_state_dict(checkpoint['model_state_dict']) + optimizer.load_state_dict(checkpoint['optimizer_state_dict']) + epoch = checkpoint['epoch'] + loss = checkpoint['loss'] + + model.eval() + # - or - + model.train() + ``` -

脚本执行

-**准备数据集** -准备数据集并上传到运行环境的目录下,例如:/home/data/resnet50/imagenet +>![](public_sys-resources/icon-notice.gif) **须知:** +>通常情况下,训练图和推理图中对同一个算子处理方式不同(例如BatchNorm和dropout等算子),在输入格式上也有差别,因此在运行推理或导出ONNX模型之前,必须调用model.eval\(\) 来将dropout和batch normalization层设置为推理模式。 -**配置环境变量** +

导出ONNX模型

-请参考[配置环境变量](#zh-cn_topic_0000001144082004md)配置环境变量。 +**简介** -**执行命令** +昇腾AI处理器Pytorch模型的部署策略是基于Pytorch官方支持的ONNX模块实现的。ONNX是业内目前比较主流的模型格式,广泛用于模型交流及部署。本节主要介绍如何将Checkpoint文件通过torch.onnx.export\(\)接口导出为ONNX模型。 -例如: +**.pth或.pt文件导出ONNX模型** -单卡: +保存的.pth或.pt文件可以通过Pytorch构建模型再加载权重的方法恢复,然后导出ONNX模型,样例如下。 ``` -python3 main.py /home/data/resnet50/imagenet --batch-size 128 \ # 训练批次大小 - --lr 0.1 \ # 学习率 - --epochs 90 \ # 训练迭代轮数 - --arch resnet50 \ # 模型架构 - --world-size 1 \ - --rank 0 \ - --workers 40 \ # 加载数据进程数 - --momentum 0.9 \ # 动量 - --weight-decay 1e-4 # 权重衰减 +import torch +import torch.onnx +import torchvision.models as models +# 设置使用CPU导出模型 +device = torch.device("cpu") + +def convert(): + # 模型定义来自于torchvision,样例生成的模型文件是基于resnet50模型 + model = models.resnet50(pretrained = False) + resnet50_model = torch.load('resnet50.pth', map_location='cpu') + model.load_state_dict(resnet50_model) + + batch_size = 1 #批处理大小 + input_shape = (3, 224, 224) #输入数据,改成自己的输入shape + + # 模型设置为推理模式 + model.eval() + + dummy_input = torch.randn(batch_size, *input_shape) # 定义输入shape + torch.onnx.export(model, + dummy_input, + "resnet50_official.onnx", + input_names = ["input"], # 构造输入名 + output_names = ["output"], # 构造输出名 + opset_version=11, # ATC工具目前仅支持opset_version=11 + dynamic_axes={"input":{0:"batch_size"}, "output":{0:"batch_size"}}) #支持输出动态轴 + ) + +if __name__ == "__main__": + convert() ``` -分布式: +>![](public_sys-resources/icon-note.gif) **说明:** +>- 在导出ONNX模型之前,必须调用model.eval\(\) 来将dropout和batch normalization层设置为推理模式。 +>- 样例脚本中的model来自于torchvision模块中的定义,用户使用自己的模型时需自行指定。 +>- 构造输入输出需要对应训练时的输入输出,否则无法正常推理。 + +**.pth.tar文件导出ONNX模型** + +.pth.tar在导出ONNX模型时需要先确定保存时的信息,有时保存的节点名称和模型定义中的节点会有差异,例如会多出前缀和后缀。在进行转换的时候,可以对节点名称进行修改。转换代码样例如下。 ``` -python3 main.py /home/data/resnet50/imagenet --addr='1.1.1.1' \ # 示例IP地址,请根据实际修改 - --seed 49 \ # 随机种子 - --workers 160 \ # 加载数据进程数 - --lr 0.8 \ - --print-freq 1 \ - --arch resnet50 \ # 模型架构 - --dist-url 'tcp://127.0.0.1:50000' \ - --dist-backend 'hccl' \ - --multiprocessing-distributed \ # 使用多卡训练 - --world-size 1 \ - --batch-size 2048 \ # 训练批次大小 - --epochs 90 \ # 训练迭代轮数 - --rank 0 \ - --device-list '0,1,2,3,4,5,6,7' \ - --amp # 使用混合精度训练 +import torch +import torch.onnx +from collections import OrderedDict +import mobilenet + +# 本样例中的pth.tar文件保存时节点名加了前缀module,通过遍历删除 +def proc_nodes_module(checkpoint, AttrName): + new_state_dict = OrderedDict() + for key, value in checkpoint[AttrName].items(): + if key == "module.features.0.0.weight": + print(value) + if(key[0:7] == "module."): + name = key[7:] + else: + name = key[0:] + + new_state_dict[name] = value + return new_state_dict + +def convert(): + checkpoint = torch.load("./mobilenet_cpu.pth.tar", map_location=torch.device('cpu')) + checkpoint['state_dict'] = proc_nodes_module(checkpoint,'state_dict') + model = mobilenet.mobilenet_v2(pretrained = False) + model.load_state_dict(checkpoint['state_dict']) + model.eval() + input_names = ["actual_input_1"] + output_names = ["output1"] + dummy_input = torch.randn(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, "mobilenetV2_npu.onnx", input_names = input_names, output_names = output_names, opset_version=11) + +if __name__ == "__main__": + convert() ``` ->![](public_sys-resources/icon-note.gif) **说明:** ->dist-backend需配置成hccl以支持在昇腾AI设备上进行分布式训练。 +

模型调优样例

ShuffleNet模型调优示例