From 852c69c6b70995a93d5887553c0a2c7c19b69f0f Mon Sep 17 00:00:00 2001 From: pengzirong Date: Mon, 27 Jun 2022 14:50:35 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=97=E5=AD=90=E5=BC=80=E5=8F=91=E6=8C=87?= =?UTF-8?q?=E5=8D=97;=E7=BD=91=E7=BB=9C=E6=A8=A1=E5=9E=8B=E7=A7=BB?= =?UTF-8?q?=E6=A4=8D=E4=B8=8E=E8=AE=AD=E7=BB=83=E6=8C=87=E5=8D=97;README?= =?UTF-8?q?=E8=B5=84=E6=96=99=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...57\346\214\201\346\270\205\345\215\225.md" | 518 +++++++-------- ...11\350\243\205\346\214\207\345\215\227.md" | 619 ++++++++---------- ...02\351\205\215\346\214\207\345\215\227.md" | 14 +- ...00\345\217\221\346\214\207\345\215\227.md" | 233 +++---- ...2\351\205\215\346\265\201\347\250\213.png" | Bin .../figures/zh-cn_image_0000001144082048.png" | Bin .../figures/zh-cn_image_0000001144082056.png" | Bin .../figures/zh-cn_image_0000001144082064.png" | Bin .../figures/zh-cn_image_0000001144082072.png" | Bin .../figures/zh-cn_image_0000001144082088.png" | Bin .../figures/zh-cn_image_0000001144241896.png" | Bin .../figures/zh-cn_image_0000001190081791.png" | Bin .../figures/zh-cn_image_0000001190081803.png" | Bin .../figures/zh-cn_image_0000001190201935.png" | Bin .../figures/zh-cn_image_0000001190201951.png" | Bin .../figures/zh-cn_image_0000001190201973.png" | Bin .../public_sys-resources/icon-caution.gif" | Bin .../public_sys-resources/icon-danger.gif" | Bin .../public_sys-resources/icon-note.gif" | Bin .../public_sys-resources/icon-notice.gif" | Bin .../public_sys-resources/icon-tip.gif" | Bin .../public_sys-resources/icon-warning.gif" | Bin ...55\347\273\203\346\214\207\345\215\227.md" | 4 +- 23 files changed, 663 insertions(+), 725 deletions(-) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227.md" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227.md" (82%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/PyTorch\346\241\206\346\236\266\344\270\213\347\232\204\347\256\227\345\255\220\351\200\202\351\205\215\346\265\201\347\250\213.png" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/PyTorch\346\241\206\346\236\266\344\270\213\347\232\204\347\256\227\345\255\220\351\200\202\351\205\215\346\265\201\347\250\213.png" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082048.png" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082048.png" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082056.png" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082056.png" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082064.png" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082064.png" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082072.png" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082072.png" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082088.png" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082088.png" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144241896.png" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144241896.png" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190081791.png" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190081791.png" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190081803.png" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190081803.png" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201935.png" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201935.png" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201951.png" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201951.png" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201973.png" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201973.png" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-caution.gif" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-caution.gif" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-danger.gif" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-danger.gif" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-note.gif" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-note.gif" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-notice.gif" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-notice.gif" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-tip.gif" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-tip.gif" (100%) rename "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-warning.gif" => "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-warning.gif" (100%) diff --git "a/docs/zh/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.md" index d35c0dfe7c..4da083d42a 100644 --- "a/docs/zh/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.md" @@ -116,265 +116,265 @@ ## Math operations -| 序号 | API名称 | 是否支持 | -| ---- | -------------------------------------- | ------------------------ | -| 1 | torch.abs | 是 | -| 2 | torch.absolute | 否 | -| 3 | torch.acos | 是 | -| 4 | torch.arccos | 否 | -| 5 | torch.acosh | 否 | -| 6 | torch.arccosh | 否 | -| 7 | torch.add | 是 | -| 8 | torch.addcdiv | 是 | -| 9 | torch.addcmul | 是 | -| 10 | torch.angle | 否 | -| 11 | torch.asin | 是 | -| 12 | torch.arcsin | 否 | -| 13 | torch.asinh | 否 | -| 14 | torch.arcsinh | 否 | -| 15 | torch.atan | 是 | -| 16 | torch.arctan | 否 | -| 17 | torch.atanh | 否 | -| 18 | torch.arctanh | 否 | -| 19 | torch.atan2 | 是 | -| 20 | torch.bitwise_not | 是 | -| 21 | torch.bitwise_and | 是 | -| 22 | torch.bitwise_or | 是 | -| 23 | torch.bitwise_xor | 是 | -| 24 | torch.ceil | 是 | -| 25 | torch.clamp | 是 | -| 26 | torch.clip | 否 | -| 27 | torch.conj | 否 | -| 28 | torch.copysign | 否 | -| 29 | torch.cos | 是 | -| 30 | torch.cosh | 是 | -| 31 | torch.deg2rad | 否 | -| 32 | torch.div | 是 | -| 33 | torch.divide | 否 | -| 34 | torch.digamma | 否 | -| 35 | torch.erf | 是 | -| 36 | torch.erfc | 是 | -| 37 | torch.erfinv | 是 | -| 38 | torch.exp | 是 | -| 39 | torch.exp2 | 否 | -| 40 | torch.expm1 | 是 | -| 41 | torch.fake_quantize_per_channel_affine | 否 | -| 42 | torch.fake_quantize_per_tensor_affine | 否 | -| 43 | torch.fix | 否 | -| 44 | torch.float_power | 否 | -| 45 | torch.floor | 是 | -| 46 | torch.floor_divide | 是 | -| 47 | torch.fmod | 是 | -| 48 | torch.frac | 是 | -| 49 | torch.imag | 否 | -| 50 | torch.ldexp | 否 | -| 51 | torch.lerp | 是 | -| 52 | torch.lgamma | 否 | -| 53 | torch.log | 是 | -| 54 | torch.log10 | 是 | -| 55 | torch.log1p | 是 | -| 56 | torch.log2 | 是 | -| 57 | torch.logaddexp | 否 | -| 58 | torch.logaddexp2 | 否 | -| 59 | torch.logical_and | 是 | -| 60 | torch.logical_not | 是 | -| 61 | torch.logical_or | 是 | -| 62 | torch.logical_xor | 是 | -| 63 | torch.logit | 否 | -| 64 | torch.hypot | 否 | -| 65 | torch.i0 | 否 | -| 66 | torch.igamma | 否 | -| 67 | torch.igammac | 否 | -| 68 | torch.mul | 是 | -| 69 | torch.multiply | 否 | -| 70 | torch.mvlgamma | 否 | -| 71 | torch.nan_to_num | 否 | -| 72 | torch.neg | 是 | -| 73 | torch.negative | 否 | -| 74 | torch.nextafter | 否 | -| 75 | torch.polygamma | 否 | -| 76 | torch.pow | 是 | -| 77 | torch.rad2deg | 否 | -| 78 | torch.real | 是 | -| 79 | torch.reciprocal | 是 | -| 80 | torch.remainder | 是 | -| 81 | torch.round | 是 | -| 82 | torch.rsqrt | 是 | -| 83 | torch.sigmoid | 是 | -| 84 | torch.sign | 是 | -| 85 | torch.sgn | 否 | -| 86 | torch.signbit | 否 | -| 87 | torch.sin | 是 | -| 88 | torch.sinc | 否 | -| 89 | torch.sinh | 是 | -| 90 | torch.sqrt | 是 | -| 91 | torch.square | 是 | -| 92 | torch.sub | 是 | -| 93 | torch.subtract | 否 | -| 94 | torch.tan | 是 | -| 95 | torch.tanh | 是 | -| 96 | torch.true_divide | 是 | -| 97 | torch.trunc | 是 | -| 98 | torch.xlogy | 否 | -| 99 | torch.argmax | 是 | -| 100 | torch.argmin | 是 | -| 101 | torch.amax | 否 | -| 102 | torch.amin | 否 | -| 103 | torch.all | 是 | -| 104 | torch.any | 是 | -| 105 | torch.max | 是 | -| 106 | torch.min | 是 | -| 107 | torch.dist | 是 | -| 108 | torch.logsumexp | 是 | -| 109 | torch.mean | 是 | -| 110 | torch.median | 是 | -| 111 | torch.namedian | 否 | -| 112 | torch.mode | 否 | -| 113 | torch.norm | 是 | -| 114 | torch.nansum | 否 | -| 115 | torch.prod | 是 | -| 116 | torch.quantile | 否 | -| 117 | torch.nanquantile | 否 | -| 118 | torch.std | 是 | -| 119 | torch.std_mean | 是 | -| 120 | torch.sum | 是 | -| 121 | torch.unique | 是 | -| 122 | torch.unique_consecutive | 否 | -| 123 | torch.var | 否 | -| 124 | torch.var_mean | 否 | -| 125 | torch.count_nonzero | 否 | -| 126 | torch.allclose | 是 | -| 127 | torch.argsort | 是 | -| 128 | torch.eq | 是 | -| 129 | torch.equal | 是 | -| 130 | torch.ge | 是 | -| 131 | torch.greater_qual | 否 | -| 132 | torch.gt | 是 | -| 133 | torch.greater | 否 | -| 134 | torch.isclose | 否 | -| 135 | torch.isfinite | 是 | -| 136 | torch.isinf | 是 | -| 137 | torch.isposinf | 否 | -| 138 | torch.isneginf | 否 | -| 139 | torch.isnan | 是 | -| 140 | torch.isreal | 否 | -| 141 | torch.kthvalue | 是 | -| 142 | torch.le | 是 | -| 143 | torch.less_qual | 否 | -| 144 | torch.lt | 是 | -| 145 | torch.less | 否 | -| 146 | torch.maximum | 否 | -| 147 | torch.minimum | 否 | -| 148 | torch.fmax | 否 | -| 149 | torch.fmin | 否 | -| 150 | torch.ne | 是 | -| 151 | torch.not_equal | 否 | -| 152 | torch.sort | 是 | -| 153 | torch.topk | 是 | -| 154 | torch.msort | 否 | -| 155 | torch.fft | 否 | -| 156 | torch.ifft | 否 | -| 157 | torch.rfft | 否 | -| 158 | torch.irfft | 否 | -| 159 | torch.stft | 否 | -| 160 | torch.istft | 否 | -| 161 | torch.bartlett_window | 是 | -| 162 | torch.blackman_window | 是 | -| 163 | torch.hamming_window | 是 | -| 164 | torch.hann_window | 是 | -| 165 | torch.kasier_window | 否 | -| 166 | torch.atleast_1d | 否 | -| 167 | torch.atleast_2d | 否 | -| 168 | torch.atleast_3d | 否 | -| 169 | torch.bincount | 是 | -| 170 | torch.block_diag | 否 | -| 171 | torch.broadcast_tensors | 是 | -| 172 | torch.broadcast_to | 否 | -| 173 | torch.broadcast_shapes | 否 | -| 174 | torch.bucketize | 否 | -| 175 | torch.cartesian_prod | 是 | -| 176 | torch.cdist | 是 | -| 177 | torch.clone | 是 | -| 178 | torch.combinations | 否 | -| 179 | torch.cross | 是 | -| 180 | torch.cummax | 是 | -| 181 | torch.cummin | 是 | -| 182 | torch.cumprod | 是 | -| 183 | torch.cumsum | 是 | -| 184 | torch.diag | 是,仅支持diagonal=0场景 | -| 185 | torch.diag_embed | 是 | -| 186 | torch.diagflat | 是 | -| 187 | torch.diagonal | 是 | -| 188 | torch.diff | 否 | -| 189 | torch.einsum | 是 | -| 190 | torch.flatten | 是 | -| 191 | torch.flip | 是 | -| 192 | torch.fliplr | 否 | -| 193 | torch.flipud | 否 | -| 194 | torch.kron | 否 | -| 195 | torch.rot90 | 是 | -| 196 | torch.gcd | 否 | -| 197 | torch.histc | 否 | -| 198 | torch.meshgrid | 是 | -| 199 | torch.lcm | 否 | -| 200 | torhc.logcumsumexp | 否 | -| 201 | torch.ravel | 否 | -| 202 | torch.renorm | 是 | -| 203 | torch.repeat_interleave | 是 | -| 204 | torch.roll | 是 | -| 205 | torch.searchsorted | 否 | -| 206 | torch.tensordot | 是 | -| 207 | torch.trace | 否 | -| 208 | torch.tril | 是 | -| 209 | torch.tril_indices | 是 | -| 210 | torch.triu | 是 | -| 211 | torch.triu_indices | 是 | -| 212 | torch.vander | 否 | -| 213 | torch.view_as_real | 否 | -| 214 | torch.view_as_complex | 否 | -| 215 | torch.addbmm | 是 | -| 216 | torch.addmm | 是 | -| 217 | torch.addmv | 是 | -| 218 | torch.addr | 是 | -| 219 | torch.baddbmm | 是 | -| 220 | torch.bmm | 是 | -| 221 | torch.chain_matmul | 是 | -| 222 | torch.cholesky | 否 | -| 223 | torch.cholesky_inverse | 否 | -| 224 | torch.cholesky_solve | 否 | -| 225 | torch.dot | 是 | -| 226 | torch.eig | 否 | -| 227 | torch.geqrf | 否 | -| 228 | torch.ger | 是 | -| 229 | torch.inner | 否 | -| 230 | torch.inverse | 是 | -| 231 | torch.det | 否 | -| 232 | torch.logdet | 否 | -| 233 | torch.slogdet | 是 | -| 234 | torch.lstsq | 否 | -| 235 | torch.lu | 否 | -| 236 | torch.lu_solve | 否 | -| 237 | torch.lu_unpack | 否 | -| 238 | torch.matmul | 是 | -| 239 | torch.matrix_power | 是 | -| 240 | torch.matrix_rank | 是 | -| 241 | torch.matrix_exp | 否 | -| 242 | torch.mm | 是 | -| 243 | torch.mv | 是 | -| 244 | torch.orgqr | 否 | -| 245 | torch.ormqr | 否 | -| 246 | torch.outer | 否 | -| 247 | torch.pinverse | 是 | -| 248 | torch.qr | 是 | -| 249 | torch.solve | 否 | -| 250 | torch.svd | 是 | -| 251 | torch.svd_lowrank | 是 | -| 252 | torch.pca_lowrank | 是 | -| 253 | torch.symeig | 是 | -| 254 | torch.lobpcg | 否 | -| 255 | torch.trapz | 是 | -| 256 | torch.triangular_solve | 是 | -| 257 | torch.vdot | 否 | +| 序号 | API名称 | 是否支持 | +| ---- | -------------------------------------- | ------------------------------------------- | +| 1 | torch.abs | 是 | +| 2 | torch.absolute | 否 | +| 3 | torch.acos | 是 | +| 4 | torch.arccos | 否 | +| 5 | torch.acosh | 否 | +| 6 | torch.arccosh | 否 | +| 7 | torch.add | 是 | +| 8 | torch.addcdiv | 是 | +| 9 | torch.addcmul | 是 | +| 10 | torch.angle | 否 | +| 11 | torch.asin | 是 | +| 12 | torch.arcsin | 否 | +| 13 | torch.asinh | 否 | +| 14 | torch.arcsinh | 否 | +| 15 | torch.atan | 是 | +| 16 | torch.arctan | 否 | +| 17 | torch.atanh | 否 | +| 18 | torch.arctanh | 否 | +| 19 | torch.atan2 | 是 | +| 20 | torch.bitwise_not | 是 | +| 21 | torch.bitwise_and | 是 | +| 22 | torch.bitwise_or | 是 | +| 23 | torch.bitwise_xor | 是 | +| 24 | torch.ceil | 是 | +| 25 | torch.clamp | 是 | +| 26 | torch.clip | 否 | +| 27 | torch.conj | 否 | +| 28 | torch.copysign | 否 | +| 29 | torch.cos | 是 | +| 30 | torch.cosh | 是 | +| 31 | torch.deg2rad | 否 | +| 32 | torch.div | 是 | +| 33 | torch.divide | 否 | +| 34 | torch.digamma | 否 | +| 35 | torch.erf | 是 | +| 36 | torch.erfc | 是 | +| 37 | torch.erfinv | 是 | +| 38 | torch.exp | 是 | +| 39 | torch.exp2 | 否 | +| 40 | torch.expm1 | 是 | +| 41 | torch.fake_quantize_per_channel_affine | 否 | +| 42 | torch.fake_quantize_per_tensor_affine | 否 | +| 43 | torch.fix | 否 | +| 44 | torch.float_power | 否 | +| 45 | torch.floor | 是 | +| 46 | torch.floor_divide | 是 | +| 47 | torch.fmod | 是 | +| 48 | torch.frac | 是 | +| 49 | torch.imag | 否 | +| 50 | torch.ldexp | 否 | +| 51 | torch.lerp | 是 | +| 52 | torch.lgamma | 否 | +| 53 | torch.log | 是 | +| 54 | torch.log10 | 是 | +| 55 | torch.log1p | 是 | +| 56 | torch.log2 | 是 | +| 57 | torch.logaddexp | 否 | +| 58 | torch.logaddexp2 | 否 | +| 59 | torch.logical_and | 是 | +| 60 | torch.logical_not | 是 | +| 61 | torch.logical_or | 是 | +| 62 | torch.logical_xor | 是 | +| 63 | torch.logit | 否 | +| 64 | torch.hypot | 否 | +| 65 | torch.i0 | 否 | +| 66 | torch.igamma | 否 | +| 67 | torch.igammac | 否 | +| 68 | torch.mul | 是 | +| 69 | torch.multiply | 否 | +| 70 | torch.mvlgamma | 否 | +| 71 | torch.nan_to_num | 否 | +| 72 | torch.neg | 是 | +| 73 | torch.negative | 否 | +| 74 | torch.nextafter | 否 | +| 75 | torch.polygamma | 否 | +| 76 | torch.pow | 是 | +| 77 | torch.rad2deg | 否 | +| 78 | torch.real | 是 | +| 79 | torch.reciprocal | 是 | +| 80 | torch.remainder | 是 | +| 81 | torch.round | 是 | +| 82 | torch.rsqrt | 是 | +| 83 | torch.sigmoid | 是 | +| 84 | torch.sign | 是 | +| 85 | torch.sgn | 否 | +| 86 | torch.signbit | 否 | +| 87 | torch.sin | 是 | +| 88 | torch.sinc | 否 | +| 89 | torch.sinh | 是 | +| 90 | torch.sqrt | 是 | +| 91 | torch.square | 是 | +| 92 | torch.sub | 是 | +| 93 | torch.subtract | 否 | +| 94 | torch.tan | 是 | +| 95 | torch.tanh | 是 | +| 96 | torch.true_divide | 是 | +| 97 | torch.trunc | 是 | +| 98 | torch.xlogy | 否 | +| 99 | torch.argmax | 是 | +| 100 | torch.argmin | 是 | +| 101 | torch.amax | 否 | +| 102 | torch.amin | 否 | +| 103 | torch.all | 是 | +| 104 | torch.any | 是 | +| 105 | torch.max | 是 | +| 106 | torch.min | 是 | +| 107 | torch.dist | 是 | +| 108 | torch.logsumexp | 是 | +| 109 | torch.mean | 是 | +| 110 | torch.median | 是 | +| 111 | torch.namedian | 否 | +| 112 | torch.mode | 否 | +| 113 | torch.norm | 是 | +| 114 | torch.nansum | 否 | +| 115 | torch.prod | 是 | +| 116 | torch.quantile | 否 | +| 117 | torch.nanquantile | 否 | +| 118 | torch.std | 是 | +| 119 | torch.std_mean | 是 | +| 120 | torch.sum | 是 | +| 121 | torch.unique | 是 | +| 122 | torch.unique_consecutive | 否 | +| 123 | torch.var | 否 | +| 124 | torch.var_mean | 否 | +| 125 | torch.count_nonzero | 否 | +| 126 | torch.allclose | 是 | +| 127 | torch.argsort | 是 | +| 128 | torch.eq | 是 | +| 129 | torch.equal | 是 | +| 130 | torch.ge | 是 | +| 131 | torch.greater_qual | 否 | +| 132 | torch.gt | 是 | +| 133 | torch.greater | 否 | +| 134 | torch.isclose | 否 | +| 135 | torch.isfinite | 是 | +| 136 | torch.isinf | 是 | +| 137 | torch.isposinf | 否 | +| 138 | torch.isneginf | 否 | +| 139 | torch.isnan | 是 | +| 140 | torch.isreal | 否 | +| 141 | torch.kthvalue | 是 | +| 142 | torch.le | 是 | +| 143 | torch.less_qual | 否 | +| 144 | torch.lt | 是 | +| 145 | torch.less | 否 | +| 146 | torch.maximum | 否 | +| 147 | torch.minimum | 否 | +| 148 | torch.fmax | 否 | +| 149 | torch.fmin | 否 | +| 150 | torch.ne | 是 | +| 151 | torch.not_equal | 否 | +| 152 | torch.sort | 是 | +| 153 | torch.topk | 是 | +| 154 | torch.msort | 否 | +| 155 | torch.fft | 否 | +| 156 | torch.ifft | 否 | +| 157 | torch.rfft | 否 | +| 158 | torch.irfft | 否 | +| 159 | torch.stft | 否 | +| 160 | torch.istft | 否 | +| 161 | torch.bartlett_window | 是 | +| 162 | torch.blackman_window | 是 | +| 163 | torch.hamming_window | 是 | +| 164 | torch.hann_window | 是 | +| 165 | torch.kasier_window | 否 | +| 166 | torch.atleast_1d | 否 | +| 167 | torch.atleast_2d | 否 | +| 168 | torch.atleast_3d | 否 | +| 169 | torch.bincount | 是 | +| 170 | torch.block_diag | 否 | +| 171 | torch.broadcast_tensors | 是 | +| 172 | torch.broadcast_to | 否 | +| 173 | torch.broadcast_shapes | 否 | +| 174 | torch.bucketize | 否 | +| 175 | torch.cartesian_prod | 是 | +| 176 | torch.cdist | 是,仅支持mode=donot_use_mm_for_euclid_dist | +| 177 | torch.clone | 是 | +| 178 | torch.combinations | 否 | +| 179 | torch.cross | 是 | +| 180 | torch.cummax | 是 | +| 181 | torch.cummin | 是 | +| 182 | torch.cumprod | 是 | +| 183 | torch.cumsum | 是 | +| 184 | torch.diag | 是,仅支持diagonal=0场景 | +| 185 | torch.diag_embed | 是 | +| 186 | torch.diagflat | 是 | +| 187 | torch.diagonal | 是 | +| 188 | torch.diff | 否 | +| 189 | torch.einsum | 是 | +| 190 | torch.flatten | 是 | +| 191 | torch.flip | 是 | +| 192 | torch.fliplr | 否 | +| 193 | torch.flipud | 否 | +| 194 | torch.kron | 否 | +| 195 | torch.rot90 | 是 | +| 196 | torch.gcd | 否 | +| 197 | torch.histc | 否 | +| 198 | torch.meshgrid | 是 | +| 199 | torch.lcm | 否 | +| 200 | torhc.logcumsumexp | 否 | +| 201 | torch.ravel | 否 | +| 202 | torch.renorm | 是 | +| 203 | torch.repeat_interleave | 是 | +| 204 | torch.roll | 是 | +| 205 | torch.searchsorted | 否 | +| 206 | torch.tensordot | 是 | +| 207 | torch.trace | 否 | +| 208 | torch.tril | 是 | +| 209 | torch.tril_indices | 是 | +| 210 | torch.triu | 是 | +| 211 | torch.triu_indices | 是 | +| 212 | torch.vander | 否 | +| 213 | torch.view_as_real | 否 | +| 214 | torch.view_as_complex | 否 | +| 215 | torch.addbmm | 是 | +| 216 | torch.addmm | 是 | +| 217 | torch.addmv | 是 | +| 218 | torch.addr | 是 | +| 219 | torch.baddbmm | 是 | +| 220 | torch.bmm | 是 | +| 221 | torch.chain_matmul | 是 | +| 222 | torch.cholesky | 否 | +| 223 | torch.cholesky_inverse | 否 | +| 224 | torch.cholesky_solve | 否 | +| 225 | torch.dot | 是 | +| 226 | torch.eig | 否 | +| 227 | torch.geqrf | 否 | +| 228 | torch.ger | 是 | +| 229 | torch.inner | 否 | +| 230 | torch.inverse | 是 | +| 231 | torch.det | 否 | +| 232 | torch.logdet | 否 | +| 233 | torch.slogdet | 是 | +| 234 | torch.lstsq | 否 | +| 235 | torch.lu | 否 | +| 236 | torch.lu_solve | 否 | +| 237 | torch.lu_unpack | 否 | +| 238 | torch.matmul | 是 | +| 239 | torch.matrix_power | 是 | +| 240 | torch.matrix_rank | 是 | +| 241 | torch.matrix_exp | 否 | +| 242 | torch.mm | 是 | +| 243 | torch.mv | 是 | +| 244 | torch.orgqr | 否 | +| 245 | torch.ormqr | 否 | +| 246 | torch.outer | 否 | +| 247 | torch.pinverse | 是 | +| 248 | torch.qr | 是 | +| 249 | torch.solve | 否 | +| 250 | torch.svd | 是 | +| 251 | torch.svd_lowrank | 是 | +| 252 | torch.pca_lowrank | 是 | +| 253 | torch.symeig | 是 | +| 254 | torch.lobpcg | 否 | +| 255 | torch.trapz | 是 | +| 256 | torch.triangular_solve | 是 | +| 257 | torch.vdot | 否 | ## Utilities 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 c7c39229f5..7f76e3ee28 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" @@ -1,212 +1,112 @@ # PyTorch安装指南 -- [简介](#简介md) -- [手动编译安装](#手动编译安装md) - - [前提条件](#前提条件md) - - [安装PyTorch框架](#安装PyTorch框架md) - - [配置环境变量](#配置环境变量md) - - [安装混合精度模块](#安装混合精度模块md) -- [参考信息](#参考信息md) - - [CMake安装方法](#CMake安装方法md) - - [安装7.3.0版本gcc](#安装7-3-0版本gccmd) - - [安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配](#安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配md) -

简介

-用户在准备相关环境进行基于PyTorch框架模型的开发、运行时,可以选择在服务器中手动编译安装PyTorch框架相关模块。 +- [简介](#简介) -**图 1** 环境准备流程图 +- [系统依赖库](#系统依赖库) +- [Ascend配套软件](#Ascend配套软件) -![](figures/210926103326800.png) +- [安装方式](#安装方式) -

手动编译安装

+- [运行](#运行) +- [安装混合精度模块(可选)](#安装混合精度模块(可选)) +- [FAQ](#FAQ) +- [版本说明](#版本说明) -- **[前提条件](#前提条件md)** +# 简介 -- **[安装PyTorch框架](#安装PyTorch框架md)** +本项目开发了PyTorch Adapter插件,用于昇腾适配PyTorch框架,为使用PyTorch框架的开发者提供昇腾AI处理器的超强算力。用户在准备相关环境进行基于PyTorch框架模型的开发、运行时,可以选择在服务器中手动编译相关模块。 -- **[配置环境变量](#配置环境变量md)** - -- **[安装混合精度模块](#安装混合精度模块md)** - - -

前提条件

- -#### 前提条件 +

前提条件

- 需完成CANN开发或运行环境的安装,具体操作请参考《CANN 软件安装指南》。 +- 需安装python版本为3.7.5、3.8、3.9。 -| AscendPyTorch版本 | CANN版本 | 支持PyTorch版本 | -| :------------ | :----------- | :----------- | -| 3.0.2 | CANN 5.0.2 | 1.5.0.post2 | -| 2.0.3 | CANN 5.0.3 | 1.5.0.post3 | -| 2.0.4 | CANN 5.0.4 | 1.5.0.post4 | -| 3.0.rc1 | CANN 5.1.RC1 | 1.5.0.post5, 1.8.1.rc1 | +# 系统依赖库 -- 需安装3.12.0以上版本的CMake,安装方法请参考[CMake安装方法](#CMake安装方法md)。 +## CentOS & EulerOS -- 需确保已安装7.3.0以上版本的gcc,7.3.0版本gcc具体安装及使用方式请参考[安装7.3.0版本gcc](#安装7-3-0版本gccmd)。 +yum install -y cmake==3.12.0 zlib-devel libffi-devel openssl-devel libjpeg-turbo-devel gcc-c++ sqlite-devel dos2unix openblas git gcc==7.3.0 -- 需安装python版本为3.7.5、3.8、3.9。 +## Ubuntu -- 需注意torch1.5版本不支持python3.9编译安装(与官方保持一致),仅torch1.8.1版本支持python版本3.9进行编译安装。 +apt-get install -y gcc==7.3.0 g++ make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev m4 cmake==3.12.0 dos2unix libopenblas-dev git -- 需确保环境中已安装patch、git工具,以Ubuntu和CentOS系统为例,命令如下: - - Ubuntu系统 +# Ascend配套软件 - ``` - apt-get install patch - apt-get install git - ``` +| AscendPyTorch版本 | CANN版本 | 支持PyTorch版本 | Gitee分支名称 | +| :---------------- | :----------- | :-------------- | -------------- | +| 2.0.2 | CANN 5.0.2 | 1.5.0.post2 | 2.0.2.tr5 | +| 2.0.3 | CANN 5.0.3 | 1.5.0.post3 | 2.0.3.tr5 | +| 2.0.4 | CANN 5.0.4 | 1.5.0.post4 | 2.0.4.tr5 | +| 3.0.rc1 | CANN 5.1.RC1 | 1.5.0.post5 | v1.5.0-3.0.rc1 | +| 3.0.rc1 | CANN 5.1.RC1 | 1.8.1.rc1 | v1.8.1-3.0.rc1 | - - CentOS系统 +# 安装方式 - ``` - yum install patch - yum install git - ``` +## 安装Pytorch依赖环境 +如果使用非root用户安装,用户需要在本步骤的每句命令后加**--user**,示例如:pip3 install pyyaml --user。 +```sh +pip3 install pyyaml +pip3 install wheel +``` -

安装PyTorch框架

+## 编译安装PyTorch和昇腾插件 -#### 安装流程 +首先安装官方torch包,然后编译安装插件。(ARM架构CPU安装,请参见第一条FAQ) -1. 以root或非root用户登录服务器。 +```sh +#x86_64 +pip3 install torch==1.8.1+cpu #安装cpu版本PyTorch 下载地址:(https://download.pytorch.org/whl/torch) -2. 依次执行如下命令安装PyTorch依赖环境。 +#aarch64 +#社区未提供arm架构cpu安装包,请参见FAQ第一条,使用源码编译安装pytorch +``` - 如果使用非root用户安装Python及其依赖,用户需要在本步骤中的每句命令结尾加上**--user**,命令示例为:**pip3.7 install pyyaml --user** +编译生成pytorch插件的二进制安装包。 - ``` - pip3 install pyyaml - pip3 install wheel - ``` +``` +git clone -b master https://gitee.com/ascend/pytorch.git & cd pytorch # 下载master分支代码,进入插件根目录 +# 指定python版本编包方式: +bash ci/build.sh --python=3.7 +# 或 +bash ci/build.sh --python=3.8 +# 或 +bash ci/build.sh --python=3.9 +``` -3. 获取PyTorch源代码。 +然后安装pytorch/dist下生成的插件torch_npu包 - 1. 运行如下命令,获取适配昇腾AI处理器的PyTorch源代码,并切换到所需的分支。 +``` +pip3 install --upgrade dist/torch_npu-1.8.1rc1-cp37-cp37m-linux_{arch}.whl +``` - ``` - git clone https://gitee.com/ascend/pytorch.git - # 默认是master分支,master分支时pytorch1.8.1版本,若需要其他分支请使用git checkout 命令切换 - cd pytorch - git checkout -b v1.8.1-3.0.rc1 remotes/origin/v1.8.1-3.0.rc1 - ``` - 2. 在当前仓根目录“/pytorch”下获得原生PyTorch 1.8.1源代码并重命名为pytorch_v1.8.1。 +# 运行 - ``` - //1.8.1版本 - - cd pytorch #插件根目录 - - git clone -b v1.8.1 --depth=1 https://github.com/pytorch/pytorch.git pytorch_v1.8.1 - ``` +## 运行环境变量 - >![](public_sys-resources/icon-note.gif) **说明:** - >请关注PyTorch原生社区的安全板块与Issue板块是否有安全相关问题修复,并根据社区修复及时更新原生PyTorch代码。 +在当前仓库根目录中执行设置环境变量脚本 - 3. 运行如下命令,进入原生pytorch代码目录“pytorch_v1.8.1“,并获取PyTorch被动依赖代码。 +``` +source env.sh +``` - ``` - cd pytorch_v1.8.1 - git submodule sync - git submodule update --init --recursive - ``` - >![](public_sys-resources/icon-note.gif) **说明:** - >受网络波动影响,源码获取时间可能较长,下载过程中请耐心等待。 下载完成之后若没有报错,即生成了PyTorch及其依赖的第三方代码。 - -4. 编译生成适配昇腾AI处理器的PyTorch安装包。 - 1. 将patch打入Pytorch源码并编译。 - - ``` - cd ../patch - bash apply_patch.sh ../pytorch_v1.8.1 - cd ../pytorch_v1.8.1 - 指定python版本编包方式: - bash build.sh --python=3.7 - 或 - bash build.sh --python=3.8 - 或 - bash build.sh --python=3.9 - ``` - - 安装当前dist目录(pytorch/pytorch_v1.8.1/dist)下生成的torch包。 - - ``` - cd dist - pip3 install --upgrade torch-1.8.1+ascend.rc1-cp37-cp37m-linux_{arch}.whl #**\{arch\}**表示架构信息,为aarch64或x86\_64。 - ``` - - 3. 编译生成pytorch插件的二进制安装包。 - - ``` - cd ../../ci #进入插件根目录 - 指定python版本编包方式: - bash build.sh --python=3.7 - 或 - bash build.sh --python=3.8 - 或 - bash build.sh --python=3.9 - ``` - - 请指定环境中python版本进行编译。生成的二进制包在当前的dist目录下,即“pytorch/dist”文件夹目录下。 - -5. 安装PyTorch插件。 - - 进入“pytorch/dist“文件夹目录,执行如下命令安装torch_npu包。 - - ``` - cd ../dist - pip3 install --upgrade torch_npu-1.8.1rc1-cp37-cp37m-linux_{arch}.whl - ``` - - >![](public_sys-resources/icon-note.gif) **说明:** - >若对环境中的PyTorch插件进行升级时,需要先卸载环境中已安装的PyTorch插件软件包再执行[5. 安装PyTorch插件。](#zh-cn_topic_0000001152776301_li49671667141)可以通过执行如下命令查询环境上是否已安装PyTorch插件。 - >**pip3 list | grep torch-npu** - - -

配置环境变量

- -安装完软件包后,需要配置环境变量才能正常使用昇腾PyTorch。相关环境变量介绍参见[表1](#zh-cn_topic_0000001152616261_table42017516135)。 - -1. 配置运行环境变量,在适配昇腾AI处理器的PyTorch源代码根目录中运行如下命令。 - - ``` - cd ../ - source env.sh - ``` - -2. 请依据实际场景,选择合适的HCCL初始化方式,并配置相应环境变量。 - - ``` - # 场景一:单机场景 - export HCCL_WHITELIST_DISABLE=1 # 关闭HCCL通信白名单 - # 场景二:多机场景。 - export HCCL_WHITELIST_DISABLE=1 # 关闭HCCL通信白名单 - export HCCL_IF_IP="1.1.1.1" # “1.1.1.1”为示例使用的host网卡IP,请根据实际修改。需要保证使用的网卡IP在集群内是互通的。 - ``` - -3. (可选)NPU场景下配置功能或性能环境变量。默认为不开启。 - - ``` - export DYNAMIC_COMPILE_ENABLE=1 # 动态shape特性功能,针对shape变化场景,可选,开启设置为1(PyTorch1.8.1不支持该环境变量) - export COMBINED_ENABLE=1 # 非连续两个算子组合类场景优化,可选,开启设置为1 - export ACL_DUMP_DATA=1 # 算子数据dump功能,调试时使用,可选,开启设置为1 - export DYNAMIC_OP="ADD#MUL" # 算子实现,ADD和MUL算子在不同场景下有不同的性能表现。可选 - ``` - -4. (可选)当系统为openEuler及其继承操作系统时,如UOS,需设置此命令,取消CPU绑核。 - - ``` - # unset GOMP_CPU_AFFINITY - ``` +## 自定义环境变量 +可选的环境变量可能会对运行的模型产生影响: -**表 1** 环境变量说明 +``` +export COMBINED_ENABLE=1 # 非连续两个算子组合类场景优化,可选,开启设置为1 +export ACL_DUMP_DATA=1 # 算子数据dump功能,调试时使用,可选,开启设置为1 +``` +**表 1** 环境变量说明 + - - - - - - - - - - - - - - - - - - @@ -123,11 +123,12 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的API适配。 +

算子开发准备

- **[环境准备](#环境准备md)** -- **[API速查](#API速查md)** +- **[算子速查](#算子速查md)**

环境准备

@@ -153,30 +154,30 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的API适配。 -

API速查

+

算子速查

-进行API开发时,您可以查询当前昇腾AI处理器中支持的算子列表和当前PyTorch适配的API列表。根据查询结果进行算子开发或PyTorchAPI适配。 +进行算子开发时,您可以查询当前昇腾AI处理器中支持的算子列表和当前PyTorch适配的算子列表。根据查询结果进行算子开发或PyTorch算子适配。 -- 若昇腾AI处理器不支持算子,则需要进行TBE算子开发和PyTorch框架API适配。 -- 若昇腾AI处理器支持算子但PyTorch框架没有API适配,仅需要进行PyTorch框架下API适配。 -- 若PyTorch框架已经适配API,直接使用API即可,不需要开发和适配。 +- 若昇腾AI处理器不支持算子,则需要进行TBE算子开发和PyTorch框架算子适配。 +- 若昇腾AI处理器支持算子但PyTorch框架没有算子适配,仅需要进行PyTorch框架下算子适配。 +- 若PyTorch框架已经适配算子,直接使用算子即可,不需要开发和适配。 -昇腾AI处理器和PyTorch适配的API查询方式如下。 +昇腾AI处理器和PyTorch适配的算子查询方式如下。 -- 当前昇腾AI处理器中支持的算子以及对应的API约束可以通过以下两种方式查询。 +- 当前昇腾AI处理器中支持的算子以及对应的算子约束可以通过以下两种方式查询。 - 命令行开发方式下,您可以参见《CANN 算子清单 \(Ascend 910\)》进行离线查询。 - MindStudio开发方式下,您可以通过MindStudio进行在线查询,详细查看方法可参见《MindStudio 用户指南》中的“算子&模型速查”章节。 -- 当前PyTorch适配的API列表可以参见[《PyTorch API支持清单》](https://gitee.com/ascend/pytorch/blob/master/docs/zh/PyTorch%20API%E6%94%AF%E6%8C%81%E6%B8%85%E5%8D%95.md)。 +- 当前PyTorch适配的算子列表可以参见[《PyTorch API支持清单》](https://gitee.com/ascend/pytorch/blob/master/docs/zh/PyTorch%20API%E6%94%AF%E6%8C%81%E6%B8%85%E5%8D%95.md)。 -

API适配开发

+

算子适配开发

- **[前提条件](#前提条件md)** - **[获取PyTorch源码](#获取PyTorch源码md)** -- **[注册API开发](#注册API开发md)** +- **[注册算子开发](#注册算子开发md)** -- **[API适配插件开发](#API适配插件开发md)** +- **[算子适配插件开发](#算子适配插件开发md)** - **[编译和安装PyTorch框架](#编译和安装PyTorch框架md)** @@ -188,52 +189,52 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的API适配。

获取PyTorch源码

-针对pytorch1.8.1版本,PyTorch源码获取请参见[《PyTorch安装指南》](https://gitee.com/ascend/pytorch/blob/master/docs/zh/PyTorch%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97/PyTorch%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97.md)中“安装PyTorch框架”章节,完成在"pytorch/pytorch_v1.8.1"目录生成适配昇腾AI处理器的全量代码步骤。将在pytorch/pytorch目录中进行PyTorch API适配开发。 +针对pytorch1.8.1版本,PyTorch源码获取请参见[《PyTorch安装指南》](https://gitee.com/ascend/pytorch/blob/master/docs/zh/PyTorch%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97/PyTorch%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97.md)中“安装PyTorch框架”章节,完成在"pytorch/pytorch_v1.8.1"目录生成适配昇腾AI处理器的全量代码步骤。将在pytorch/pytorch目录中进行PyTorch 算子适配开发。 -

注册API开发

+

注册算子开发

- **[概述](#概述md)** -- **[PyTorch1.8.1 注册API开发](#PyTorch1-8-1-注册API开发md)** +- **[PyTorch1.8.1 注册算子开发](#PyTorch1-8-1-注册算子开发md)**

概述

-当前制定的NPU适配派发原则是NPUAPI的派发不经过框架公共函数,直接派发成NPU适配的函数,即API执行调用栈中只包含NPU适配的函数调用,不包含框架公共函数。PyTorch框架在编译时,会根据 native\_functions.yaml 的定义,按框架中定义的类型和设备分发原则,生成相应的新API的中间层的调用说明。对于NPU,会生成在 build/aten/src/ATen/NPUType.cpp。 +当前制定的NPU适配派发原则是NPU算子的派发不经过框架公共函数,直接派发成NPU适配的函数,即算子执行调用栈中只包含NPU适配的函数调用,不包含框架公共函数。PyTorch框架在编译时,会根据 native\_functions.yaml 的定义,按框架中定义的类型和设备分发原则,生成相应的新算子的中间层的调用说明。对于NPU,会生成在 build/aten/src/ATen/NPUType.cpp。 -

PyTorch1.8.1 注册API开发

+

PyTorch1.8.1 注册算子开发

-##### 注册API开发方法 +##### 注册算子开发方法 1. 打开native\_functions.yaml文件。 - native\_functions.yaml 文件中,定义了所有API函数原型,包括函数名称和参数等信息,每个API函数支持不同硬件平台的派发信息。该文件所在路径为pytorch/aten/src/ATen/native/native\_functions.yaml。 + native\_functions.yaml 文件中,定义了所有算子函数原型,包括函数名称和参数等信息,每个算子函数支持不同硬件平台的派发信息。该文件所在路径为pytorch/aten/src/ATen/native/native\_functions.yaml。 2. 确定需要派发函数。 - - yaml 中已存在的API + - yaml 中已存在的算子 - 将所有与待适配API相关的函数进行派发。 + 将所有与待适配算子相关的函数进行派发。 - - yaml中未存在的自定义API + - yaml中未存在的自定义算子 - 由于yaml中没有相关API的信息,需要手动添加相关函数,包括函数名,参数信息,返回类型信息。添加规则及方法请参见“pytorch/aten/src/ATen/native/README.md“。 + 由于yaml中没有相关算子的信息,需要手动添加相关函数,包括函数名,参数信息,返回类型信息。添加规则及方法请参见“pytorch/aten/src/ATen/native/README.md“。 ``` - - func:适配API名称(输入参数信息) -> 返回类型 + - func:适配算子名称(输入参数信息) -> 返回类型 ``` ##### 示例 -以torch.add\(\)API为例介绍注册API开发过程。 +以torch.add\(\)算子为例介绍注册算子开发过程。 1. 打开native\_functions.yaml文件。 2. 搜索相关函数。 - 在yaml中搜索add,找到与addAPI相关的函数描述func。由于add是PyTorch内置API,不需要手动添加func。若是自定义API,需要手动添加func。 + 在yaml中搜索add,找到与add算子相关的函数描述func。由于add是PyTorch内置算子,不需要手动添加func。若是自定义算子,需要手动添加func。 -3. 确定API相关函数名称及其类型的func描述。 +3. 确定算子相关函数名称及其类型的func描述。 - add.Tensor 的函数分发描述。 ``` @@ -289,18 +290,18 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的API适配。 -

API适配插件开发

+

算子适配插件开发

#### 简介 -用户通过开发API适配插件,实现PyTorch原生API的输入参数、输出参数和属性的格式转换,使转换后的格式与TBE算子的输入参数、输出参数和属性的格式相同。适配昇腾AI处理器的PyTorch源代码中提供了适配关联、类型转换和判别、处理动态shape等相关的方法供用户使用。 +用户通过开发算子适配插件,实现PyTorch原生算子的输入参数、输出参数和属性的格式转换,使转换后的格式与TBE算子的输入参数、输出参数和属性的格式相同。适配昇腾AI处理器的PyTorch源代码中提供了适配关联、类型转换和判别、处理动态shape等相关的方法供用户使用。 #### npu_native_functions.yaml文件介绍 ``` backend: NPU # Backend类型 -cpp_namespace: at_npu::native # 插件中开发API的命名空间 -supported: # 已支持的和PyTorch Native Functions对齐的API +cpp_namespace: at_npu::native # 插件中开发算子的命名空间 +supported: # 已支持的和PyTorch Native Functions对齐的算子 - add.Tensor - add.Scalar - slow_conv3d.out @@ -313,10 +314,10 @@ supported: # 已支持的和PyTorch Native Functions对齐的API - addcdiv_ - addcdiv.out -autograd: # 已支持的和PyTorch Native Functions对齐的继承自Function的具有前反向操作的API +autograd: # 已支持的和PyTorch Native Functions对齐的继承自Function的具有前反向操作的算子 - maxpool2d -custom: # 自定义API,需要提供API格式定义 +custom: # 自定义算子,需要提供算子格式定义 - func: npu_dtype_cast(Tensor self, ScalarType dtype) -> Tensor variants: function, method - func: npu_dtype_cast_(Tensor(a!) self, Tensor src) -> Tensor(a!) @@ -326,21 +327,21 @@ custom: # 自定义API,需要提供API格式定义 - func: npu_get_float_status(Tensor self) -> Tensor variants: function, method -custom_autograd: # 自定义继承自Function的自定义API +custom_autograd: # 自定义继承自Function的自定义算子 - func: npu_convolution(Tensor input, Tensor weight, Tensor? bias, ...) -> Tensor ``` -官方提供的native_functions.yaml文件定义了PyTorch Native Functions的具体API定义和分发细节,在NPU设备上适配官方已定义API,我们不需要重新定义,只需要注册NPU分发即可。由于我们可以根据已支持的API(supported,autograd)对应解析官方yaml文件得到每个函数的具体格式,所以对应的函数声明和注册分发可以自动化完成,API迁移和开发的时候只需要关注对应的实现细节即可。对于自定义API,由于没有具体的API定义,我们需要在npu_native_functions.yaml文件中给出定义,以便对API进行结构化解析从而实现自动化注册和Python接口绑定。 +官方提供的native_functions.yaml文件定义了PyTorch Native Functions的具体算子定义和分发细节,在NPU设备上适配官方已定义算子,我们不需要重新定义,只需要注册NPU分发即可。由于我们可以根据已支持的算子(supported,autograd)对应解析官方yaml文件得到每个函数的具体格式,所以对应的函数声明和注册分发可以自动化完成,算子迁移和开发的时候只需要关注对应的实现细节即可。对于自定义算子,由于没有具体的算子定义,我们需要在npu_native_functions.yaml文件中给出定义,以便对算子进行结构化解析从而实现自动化注册和Python接口绑定。 #### 适配插件实现 -1. 注册API。 +1. 注册算子。 - 根据npu_native_functions.yaml文件介绍,添加相应API信息。 + 根据npu_native_functions.yaml文件介绍,添加相应算子信息。 2. 创建适配插件文件。 - NPU TBE算子适配文件保存在pytorch/torch_npu/csrc/aten/ops目录下,命名风格采用大驼峰,命名格式: + .cpp,如:AddKernelNpu.cpp。 + NPU TBE算子适配文件保存在pytorch/torch_npu/csrc/aten/ops目录下,命名风格采用大驼峰,命名格式:<算子名\> + .cpp,如:AddKernelNpu.cpp。 3. 引入依赖头文件。 @@ -349,25 +350,25 @@ custom_autograd: # 自定义继承自Function的自定义API >![](public_sys-resources/icon-note.gif) **说明:** >工具的功能和使用方法,可查看头文件和源码获得。 -4. 定义API适配主体函数。 +4. 定义算子适配主体函数。 - 根据注册API开发中的分发函数确定自定义API适配主体函数。 + 根据注册算子开发中的分发函数确定自定义算子适配主体函数。 5. 分别实现适配主体函数。 - 实现API适配主题函数,根据TBE算子原型构造得到对应的input、output、attr。 + 实现算子适配主题函数,根据TBE算子原型构造得到对应的input、output、attr。 #### 示例 -以torch.add\(\)API为例介绍API适配开发过程。 +以torch.add\(\)算子为例介绍算子适配开发过程。 -1. 注册API。 +1. 注册算子。 - 将addAPI添加到npu_native_functions.yaml文件的对应位置,用于自动化声明和注册。 + 将add算子添加到npu_native_functions.yaml文件的对应位置,用于自动化声明和注册。 ``` - supported: #已支持的Pytorch Native Functions 对齐的API + supported: #已支持的Pytorch Native Functions 对齐的算子 add.Tensor add_.Tensor add.out @@ -397,7 +398,7 @@ custom_autograd: # 自定义继承自Function的自定义API >" CalcuOpUtil.h "中主要包含类型转换和判别的函数。 >" OpAdapter.h"文件中主要包含适配关联的头文件。 -4. 定义API适配主体函数。 +4. 定义算子适配主体函数。 ``` at::Tensor NPUNativeFunctions::add(const at::Tensor &self, const at::Tensor &other, at::Scalar alpha) @@ -409,7 +410,7 @@ custom_autograd: # 自定义继承自Function的自定义API > ![](public_sys-resources/icon-note.gif) **说明:** > - > NPUNativeFunctions是API定义需要添加的命名空间约束。 + > NPUNativeFunctions是算子定义需要添加的命名空间约束。 5. 分别实现适配主体函数。 @@ -596,7 +597,7 @@ pip3 install --upgrade torch_npu-1.8.1rc1-cp37-cp37m-linux_{arch}.whl 修改代码之后,需要重新执行“编译”和“安装”PyTorch插件过程。 -

API功能验证

+

算子功能验证

- **[概述](#概述-0md)** @@ -607,13 +608,13 @@ pip3 install --upgrade torch_npu-1.8.1rc1-cp37-cp37m-linux_{arch}.whl #### 简介 -完成API适配开发后,可通过运行适配昇腾处理器的PyTorchAPI,验证API运行结果是否正确。 +完成算子适配开发后,可通过运行适配昇腾处理器的PyTorch算子,验证算子运行结果是否正确。 -API功能验证会覆盖API开发的所有交付件,包含实现文件,API原型定义、API信息库以及API适配插件。本节仅对验证的方法做介绍。 +算子功能验证会覆盖算子开发的所有交付件,包含实现文件,算子原型定义、算子信息库以及算子适配插件。本节仅对验证的方法做介绍。 #### 测试用例及测试工具 -进行自定义API功能验证,通过PyTorch前端构造自定义API的函数并运行验证。 +进行自定义算子功能验证,通过PyTorch前端构造自定义算子的函数并运行验证。 在https://gitee.com/ascend/pytorch 中 "pytorch/test/test_network_ops"目录下提供了测试用例及测试工具,供用户参考。 @@ -621,7 +622,7 @@ API功能验证会覆盖API开发的所有交付件,包含实现文件,API #### 简介 -本章通过具体例子,完成PyTorchAPI的功能测试步骤。 +本章通过具体例子,完成PyTorch算子的功能测试步骤。 #### 操作步骤 @@ -634,7 +635,7 @@ API功能验证会覆盖API开发的所有交付件,包含实现文件,API ${HOME}/Ascend/ascend-toolkit/set_env.sh ``` -2. 编写测试脚本。以addAPI为例,在“pytorch/test/test\_network\_ops“路径下编写测试脚本文件: test\_add.py。 +2. 编写测试脚本。以add算子为例,在“pytorch/test/test\_network\_ops“路径下编写测试脚本文件: test\_add.py。 ``` # 引入依赖库 @@ -795,7 +796,7 @@ pip3.7 install torchvision --no-deps #### 现象描述 -完成“自定义TBE算子”开发,和“PyTorch”适配开发,但执行测试用例,发现无法调用到新开发的API。 +完成“自定义TBE算子”开发,和“PyTorch”适配开发,但执行测试用例,发现无法调用到新开发的算子。 #### 可能原因 @@ -805,15 +806,15 @@ pip3.7 install torchvision --no-deps #### 处理方法 -1. 参考“[API功能验证](#API功能验证md)”章节,完成运行环境设置,特别注意: +1. 参考“[算子功能验证](#算子功能验证md)”章节,完成运行环境设置,特别注意: ``` . /home/HwHiAiUser/Ascend/ascend-toolkit/set_env.sh ``` -2. 检查yaml文件中对应API的分发配置,是否正确的完整分发; +2. 检查yaml文件中对应算子的分发配置,是否正确的完整分发; 3. 分析排查代码实现,建议手段: - 1. 修改"pytorch"中的API适配实现,让“test\_add.py”可以调用到“自定义API包”中的TBE算子; + 1. 修改"pytorch"中的算子适配实现,让“test\_add.py”可以调用到“自定义算子包”中的TBE算子; "pytorch/aten/src/ATen/native/npu/AddKernelNpu.cpp" @@ -829,44 +830,44 @@ pip3.7 install torchvision --no-deps 至此步骤,不应该有错误,屏幕应该输出 "add" 中增加的日志打印。若出错,请完成代码清理排查,保证无新开发的代码影响测试。 - 3. 将新开发的“自定义TBE算子”合并到"cann"中,在对应的在API入口增加日志打印,作为运行标识。 + 3. 将新开发的“自定义TBE算子”合并到"cann"中,在对应的在算子入口增加日志打印,作为运行标识。 4. 完成上面的"cann"编译、安装,调用“python3.7.5 test\_add.py”进行测试。 >![](public_sys-resources/icon-note.gif) **说明:** - >根据Ascend的设计逻辑,用户开发安装的“custom”API包优先级高于“built-in”的内置API包,在运行加载时,会优先加载调度“custom”包中的API。过程中,若解析“custom”中的API信息文件失败,则会跳过“custom”API包,不加载调度任何“custom”API包中的任何API。 + >根据Ascend的设计逻辑,用户开发安装的“custom”算子包优先级高于“built-in”的内置算子包,在运行加载时,会优先加载调度“custom”包中的算子。过程中,若解析“custom”中的算子信息文件失败,则会跳过“custom”算子包,不加载调度任何“custom”算子包中的任何算子。 > - >- 若此步骤出错,或屏幕未输出 "add" 中增加的日志打印,则说明新开发的“自定义TBE算子”有错误,影响了“自定义API包”的加载,建议**优先排查新开发的“自定义TBE算子”中的“API信息定义”是否正确**。 - >- 若此步骤正确,至少说明 **新开发的“自定义TBE算子”中的“API信息定义”不影响运行**。 + >- 若此步骤出错,或屏幕未输出 "add" 中增加的日志打印,则说明新开发的“自定义TBE算子”有错误,影响了“自定义算子包”的加载,建议**优先排查新开发的“自定义TBE算子”中的“算子信息定义”是否正确**。 + >- 若此步骤正确,至少说明 **新开发的“自定义TBE算子”中的“算子信息定义”不影响运行**。 5. 调用“python3.7.5 xxx\_testcase.py”进行测试; >![](public_sys-resources/icon-note.gif) **说明:** - >- 若屏幕正常输出新开发的“自定义TBE算子”中增加的日志打印,则至少说明调度到了新开发的API。 + >- 若屏幕正常输出新开发的“自定义TBE算子”中增加的日志打印,则至少说明调度到了新开发的算子。 >- 若屏幕未输出新开发的“自定义TBE算子”中增加的日志打印,则问题可能出现在“PyTorch适配”中,需要排查这一部分的实现代码,较多的可能会出现在“XxxxKernelNpu.cpp”中的输入、输出未能正确适配。

如何确定“TBE算子”是否被“PyTorch适配”正确调用

-不管是“custom”API,还是“built-in”API,在安装后,都是以\*.py源码的方式存放在安装目录下,所以我们可以通过编辑源码,在API入口增加日志的方式,打印输出入参,确定输入的参数是否正确。 +不管是“custom”算子,还是“built-in”算子,在安装后,都是以\*.py源码的方式存放在安装目录下,所以我们可以通过编辑源码,在API入口增加日志的方式,打印输出入参,确定输入的参数是否正确。 >![](public_sys-resources/icon-caution.gif) **注意:** >该操作存在风险,建议在操作前备份计划修改的文件。若未备份,损坏后无法恢复,请及时联系支持人员。 -下面以"built-in"API中的"zn\_2\_nchw"API为例: +下面以"built-in"算子中的"zn\_2\_nchw"算子为例: -1. 打开安装在用户目录下的API包安装目录。 +1. 打开安装在用户目录下的算子包安装目录。 ``` cd ~/.local/Ascend/opp/op_impl/built-in/ai_core/tbe/impl ll ``` - 可以看到相应的API\*.py源码文件均为“只读”,即此时不可编辑。 + 可以看到相应的算子\*.py源码文件均为“只读”,即此时不可编辑。 ![](figures/zh-cn_image_0000001190081791.png) -2. 修改API\*.py源码文件属性,增加“可写”权限。 +2. 修改算子\*.py源码文件属性,增加“可写”权限。 ``` sudo chmod +w zn_2_nchw.py @@ -875,7 +876,7 @@ pip3.7 install torchvision --no-deps ![](figures/zh-cn_image_0000001190081803.png) -3. 打开API\*.py源码文件,增加日志,保存退出。 +3. 打开算子\*.py源码文件,增加日志,保存退出。 ``` vi zn_2_nchw.py @@ -886,8 +887,8 @@ pip3.7 install torchvision --no-deps 上面例子只加了个标识,实际调测时,可以增加打印输入参数信息。 4. 调用脚本执行测试用例,通过打印日志分析“输入参数信息”。 -5. 完成测试分析后,重新打开API\*.py源码文件,删除增加的日志,保存退出。 -6. 修改API\*.py源码文件属性,删除“可写”权限。 +5. 完成测试分析后,重新打开算子\*.py源码文件,删除增加的日志,保存退出。 +6. 修改算子\*.py源码文件属性,删除“可写”权限。 ``` sudo chmod -w zn_2_nchw.py @@ -906,7 +907,7 @@ PyTorch编译失败,提示“ error: ld returned 1 exit status”。 #### 可能原因 -通过日志分析,大概原因为XxxxKernelNpu.cpp中实现的适配函数,与PyTorch框架API要求的分发实现接口参数不匹配。在上面的例子中,是“binary\_cross\_entropy\_npu”,打开对应的XxxxKernelNpu.cpp文件,找到相应的适配函数。 +通过日志分析,大概原因为XxxxKernelNpu.cpp中实现的适配函数,与PyTorch框架算子要求的分发实现接口参数不匹配。在上面的例子中,是“binary\_cross\_entropy\_npu”,打开对应的XxxxKernelNpu.cpp文件,找到相应的适配函数。 ![](figures/zh-cn_image_0000001144241896.png) @@ -944,7 +945,7 @@ PyTorch编译失败,提示“error: call of overload ....”。 - **[CMake安装方法](#CMake安装方法md)** -- **[自定义API导出方法](#自定义API导出方法md)** +- **[自定义算子导出方法](#自定义算子导出方法md)**

CMake安装方法

@@ -990,7 +991,7 @@ PyTorch编译失败,提示“error: call of overload ....”。 #### 简介 -PyTorch训练模型中包含自定义API,将自定义API导出成onnx单API模型,方便转移到其他AI框架中使用。自定义API导出有三种形式,适配NPU的TBE算子导出、C++API导出、纯PythonAPI导出。 +PyTorch训练模型中包含自定义算子,将自定义算子导出成onnx单算子模型,方便转移到其他AI框架中使用。自定义算子导出有三种形式,适配NPU的TBE算子导出、C++算子导出、纯Python算子导出。 #### 前提条件 @@ -1002,10 +1003,10 @@ TBE算子导出有两种方式。 方式一: -1. 定义和注册API +1. 定义和注册算子 ``` - # 定义API + # 定义算子 @parse_args('v', 'v', 'f', 'i', 'i', 'i', 'i') def symbolic_npu_roi_align(g, input, rois, spatial_scale, pooled_height, pooled_width, sample_num, roi_end_mode): args = [input, rois] @@ -1017,7 +1018,7 @@ TBE算子导出有两种方式。 return g.op('torch::npu_roi_align',*args, **kwargs) - # 注册API + # 注册算子 import torch.onnx.symbolic_registry as sym_registry def register_onnx_sym_npu_roi_align(): sym_registry.register_op('npu_roi_align', symbolic_npu_roi_align, '', 11) @@ -1072,7 +1073,7 @@ TBE算子导出有两种方式。 1. 定义方法类 ``` - # 实现API方法类及符号导出实现的方法 + # 实现算子方法类及符号导出实现的方法 class CustomClassOp_Func_npu_roi_align(Function): @staticmethod def forward(ctx, input, rois, spatial_scale, pooled_height, pooled_width , sample_num, roi_end_mode): @@ -1090,10 +1091,10 @@ TBE算子导出有两种方式。 return g.op('torch::npu_roi_align',*args, **kwargs) ``` -2. 自定义API模型 +2. 自定义算子模型 ``` - # 实现API模型 + # 实现算子模型 class NpuOp_npu_roi_align_Module(torch.nn.Module): def __init__(self): super(NpuOp_npu_roi_align_Module, self).__init__() @@ -1151,15 +1152,15 @@ TBE算子导出有两种方式。 >![](public_sys-resources/icon-note.gif) **说明:** >详细实现代码请参见[test\_custom\_ops\_npu\_demo.py](https://gitee.com/ascend/pytorch/blob/master/test/test_npu/test_onnx/torch.onnx/custom_ops_demo/test_custom_ops_npu_demo.py),如无权限获取代码,请联系华为技术支持申请加入“Ascend”组织。 -#### C++API导出 +#### C++算子导出 -1. 自定义API +1. 自定义算子 ``` import torch import torch_npu import torch.utils.cpp_extension - # 定义C++实现的API + # 定义C++实现的算子 def test_custom_add(): op_source = """ #include @@ -1180,10 +1181,10 @@ TBE算子导出有两种方式。 test_custom_add() ``` -2. 注册自定义API +2. 注册自定义算子 ``` - # 定义API注册方法并注册API + # 定义算子注册方法并注册算子 from torch.onnx import register_custom_op_symbolic def symbolic_custom_add(g, self, other): @@ -1195,16 +1196,16 @@ TBE算子导出有两种方式。 3. 建立模型 ``` - # 建立API模型 + # 建立算子模型 class CustomAddModel(torch.nn.Module): def forward(self, a, b): return torch.ops.custom_namespace.custom_add(a, b) ``` -4. 导出APIonnx模型 +4. 导出算子onnx模型 ``` - # 将API导出onnx模型 + # 将算子导出onnx模型 def do_export(model, inputs, *args, **kwargs): out = torch.onnx._export(model, inputs, "custom_demo.onnx", *args, **kwargs) @@ -1218,9 +1219,9 @@ TBE算子导出有两种方式。 >![](public_sys-resources/icon-note.gif) **说明:** >详细实现代码请参见[test\_custom\_ops\_demo.py](https://gitee.com/ascend/pytorch/blob/master/test/test_npu/test_onnx/torch.onnx/custom_ops_demo/test_custom_ops_demo.py),如无权限获取代码,请联系华为技术支持申请加入“Ascend”组织。 -#### 纯PythonAPI导出 +#### 纯Python算子导出 -1. 自定义API +1. 自定义算子 ``` import torch @@ -1237,7 +1238,7 @@ TBE算子导出有两种方式。 import math from torch.nn import init - # 定义API类方法 + # 定义算子类方法 class CustomClassOp_Add_F(Function): @staticmethod def forward(ctx, input1,input2): @@ -1257,7 +1258,7 @@ TBE算子导出有两种方式。 2. 建立模型 ``` - # 注册API并建立模型 + # 注册算子并建立模型 class CustomClassOp_Add(torch.nn.Module): def __init__(self): super(CustomClassOp_Add, self).__init__() @@ -1283,7 +1284,7 @@ TBE算子导出有两种方式。 return rtn ``` -3. 导出APIonnx模型 +3. 导出算子onnx模型 ``` ONNX_FILE_NAME = "./custom_python_module_demo.onnx" @@ -1298,7 +1299,7 @@ TBE算子导出有两种方式。 output = model(input) do_export(model, input, opset_version=11) - # 将API导出到onnx模型 + # 将算子导出到onnx模型 test_class_export() ``` diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/PyTorch\346\241\206\346\236\266\344\270\213\347\232\204\347\256\227\345\255\220\351\200\202\351\205\215\346\265\201\347\250\213.png" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/PyTorch\346\241\206\346\236\266\344\270\213\347\232\204\347\256\227\345\255\220\351\200\202\351\205\215\346\265\201\347\250\213.png" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/PyTorch\346\241\206\346\236\266\344\270\213\347\232\204\347\256\227\345\255\220\351\200\202\351\205\215\346\265\201\347\250\213.png" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/PyTorch\346\241\206\346\236\266\344\270\213\347\232\204\347\256\227\345\255\220\351\200\202\351\205\215\346\265\201\347\250\213.png" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082048.png" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082048.png" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082048.png" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082048.png" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082056.png" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082056.png" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082056.png" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082056.png" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082064.png" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082064.png" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082064.png" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082064.png" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082072.png" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082072.png" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082072.png" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082072.png" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082088.png" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082088.png" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082088.png" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144082088.png" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144241896.png" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144241896.png" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144241896.png" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001144241896.png" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190081791.png" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190081791.png" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190081791.png" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190081791.png" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190081803.png" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190081803.png" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190081803.png" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190081803.png" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201935.png" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201935.png" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201935.png" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201935.png" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201951.png" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201951.png" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201951.png" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201951.png" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201973.png" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201973.png" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201973.png" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/figures/zh-cn_image_0000001190201973.png" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-caution.gif" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-caution.gif" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-caution.gif" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-caution.gif" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-danger.gif" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-danger.gif" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-danger.gif" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-danger.gif" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-note.gif" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-note.gif" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-note.gif" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-note.gif" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-notice.gif" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-notice.gif" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-notice.gif" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-notice.gif" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-tip.gif" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-tip.gif" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-tip.gif" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-tip.gif" diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-warning.gif" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-warning.gif" similarity index 100% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-warning.gif" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/public_sys-resources/icon-warning.gif" 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 6259e6c9c5..343f3ded6f 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" @@ -1468,7 +1468,7 @@ CANN Profiling数据采集 optimizer.zero_grad() optimizer.step() ``` - 其中config参数用于配置需要获取CANN的性能数据种类,设置方法见[E2E prof高级设置](#E2E prof高级设置)中的config参数说明。 + 其中config参数用于配置需要获取CANN的性能数据种类,设置方法见[E2E prof高级设置](#E2E)中的config参数说明。 >![](public_sys-resources/icon-note.gif) **说明:** >获取性能数据文件时,model、input\_tensor、target需要下发到npu上。 @@ -1544,7 +1544,7 @@ d. timeline路径下为解析得到的性能数据,可以通过chrome://tracin 该示例分为4个层次,由上到下,第一层(MsprofTx)为Pytorch框架数据,第二层(AscendCL)为ACL层面数据,第三层(Task Scheduler)为device数据,第四层(AI CPU)为AICPU数据。 -3. E2E profiling高级设置 +3. E2E profiling高级设置 E2E prof工具默认配置获取上述所有层面数据。获取数据过程亦会影响性能,若获取数据过多,会导致性能数据不具备参考价值。因此,E2E prof工具提供了可配置选项,用于精细化控制获取部分层面数据。 ``` -- Gitee

配置项

说明

@@ -244,11 +144,6 @@

aicpu算子包路径。

TASK_QUEUE_ENABLE

-

使用异步任务下发,异步调用acl接口。建议开启,开启设置为1。

-

HCCL_WHITELIST_DISABLE

配置在使用HCCL时是否开启通信白名单。

@@ -281,11 +176,6 @@
  • 0:不开启Event日志。
  • 1:开启Event日志。
  • 其他值为非法值。

DYNAMIC_COMPILE_ENABLE

-

(可选)动态shape特性功能,针对shape变化场景,开启设置为1(PyTorch1.8.1不支持该环境变量)。

-

COMBINED_ENABLE

(可选)非连续两个算子组合类场景优化,开启设置为1。

@@ -296,11 +186,6 @@

(可选)算子数据dump功能,调试时使用,开启设置为1。

DYNAMIC_OP

-

(可选)算子实现,ADD和MUL算子在不同场景下有不同的性能表现。默认不设置。

-

unset GOMP_CPU_AFFINITY

(可选)当系统为openEuler及其继承操作系统时,如UOS,需设置此命令,取消CPU绑核。

@@ -311,243 +196,295 @@ -

安装混合精度模块

-#### 前提条件 +## 执行单元测试脚本 + +验证运行, 输出结果OK + +```shell +cd test/test_network_ops/ +python3 test_div.py +``` + +# 安装混合精度模块(可选) -1. 请确保运行环境中适配昇腾AI处理器的PyTorch框架能正常使用。 -2. 编译安装Apex前,需参见[配置环境变量](#配置环境变量md)配置好编译过程依赖的环境变量。 +AscendPyTorch1.8.1集成了AMP模块,也可用于混合精度训练等应用场景,与Apex模块的区别如下,请用户根据功能需要选择使用,若需安装Apex模块请参考相关[README文档](https://gitee.com/ascend/apex)进行编译安装Apex模块。 -#### 安装流程 +- AMP -1. 以root或非root用户登录服务器。 -2. 获取apex源代码。 + - 动态loss scale:动态计算loss scale的值并判断是否溢出。 + - 不支持tensor融合功能。 - 1. 运行如下命令,获取适配昇腾AI处理器的apex源代码。 +- APEX - ``` - git clone -b master https://gitee.com/ascend/apex.git - ``` + - O1配置模式:Conv,Matmul等使用float16精度计算,其他如softmax、BN使用float32精度。 + - O2配置模式:除BN使用float32精度外,其他部分使用float16精度。 + - 静态loss scale:静态设置参数确保混合精度训练收敛。 + - 动态loss scale:动态计算loss scale的值并判断是否溢出。 - 下载的源码主要目录结构如下所示: - ``` - apex - │ ├─patch # 昇腾AI处理器适配补丁目录 - │ ├─npu.patch - │ ├─scripts # 编译构建目录 - │ ├─gen.sh - │ ├─src # 源码目录 - │ ├─tests # 测试用例存放目录 - ``` +# FAQ - 2. 运行如下命令,进入“apex“目录,并获取原生apex源代码。 +## CPU架构为ARM架构时,由于社区未提供ARM架构CPU版本的torch包,无法使用PIP3命令安装PyTorch1.8.1,需要使用源码编译安装。 - ``` - cd apex - git clone https://github.com/NVIDIA/apex.git - ``` +下载PyTorch v1.8.1源码包。 - 下载原生apex源码后,代码主要目录结构如下所示: +``` +git clone -b v1.8.1 https://github.com/pytorch/pytorch.git --depth=1 pytorch_v1.8.1 +``` - ``` - apex - │ ├─apex # 原生apex代码目录 - │ ├─patch # 昇腾AI处理器适配补丁目录 - │ ├─npu.patch - │ ├─scripts # 编译构建目录 - │ ├─gen.sh - │ ├─src # 源码目录 - │ ├─tests # 测试用例存放目录 - ``` +进入源码包获取被动依赖代码。 - 3. 进入原生apex代码目录,即“apex/apex“目录。切换至commitid为4ef930c1c884fdca5f472ab2ce7cb9b505d26c1a的代码分支。 +``` +cd pytorch_v1.8.1 +git submodule sync +git submodule update --init --recursive +``` - ``` - cd apex - git checkout 4ef930c1c884fdca5f472ab2ce7cb9b505d26c1a - ``` +执行编译安装。 - >![](public_sys-resources/icon-note.gif) **说明:** - >受网络波动影响,源码获取时间可能较长,下载过程中请耐心等待。 +``` +python3 setup.py install +``` -3. 编译生成适配昇腾AI处理器的apex安装包。 - 1. 进入“apex/scripts“文件夹,执行转换脚本,生成适配昇腾AI处理器的全量代码。 +## 在PIP设置为华为源时,安装requirments.txt中的typing依赖后,会导致python环境错误。 - ``` - cd ../scripts - bash gen.sh - ``` +在PIP设置为华为源时,需打开requirments.txt文件,删除typing依赖,再执行命令。 - 将在"apex/apex"目录中生成适配昇腾AI处理器的全量代码。 +``` +pip3 install -r requirments.txt +``` - 2. 进入适配后的全量代码目录,即“apex/apex“目录,编译生成apex的二进制安装包。 +## 编译过程执行bash build.sh报错no module named yaml/typing_extensions. - ``` - cd ../apex - python3 setup.py --cpp_ext --npu_float_status bdist_wheel - ``` +pytorch编译依赖 yaml库和typing_extensions库,需要手动安装。 - Python版本需与PyTorch使用的Python一致,生成的二进制包在当前的dist目录下,即“apex/apex/dist”文件夹目录下。 +``` +pip3 install pyyaml -4. 安装apex。 +pip3 install typing_extensions +``` - 进入“apex/apex/dist“文件夹目录,执行如下命令安装。 +安装成功后,注意需要执行make clean在执行bash build.sh进行编译,否则可能因缓存出现未知编译错误。 - ``` - cd dist - pip3 install --upgrade apex-0.1+ascend-cp37-cp37m-linux_{arch}.whl - ``` - - **\{arch\}**表示架构信息,为aarch64或x86\_64。 - - >![](public_sys-resources/icon-note.gif) **说明:** - >若对环境中的Apex进行升级时,需要先卸载环境中已安装的PyTorch软件包再执行[4. 安装apex。](#zh-cn_topic_0000001106176190_li425495374416)可以通过执行如下命令查询环境上是否已安装PyTorch。 - >**pip3 list | grep apex** +## 运行遇到找不到te问题 +开发态: -

参考信息

+``` +cd /urs/local/Ascend/ascend-toolkit/latest/{arch}-linux/lib64 +``` -- **[CMake安装方法](#CMake安装方法md)** +用户态: -- **[安装7.3.0版本gcc](#安装7-3-0版本gccmd)** +``` +cd /urs/local/Ascend/nnae/latest/{arch}-linux/lib64 -- **[安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配](#安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配md)** +pip3 install --upgrade topi-0.4.0-py3-none-any.whl +pip3 install --upgrade te-0.4.0-py3-none-any.whl +``` -

CMake安装方法

+## 命令行安装cmake依赖时提示找不到包、编译cmake报错版本过低,可使用安装脚本或源码编译安装。 -CMake版本升级为3.12.1的方法 +下载安装脚本安装cmake。(参考cmake官网) -1. 获取Cmake软件包。 +​ X86_64环境推荐脚本安装:cmake-3.12.0-Linux-x86_64.sh - ``` - wget https://cmake.org/files/v3.12/cmake-3.12.1.tar.gz --no-check-certificate - ``` -2. 解压并进入软件包目录。 +部分源下载cmake时会提示无法找到包,需要使用源码编译安装。 - ``` - tar -xf cmake-3.12.1.tar.gz - cd cmake-3.12.1/ - ``` +1. 获取Cmake软件包。 -3. 执行配置、编译和安装命令。 + ``` + wget https://cmake.org/files/v3.12/cmake-3.12.0.tar.gz --no-check-certificate + ``` - ``` - ./configure --prefix=/usr/local/cmake - make && make install - ``` +2. 解压并进入软件包目录。 -4. 设置软连接。 + ``` + tar -xf cmake-3.12.0.tar.gz + cd cmake-3.12.0/ + ``` - ``` - ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake - ``` +3. 执行配置、编译和安装命令。 -5. 执行如下命令验证是否安装成功。 + ``` + ./configure --prefix=/usr/local/cmake + make && make install + ``` - ``` - cmake --version - ``` +4. 设置软连接。 - 如显示“cmake version 3.12.1”则表示安装成功。 + ``` + ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake + ``` +5. 执行如下命令验证是否安装成功。 -

安装7.3.0版本gcc

+ ``` + cmake --version + ``` + + 如显示“cmake version 3.12.0”则表示安装成功。 + +## 命令行安装gcc依赖时提示找不到包、编译时gcc报错问题 + +部分源下载gcc时会提示无法找到包,需要使用源码编译安装。 以下步骤请在root用户下执行。 -1. 下载gcc-7.3.0.tar.gz,下载地址为[https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz](https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz)。 -2. 安装gcc时候会占用大量临时空间,所以先执行下面的命令清空/tmp目录: +1. 下载gcc-7.3.0.tar.gz,下载地址为[https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz](https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz)。 + +2. 安装gcc时候会占用大量临时空间,所以先执行下面的命令清空/tmp目录: + + ``` + sudo rm -rf /tmp/* + ``` + +3. 安装依赖(以CentOS和Ubuntu系统为例)。 + + - CentOS执行如下命令安装。 + + ``` + yum install bzip2 + ``` - ``` - sudo rm -rf /tmp/* - ``` + - Ubuntu执行如下命令安装。 -3. 安装依赖(以CentOS和Ubuntu系统为例)。 - - CentOS执行如下命令安装。 + ``` + apt-get install bzip2 + ``` - ``` - yum install bzip2 - ``` +4. 编译安装gcc。 - - Ubuntu执行如下命令安装。 + 1. 进入gcc-7.3.0.tar.gz源码包所在目录,解压源码包,命令为: - ``` - apt-get install bzip2 - ``` + ``` + tar -zxvf gcc-7.3.0.tar.gz + ``` -4. 编译安装gcc。 - 1. 进入gcc-7.3.0.tar.gz源码包所在目录,解压源码包,命令为: + 2. 进入解压后的文件夹,执行如下命令下载gcc依赖包: - ``` - tar -zxvf gcc-7.3.0.tar.gz - ``` + ``` + cd gcc-7.3.0 + ./contrib/download_prerequisites + ``` - 2. 进入解压后的文件夹,执行如下命令下载gcc依赖包: + 如果执行上述命令报错,需要执行如下命令在“gcc-7.3.0/“文件夹下下载依赖包: - ``` - cd gcc-7.3.0 - ./contrib/download_prerequisites - ``` + ``` + wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 + wget http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 + wget http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz + wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2 + ``` - 如果执行上述命令报错,需要执行如下命令在“gcc-7.3.0/“文件夹下下载依赖包: + 下载好上述依赖包后,重新执行以下命令: - ``` - wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 - wget http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 - wget http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz - wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2 - ``` + ``` + ./contrib/download_prerequisites + ``` - 下载好上述依赖包后,重新执行以下命令: + 如果上述命令校验失败,需要确保依赖包为一次性下载成功,无重复下载现象。 - ``` - ./contrib/download_prerequisites - ``` + 3. 执行配置、编译和安装命令: - 如果上述命令校验失败,需要确保依赖包为一次性下载成功,无重复下载现象。 + ``` + ./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/linux_gcc7.3.0 + make -j15 # 通过grep -w processor /proc/cpuinfo|wc -l查看cpu数,示例为15,用户可自行设置相应参数。 + make install + ``` - 3. 执行配置、编译和安装命令: + >![](D:\projects\pzrpytorch\pytorch\docs\zh\PyTorch安装指南\public_sys-resources\icon-notice.gif) **须知:** + >其中“--prefix“参数用于指定linux\_gcc7.3.0安装路径,用户可自行配置,但注意不要配置为“/usr/local“及“/usr“,因为会与系统使用软件源默认安装的gcc相冲突,导致系统原始gcc编译环境被破坏。示例指定为“/usr/local/linux\_gcc7.3.0“。 - ``` - ./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/linux_gcc7.3.0 - make -j15 # 通过grep -w processor /proc/cpuinfo|wc -l查看cpu数,示例为15,用户可自行设置相应参数。 - make install - ``` - >![](public_sys-resources/icon-notice.gif) **须知:** - >其中“--prefix“参数用于指定linux\_gcc7.3.0安装路径,用户可自行配置,但注意不要配置为“/usr/local“及“/usr“,因为会与系统使用软件源默认安装的gcc相冲突,导致系统原始gcc编译环境被破坏。示例指定为“/usr/local/linux\_gcc7.3.0“。 +5. 配置环境变量。 + 当用户执行训练时,需要用到gcc升级后的编译环境,因此要在训练脚本中配置环境变量,通过如下命令配置。 -5. 配置环境变量。 + ``` + export LD_LIBRARY_PATH=${install_path}/lib64:${LD_LIBRARY_PATH} + ``` - 当用户执行训练时,需要用到gcc升级后的编译环境,因此要在训练脚本中配置环境变量,通过如下命令配置。 + 其中$\{install\_path\}为[3.](#zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310)中配置的gcc7.3.0安装路径,本示例为“/usr/local/gcc7.3.0/“。 - ``` - export LD_LIBRARY_PATH=${install_path}/lib64:${LD_LIBRARY_PATH} - ``` + >![](D:\projects\pzrpytorch\pytorch\docs\zh\PyTorch安装指南\public_sys-resources\icon-note.gif) **说明:** + >本步骤为用户在需要用到gcc升级后的编译环境时才配置环境变量。 - 其中$\{install\_path\}为[3.](#zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310)中配置的gcc7.3.0安装路径,本示例为“/usr/local/gcc7.3.0/“。 +目前存在测试环境从GCC4.8.5 切换到 GCC7.3.0。这个过程容易出现错误导致pytorch编译不过,以下是需要软连接的库 - >![](public_sys-resources/icon-note.gif) **说明:** - >本步骤为用户在需要用到gcc升级后的编译环境时才配置环境变量。 +gcc, g++,c++(--version 必须是7.3.0) +libstdc++->libstdc++.so.6.0.24(7.3.0) -

安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配

+## 找不到libblas.so问题 -#### 现象描述 +环境缺少openblas库,需要安装openblas库 -安装“torch-\*.whl”时,提示"ERROR:torchvision 0.6.0 has requirement torch==1.5.0, but you'll have torch 1.5.0a0+1977093 which is incompatible"。 +Centos,EulerOS环境 -![](figures/zh-cn_image_0000001190081735.png) +```sh +yum -y install openblas +``` -#### 可能原因 +Ubuntu环境 -安装torch时,会自动触发torchvision进行依赖版本检查,环境中安装的torchvision版本为0.6.0,检查时发现我们安装的torch-\*.whl的版本号与要求的1.5.0不一致,所以提示报错,但实际安装成功 。 +```sh +apt install libopenblas-dev +``` + +## 容器中未挂载device问题 + +在容器中运行脚本出现NPU相关ERROR。由于启动容器实例时,未挂载device参数,导致无法正常启动实例。 + +![](D:\projects\pzrpytorch\pytorch\figures\FAQ.png) + +请用户参考以下命令,重启容器。 + +```sh +docker run -it --ipc=host \ +--device=/dev/davinciX \ +--device=/dev/davinci_manager \ +--device=/dev/devmm_svm \ +--device=/dev/hisi_hdc \ +-v /usr/local/Ascend/driver \ +-v /usr/local/dcmi \ +-v /usr/local/bin/npu-smi \ +${镜像名称}:{tag} \ +/bin/bash +``` -#### 处理方法 +参数说明: + +/dev/davinciX:NPU设配,X是芯片物理ID号例如davinci0。 + +/dev/davinci_manager:管理设备。 + +/dev/devmm_svm:管理设备。 + +/dev/hisi_hdc:管理设备。 + +/usr/local/Ascend/driver:驱动目录。 + +/usr/local/dcmi:DCMI目录。 + +/usr/local/bin/npu-smi:npu-smi工具。 + +${镜像名称}:{tag}:镜像名称与版本号。 + +## 安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配 + +安装“torch-\*.whl”时,提示"ERROR:torchvision 0.6.0 has requirement torch==1.5.0, but you'll have torch 1.5.0a0+1977093 which is incompatible"。 +![](D:\projects\pzrpytorch\pytorch\figures\zh-cn_image_0000001190081735.png) + +安装torch时,会自动触发torchvision进行依赖版本检查,环境中安装的torchvision版本为0.6.0,检查时发现我们安装的torch-\*.whl的版本号与要求的1.5.0不一致,所以提示报错,但实际安装成功 。 对实际结果无影响,无需处理。 + + +# 版本说明 + +版本说明请参阅[ReleseNote](docs/zh/RELEASENOTE) 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" index 3823b76d11..165c95b85e 100644 --- "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" @@ -715,12 +715,12 @@ pytorch分布式训练基本概念 3. 在每台服务器上分别打开**/etc/hosts**文件,在该文件中添加本服务器对应的IP地址和主机名,且需要添加到该文件的首行。如果文件中已添加,则跳过此步骤。添加内容示例如下: ``` - 10.90.140.199 ubuntu + xxx.xxx.xxx.111 ubuntu ``` - 其中10.90.140.199为该服务器的IP地址,ubuntu为主机名。 + 其中xxx.xxx.xxx.111为该服务器的IP地址,ubuntu为主机名。 - 4. 在第一台服务器执行如下命令生成公钥(例如第一台服务器IP为10.90.140.199)。 + 4. 在第一台服务器执行如下命令生成公钥(例如第一台服务器IP为xxx.xxx.xxx.111)。 ``` cd ~/.ssh/ # 若没有该目录,请先执行一次ssh localhost @@ -749,7 +749,7 @@ pytorch分布式训练基本概念 6. 在其他每台服务器上执行如下命令将第一台服务器制作好的公钥复制到其他每台服务器内。 cd ~/.ssh/ - scp root@10.90.140.199:~/.ssh/authorized_keys ./ + scp root@xxx.xxx.xxx.111:~/.ssh/authorized_keys ./ 7. 在每台服务器执行如下命令测试免密登录。 @@ -757,9 +757,9 @@ pytorch分布式训练基本概念 ssh 用户名@IP地址 ``` - 例如:在第一台服务器10.90.140.199免密登录服务器10.90.140.231,执行**ssh root@10.90.140.231**命令。 + 例如:在第一台服务器xxx.xxx.xxx.111免密登录服务器xxx.xxx.xxx.222,执行**ssh root@xxx.xxx.xxx.222**命令。 - 若显示类似如下信息,说明已免密登录服务器10.90.140.231。 + 若显示类似如下信息,说明已免密登录服务器xxx.xxx.xxx.222。 ``` Linux ubuntu 4.19.28 #1 SMP Tue Jun 23 19:05:23 EDT 2020 x86_64 @@ -777,7 +777,7 @@ pytorch分布式训练基本概念 ``` logout - Connection to 10.90.140.231 closed. + Connection to xxx.xxx.xxx.222 closed. ``` 3. 使用OpenMPI拉起模型训练。 diff --git "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227.md" "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227.md" similarity index 82% rename from "docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227.md" rename to "docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227.md" index b1b3aa8e14..aa64a03016 100644 --- "a/docs/zh/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227/PyTorch API\345\274\200\345\217\221\346\214\207\345\215\227.md" +++ "b/docs/zh/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227/PyTorch\347\256\227\345\255\220\345\274\200\345\217\221\346\214\207\345\215\227.md" @@ -1,18 +1,18 @@ -# PyTorch API开发指南 +# PyTorch 算子开发指南 - [简介](#简介md) - [算子开发流程](#算子开发流程md) - [算子开发准备](#算子开发准备md) - [环境准备](#环境准备md) - - [API速查](#API速查md) -- [API适配开发](#API适配开发md) + - [算子速查](#算子速查md) +- [算子适配开发](#算子适配开发md) - [前提条件](#前提条件md) - [获取PyTorch源码](#获取PyTorch源码md) - - [注册API开发](#注册API开发md) + - [注册算子开发](#注册算子开发md) - [概述](#概述md) - - [PyTorch1.8.1 注册API开发](#PyTorch1-8-1-注册API开发md) - - [API适配插件开发](#API适配插件开发md) + - [PyTorch1.8.1 注册算子开发](#PyTorch1-8-1-注册算子开发md) + - [算子适配插件开发](#算子适配插件开发md) - [编译和安装PyTorch框架](#编译和安装PyTorch框架md) -- [API功能验证](#API功能验证md) +- [算子功能验证](#算子功能验证md) - [概述](#概述-0md) - [实现过程](#实现过程md) - [FAQ](#FAQmd) @@ -26,7 +26,7 @@ - [PyTorch编译失败,提示“error: call of overload ....”](#PyTorch编译失败-提示-error-call-of-overloadmd) - [附录](#附录md) - [CMake安装方法](#CMake安装方法md) - - [自定义API导出方法](#自定义API导出方法md) + - [自定义算子导出方法](#自定义算子导出方法md)

简介

### 概述 @@ -35,17 +35,17 @@

算子开发流程

-PyTorch算子开发包含TBE算子开发和PyTorch框架下的API适配。 +PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。 -1. TBE算子开发:昇腾AI软件栈中不包含相应的算子,需要先完成TBE算子的开发,再进行PyTorch框架下的API适配。 +1. TBE算子开发:昇腾AI软件栈中不包含相应的算子,需要先完成TBE算子的开发,再进行PyTorch框架下的算子适配。 TBE算子开发流程及方法请参见《CANN TBE自定义算子开发指南》。 -2. PyTorch框架下的API适配:昇腾AI软件栈中已实现了相应的TBE算子,可直接进行PyTorch框架适配。 +2. PyTorch框架下的算子适配:昇腾AI软件栈中已实现了相应的TBE算子,可直接进行PyTorch框架适配。 - PyTorch框架下的API适配流程如下所示。 + PyTorch框架下的算子适配流程如下所示。 - **图 1** PyTorch框架下的API适配流程 + **图 1** PyTorch框架下的算子适配流程 ![](figures/PyTorch框架下的算子适配流程.png "PyTorch框架下的算子适配流程") **表 1** 算子开发步骤详解 @@ -68,15 +68,15 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的API适配。

准备算子开发及运行验证所依赖的开发环境与运行环境。

算子开发准备

+

算子开发准备

2

API速查

+

算子速查

查看TBE算子支持列表和PyTorchAPI适配列表。

-
  • 当前昇腾AI处理器支持的算子列表及支持的算子的详细规格约束。
  • 当前PyTorch适配的API列表。
+

查看TBE算子支持列表和PyTorch算子适配列表。

+
  • 当前昇腾AI处理器支持的算子列表及支持的算子的详细规格约束。
  • 当前PyTorch适配的算子列表。

3

@@ -85,7 +85,7 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的API适配。

获取昇腾社区PyTorch源码。

API适配开发

+

算子适配开发

4

@@ -97,9 +97,9 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的API适配。

5

API适配层开发

+

算子适配层开发

API适配层开发,将基于第三方框架的算子属性映射成适配昇腾AI处理器的算子属性。

+

算子适配层开发,将基于第三方框架的算子属性映射成适配昇腾AI处理器的算子属性。

6

@@ -111,11 +111,11 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的API适配。

7

API功能验证

+

算子功能验证

在真实的硬件环境中验证API功能。

+

在真实的硬件环境中验证算子功能。

API功能验证

+

算子功能验证