From 340e692468fa49ec758adcc1d9c898b8af96bdf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=BD=AC?= Date: Sat, 26 Mar 2022 10:44:43 +0800 Subject: [PATCH 01/18] =?UTF-8?q?=E3=80=90=E6=A8=A1=E5=9E=8Bpytorch?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E8=BF=81=E7=A7=BB=E3=80=91=20=20=20=20=20=20?= =?UTF-8?q?=20=20=201.5.0->1.8.1=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FaceNet_for_PyTorch/models/dropout.py | 6 ++- .../utils/dropout.py | 6 ++- .../built-in/nlp/GRU_for_PyTorch/decoder.py | 5 ++- .../built-in/nlp/GRU_for_PyTorch/encoder.py | 5 ++- .../NPU/1p/models/model_ctc.py | 10 ++++- .../NPU/8p/models/model_ctc.py | 10 ++++- .../models/transformer.py | 45 +++++++++++++++---- .../modules/multihead_attention.py | 5 ++- 8 files changed, 72 insertions(+), 20 deletions(-) diff --git a/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/models/dropout.py b/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/models/dropout.py index db8d481c59..53d79f470e 100644 --- a/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/models/dropout.py +++ b/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/models/dropout.py @@ -62,6 +62,8 @@ class DroupoutV2(nn.Module): if not self.checked: self.check_self(x) - - x, mask, _ = torch.npu_dropoutV2(x, self.seed, p=self.p) + if torch.__version__ >= "1.8.1": + x = nn.functional.dropout(x, p=self.p) + else: + x, mask, _ = torch.npu_dropoutV2(x, self.seed, p=self.p) return x diff --git a/PyTorch/built-in/cv/semantic_segmentation/DeepLabv3+_ID1695_for_PyTorch/utils/dropout.py b/PyTorch/built-in/cv/semantic_segmentation/DeepLabv3+_ID1695_for_PyTorch/utils/dropout.py index 8ad82cf02d..a681b4e1ea 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/DeepLabv3+_ID1695_for_PyTorch/utils/dropout.py +++ b/PyTorch/built-in/cv/semantic_segmentation/DeepLabv3+_ID1695_for_PyTorch/utils/dropout.py @@ -69,8 +69,10 @@ class DropoutV2(nn.Module): if not self.checked: self.check_self(x) - - x, mask, _ = torch.npu_dropoutV2(x, self.seed, p=self.p) + if torch.__version__ >= "1.8.1": + x = nn.functional.dropout(x, p=self.p) + else: + x, mask, _ = torch.npu_dropoutV2(x, self.seed, p=self.p) return x diff --git a/PyTorch/built-in/nlp/GRU_for_PyTorch/decoder.py b/PyTorch/built-in/nlp/GRU_for_PyTorch/decoder.py index eb558dc9fc..d2eb2ba41c 100644 --- a/PyTorch/built-in/nlp/GRU_for_PyTorch/decoder.py +++ b/PyTorch/built-in/nlp/GRU_for_PyTorch/decoder.py @@ -20,7 +20,10 @@ class Decoder(nn.Module): input = input.unsqueeze(0) embedded = self.embedding(input) if self.training: - embedded, _, _ = torch.npu_dropoutV2(embedded, self.seed, p=self.prob) + if torch.__version__ >= "1.8.1": + embedded = nn.functional.dropout(embedded, p=self.prob) + else: + embedded, _, _ = torch.npu_dropoutV2(embedded, self.seed, p=self.prob) emb_con = torch.cat((embedded, context), dim=2) output, hidden = self.rnn(emb_con, hidden) diff --git a/PyTorch/built-in/nlp/GRU_for_PyTorch/encoder.py b/PyTorch/built-in/nlp/GRU_for_PyTorch/encoder.py index f9e4f40b8a..1d238ac7a3 100644 --- a/PyTorch/built-in/nlp/GRU_for_PyTorch/encoder.py +++ b/PyTorch/built-in/nlp/GRU_for_PyTorch/encoder.py @@ -18,7 +18,10 @@ class Encoder(nn.Module): embedded = self.embedding(src) if self.training: - embedded, _, _ = torch.npu_dropoutV2(embedded, self.seed, p=self.prob) + if torch.__version__ >= "1.8.1": + embedded = nn.functional.dropout(embedded, p=self.prob) + else: + embedded, _, _ = torch.npu_dropoutV2(embedded, self.seed, p=self.prob) outputs, hidden = self.rnn(embedded) # no cell state! diff --git a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/models/model_ctc.py b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/models/model_ctc.py index 1d3614e68c..ec3ab986e5 100644 --- a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/models/model_ctc.py +++ b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/models/model_ctc.py @@ -56,7 +56,10 @@ class BatchRNN(nn.Module): x = torch.cat((x_post, x_reverse), 2) if self.training: - x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.prob) + if torch.__version__ >= "1.8.1": + x = nn.functional.dropout(x, p=self.prob) + else: + x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.prob) return x @@ -93,7 +96,10 @@ class LayerCNN(nn.Module): if self.pooling is not None: x = self.pooling(x) if self.training: - x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.prob) + if torch.__version__ >= "1.8.1": + x = nn.functional.dropout(x, p=self.prob) + else: + x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.prob) return x diff --git a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/models/model_ctc.py b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/models/model_ctc.py index 0641c34183..15a2d72bc2 100644 --- a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/models/model_ctc.py +++ b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/models/model_ctc.py @@ -56,7 +56,10 @@ class BatchRNN(nn.Module): x = torch.cat((x_post, x_reverse), 2) if self.training: - x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.prob) + if torch.__version__ >= "1.8.1": + x = nn.functional.dropout(x, p=self.prob) + else: + x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.prob) return x @@ -94,7 +97,10 @@ class LayerCNN(nn.Module): if self.pooling is not None: x = self.pooling(x) if self.training: - x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.prob) + if torch.__version__ >= "1.8.1": + x = nn.functional.dropout(x, p=self.prob) + else: + x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.prob) return x diff --git a/PyTorch/built-in/nlp/Transformer_for_PyTorch/models/transformer.py b/PyTorch/built-in/nlp/Transformer_for_PyTorch/models/transformer.py index 3995699393..0d8b0fdba2 100644 --- a/PyTorch/built-in/nlp/Transformer_for_PyTorch/models/transformer.py +++ b/PyTorch/built-in/nlp/Transformer_for_PyTorch/models/transformer.py @@ -185,7 +185,10 @@ class TransformerEncoder(nn.Module): if self.embed_positions is not None: x += self.embed_positions(src_tokens) if self.training: - x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.dropout) + if torch.__version__ >= "1.8.1": + x = nn.functional.dropout(x, p=self.dropout) + else: + x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.dropout) # B:batch size ; T: seq length ; C: embedding dim 512 # B x T x C -> T x B x C @@ -267,7 +270,10 @@ class TransformerDecoder(IncrementalDecoder): if positions is not None: x += positions if self.training: - x,_,_ = torch.npu_dropoutV2(x, self.seed, p=self.dropout) + if torch.__version__ >= "1.8.1": + x = nn.functional.dropout(x, p=self.dropout) + else: + x,_,_ = torch.npu_dropoutV2(x, self.seed, p=self.dropout) # B x T x C -> T x B x C x = x.transpose(0, 1) @@ -320,17 +326,26 @@ class TransformerEncoderLayer(nn.Module): need_weights=False, static_kv=False) if self.training: - x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.dropout) + if torch.__version__ >= "1.8.1": + x = nn.functional.dropout(x, p=self.dropout) + else: + x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.dropout) x = residual + x x = self.ln1(x) residual = x x = F.threshold(self.fc1(x), 0.0, 0.0) if self.training: - x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.relu_dropout) + if torch.__version__ >= "1.8.1": + x = nn.functional.dropout(x, p=self.relu_dropout) + else: + x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.relu_dropout) x = self.fc2(x) if self.training: - x, _, _ = torch.npu_dropoutV2(x, self.seed, p =self.dropout) + if torch.__version__ >= "1.8.1": + x = nn.functional.dropout(x, p=self.dropout) + else: + x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.dropout) x = residual + x x = self.ln2(x) return x @@ -384,7 +399,10 @@ class TransformerDecoderLayer(nn.Module): ) if self.training: - x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.dropout) + if torch.__version__ >= "1.8.1": + x = nn.functional.dropout(x, p=self.dropout) + else: + x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.dropout) x = residual + x x = self.self_attn_layer_norm(x) @@ -403,7 +421,10 @@ class TransformerDecoderLayer(nn.Module): need_weights=(not self.training and self.need_attn), ) if self.training: - x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.dropout) + if torch.__version__ >= "1.8.1": + x = nn.functional.dropout(x, p=self.dropout) + else: + x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.dropout) x = residual + x x = self.encoder_attn_layer_norm(x) @@ -411,10 +432,16 @@ class TransformerDecoderLayer(nn.Module): residual = x x = F.threshold(self.fc1(x), 0.0, 0.0) if self.training: - x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.relu_dropout) + if torch.__version__ >= "1.8.1": + x = nn.functional.dropout(x, p=self.relu_dropout) + else: + x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.relu_dropout) x = self.fc2(x) if self.training: - x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.dropout) + if torch.__version__ >= "1.8.1": + x = nn.functional.dropout(x, p=self.dropout) + else: + x, _, _ = torch.npu_dropoutV2(x, self.seed, p=self.dropout) x = residual + x x = self.layer_norm(x) return x, attn diff --git a/PyTorch/built-in/nlp/Transformer_for_PyTorch/modules/multihead_attention.py b/PyTorch/built-in/nlp/Transformer_for_PyTorch/modules/multihead_attention.py index ba5e353d0e..69e3cd2205 100644 --- a/PyTorch/built-in/nlp/Transformer_for_PyTorch/modules/multihead_attention.py +++ b/PyTorch/built-in/nlp/Transformer_for_PyTorch/modules/multihead_attention.py @@ -294,7 +294,10 @@ class MultiheadAttention(nn.Module): attn_weights = F.softmax(attn_weights, dim=-1) if self.training: - attn_weights, _, _ = torch.npu_dropoutV2(attn_weights, self.seed, p=self.dropout) + if torch.__version__ >= "1.8.1": + attn_weights = nn.functional.dropout(attn_weights, p=self.dropout) + else: + attn_weights, _, _ = torch.npu_dropoutV2(attn_weights, self.seed, p=self.dropout) attn = strided_bmm2(attn_weights, v) assert list(attn.size()) == [bsz * self.num_heads, tgt_len, self.head_dim] -- Gitee From a1daa9c5a1f7d0bbd0200f1975bbb2a71a5d5605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=BD=AC?= Date: Sat, 26 Mar 2022 17:44:41 +0800 Subject: [PATCH 02/18] =?UTF-8?q?=E3=80=90transformer=E6=A8=A1=E5=9E=8Bpyt?= =?UTF-8?q?orch=E7=89=88=E6=9C=AC=E8=BF=81=E7=A7=BB=E3=80=91=20=20=20=20?= =?UTF-8?q?=20=20=20=20=201.5.0->1.8.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../optim/cpex/amp/_process_optimizer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PyTorch/built-in/nlp/Transformer_for_PyTorch/optim/cpex/amp/_process_optimizer.py b/PyTorch/built-in/nlp/Transformer_for_PyTorch/optim/cpex/amp/_process_optimizer.py index 30b8685b00..40701cd160 100644 --- a/PyTorch/built-in/nlp/Transformer_for_PyTorch/optim/cpex/amp/_process_optimizer.py +++ b/PyTorch/built-in/nlp/Transformer_for_PyTorch/optim/cpex/amp/_process_optimizer.py @@ -225,8 +225,8 @@ def combined_init_with_master_weights(stash): stash.combined_tensor_fp16, stash.fp16_param_grad_list = get_grad_combined_tensor_from_param(stash.all_fp16_params) for model_grad, master in zip(stash.fp16_param_grad_list, stash.all_fp32_from_fp16_params): master.grad = torch.empty_like(model_grad.to(torch.float)) - master.data = master.data.npu_format_cast(model_grad.storage().npu_format()) - + master.data = master.data.npu_format_cast(torch.get_npu_format(model_grad)) + stash.combined_tensor_fp32_from_fp16, stash.fp32_from_fp16_param_grad_list = get_grad_combined_tensor_from_param(stash.all_fp32_from_fp16_params) stash.combined_tensor_fp32, stash.fp32_param_grad_list = get_grad_combined_tensor_from_param(stash.all_fp32_from_fp32_params) # please do not change the order of tensor in this list. -- Gitee From f3c3a91b78e13e0cd6753eb4a66e690692947010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=BD=AC?= Date: Sun, 27 Mar 2022 18:26:17 +0800 Subject: [PATCH 03/18] =?UTF-8?q?=E3=80=90=E6=A8=A1=E5=9E=8Bpytorch?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E8=BF=81=E7=A7=BB=E3=80=91=20=20=20=20=20=20?= =?UTF-8?q?=20=20=201.5.0->1.8.1=20=20=20=20=20=20=20=20=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A01.8.1=E7=89=88=E6=9C=ACimport=20torch=5Fnpu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cv/classification/FaceNet_for_PyTorch/models/dropout.py | 2 ++ .../DeepLabv3+_ID1695_for_PyTorch/utils/dropout.py | 2 ++ PyTorch/built-in/nlp/GRU_for_PyTorch/decoder.py | 2 ++ PyTorch/built-in/nlp/GRU_for_PyTorch/encoder.py | 2 ++ .../nlp/LSTM_ID0468_for_PyTorch/NPU/1p/models/model_ctc.py | 2 ++ .../nlp/LSTM_ID0468_for_PyTorch/NPU/8p/models/model_ctc.py | 2 ++ .../built-in/nlp/Transformer_for_PyTorch/models/transformer.py | 2 ++ .../nlp/Transformer_for_PyTorch/modules/multihead_attention.py | 2 ++ .../optim/cpex/amp/_process_optimizer.py | 2 ++ 9 files changed, 18 insertions(+) diff --git a/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/models/dropout.py b/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/models/dropout.py index 53d79f470e..6c2dfafd8b 100644 --- a/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/models/dropout.py +++ b/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/models/dropout.py @@ -36,6 +36,8 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import torch +if torch.__version__ >= "1.8.1": + import torch_npu import torch.nn as nn import numpy as np diff --git a/PyTorch/built-in/cv/semantic_segmentation/DeepLabv3+_ID1695_for_PyTorch/utils/dropout.py b/PyTorch/built-in/cv/semantic_segmentation/DeepLabv3+_ID1695_for_PyTorch/utils/dropout.py index a681b4e1ea..7bb18b1902 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/DeepLabv3+_ID1695_for_PyTorch/utils/dropout.py +++ b/PyTorch/built-in/cv/semantic_segmentation/DeepLabv3+_ID1695_for_PyTorch/utils/dropout.py @@ -13,6 +13,8 @@ # limitations under the License. import torch +if torch.__version__ >= "1.8.1": + import torch_npu import torch.nn as nn import numpy as np diff --git a/PyTorch/built-in/nlp/GRU_for_PyTorch/decoder.py b/PyTorch/built-in/nlp/GRU_for_PyTorch/decoder.py index d2eb2ba41c..cbbbae4cb0 100644 --- a/PyTorch/built-in/nlp/GRU_for_PyTorch/decoder.py +++ b/PyTorch/built-in/nlp/GRU_for_PyTorch/decoder.py @@ -1,4 +1,6 @@ import torch +if torch.__version__ >= "1.8.1": + import torch_npu import torch.nn as nn diff --git a/PyTorch/built-in/nlp/GRU_for_PyTorch/encoder.py b/PyTorch/built-in/nlp/GRU_for_PyTorch/encoder.py index 1d238ac7a3..b25b078dd0 100644 --- a/PyTorch/built-in/nlp/GRU_for_PyTorch/encoder.py +++ b/PyTorch/built-in/nlp/GRU_for_PyTorch/encoder.py @@ -1,4 +1,6 @@ import torch +if torch.__version__ >= "1.8.1": + import torch_npu import torch.nn as nn diff --git a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/models/model_ctc.py b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/models/model_ctc.py index ec3ab986e5..9db696766a 100644 --- a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/models/model_ctc.py +++ b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/models/model_ctc.py @@ -17,6 +17,8 @@ import math import torch +if torch.__version__ >= "1.8.1": + import torch_npu import torch.nn as nn import editdistance as ed from collections import OrderedDict diff --git a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/models/model_ctc.py b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/models/model_ctc.py index 15a2d72bc2..2f650e997c 100644 --- a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/models/model_ctc.py +++ b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/models/model_ctc.py @@ -17,6 +17,8 @@ import math import torch +if torch.__version__ >= "1.8.1": + import torch_npu import torch.nn as nn import editdistance as ed from collections import OrderedDict diff --git a/PyTorch/built-in/nlp/Transformer_for_PyTorch/models/transformer.py b/PyTorch/built-in/nlp/Transformer_for_PyTorch/models/transformer.py index 0d8b0fdba2..0872a5f439 100644 --- a/PyTorch/built-in/nlp/Transformer_for_PyTorch/models/transformer.py +++ b/PyTorch/built-in/nlp/Transformer_for_PyTorch/models/transformer.py @@ -24,6 +24,8 @@ import math import torch import torch.nn as nn +if torch.__version__ >= "1.8.1": + import torch_npu import torch.nn.functional as F from torch import Tensor from typing import Optional, Dict diff --git a/PyTorch/built-in/nlp/Transformer_for_PyTorch/modules/multihead_attention.py b/PyTorch/built-in/nlp/Transformer_for_PyTorch/modules/multihead_attention.py index 69e3cd2205..d640b25a44 100644 --- a/PyTorch/built-in/nlp/Transformer_for_PyTorch/modules/multihead_attention.py +++ b/PyTorch/built-in/nlp/Transformer_for_PyTorch/modules/multihead_attention.py @@ -24,6 +24,8 @@ from typing import Dict, Optional import torch +if torch.__version__ >= "1.8.1": + import torch_npu from torch import nn, Tensor from torch.nn import Parameter import torch.nn.functional as F diff --git a/PyTorch/built-in/nlp/Transformer_for_PyTorch/optim/cpex/amp/_process_optimizer.py b/PyTorch/built-in/nlp/Transformer_for_PyTorch/optim/cpex/amp/_process_optimizer.py index 40701cd160..0748b7bdb3 100644 --- a/PyTorch/built-in/nlp/Transformer_for_PyTorch/optim/cpex/amp/_process_optimizer.py +++ b/PyTorch/built-in/nlp/Transformer_for_PyTorch/optim/cpex/amp/_process_optimizer.py @@ -19,6 +19,8 @@ from apex.fp16_utils import master_params_to_model_params from apex.multi_tensor_apply import multi_tensor_applier from ._amp_state import maybe_print import torch +if torch.__version__ >= "1.8.1": + import torch_npu from apex.optimizers import FusedSGD, NpuFusedAdam, NpuFusedSGD, NpuFusedAdadelta from change_data_ptr import change_data_ptr from apex.contrib.combine_tensors import combine_npu -- Gitee From 32454ed14a1a2cec424d082f11067c4ef179d9b5 Mon Sep 17 00:00:00 2001 From: junqiang521 Date: Fri, 1 Apr 2022 11:03:08 +0800 Subject: [PATCH 04/18] bert-squad pytorch1.8 adaption --- .../nlp/Bert-Squad_ID0470_for_PyTorch/run_squad.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/PyTorch/built-in/nlp/Bert-Squad_ID0470_for_PyTorch/run_squad.py b/PyTorch/built-in/nlp/Bert-Squad_ID0470_for_PyTorch/run_squad.py index a5203e848d..4f5204fe17 100644 --- a/PyTorch/built-in/nlp/Bert-Squad_ID0470_for_PyTorch/run_squad.py +++ b/PyTorch/built-in/nlp/Bert-Squad_ID0470_for_PyTorch/run_squad.py @@ -29,6 +29,8 @@ from io import open import numpy as np import torch +if torch.__version__ >= "1.8.1": + import torch_npu from torch.utils.data import (DataLoader, RandomSampler, SequentialSampler, TensorDataset) from torch.utils.data.distributed import DistributedSampler @@ -80,11 +82,12 @@ class NpuFusedBertAdamV2(NpuFusedBertAdam): group['warmup']) else: lr_scheduled = group['lr'] - combined_param.data, exp_avg, exp_avg_sq = torch.npu_bert_apply_adam(combined_param.data, exp_avg, - exp_avg_sq, lr_scheduled, beta1, beta2, + combined_param.data, exp_avg, exp_avg_sq = torch.npu_bert_apply_adam(lr_scheduled, beta1, beta2, group['e'], combined_grad.data, group['max_grad_norm'], 0, - group['weight_decay']) + group['weight_decay'], + out=(combined_param.data, exp_avg, + exp_avg_sq)) combined_param_state['step'] += 1 -- Gitee From fc354312290c3bb5f1ece2c7ca5efad3e8a62bdb Mon Sep 17 00:00:00 2001 From: junqiang521 Date: Fri, 1 Apr 2022 11:35:49 +0800 Subject: [PATCH 05/18] Densnet121 pytorch1.8 adaption --- .../Densenet121_for_PyTorch/densenet121_1p_main.py | 2 ++ .../Densenet121_for_PyTorch/densenet121_8p_main.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_1p_main.py b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_1p_main.py index 79abe7f165..9e5619e7da 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_1p_main.py +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_1p_main.py @@ -24,6 +24,8 @@ import time import warnings import torch +if torch.__version__ >= "1.8.1": + import torch_npu import apex import torch.nn as nn import torch.nn.parallel diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_8p_main.py b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_8p_main.py index c87fda1332..efbe6b48a0 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_8p_main.py +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_8p_main.py @@ -24,6 +24,8 @@ import warnings import apex import torch +if torch.__version__ >= "1.8.1": + import torch_npu import torch.nn as nn import torch.nn.parallel import torch.backends.cudnn as cudnn -- Gitee From 0edddfbce9a08e83a3ee40be220f5cac22e0e7aa Mon Sep 17 00:00:00 2001 From: junqiang521 Date: Fri, 1 Apr 2022 12:14:15 +0800 Subject: [PATCH 06/18] Densnet161 pytorch1.8 adaption --- .../references/classification/train.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PyTorch/built-in/cv/classification/DenseNet161_ID0455_for_PyTorch/references/classification/train.py b/PyTorch/built-in/cv/classification/DenseNet161_ID0455_for_PyTorch/references/classification/train.py index 11c3a04504..5c050033fa 100644 --- a/PyTorch/built-in/cv/classification/DenseNet161_ID0455_for_PyTorch/references/classification/train.py +++ b/PyTorch/built-in/cv/classification/DenseNet161_ID0455_for_PyTorch/references/classification/train.py @@ -37,6 +37,8 @@ import time import sys import torch +if torch.__version__ >= "1.8.1": + import torch_npu import torch.utils.data from torch import nn import torchvision -- Gitee From 13593478c7b9f5d4fd1550c2e023f9494aa3eacc Mon Sep 17 00:00:00 2001 From: junqiang521 Date: Fri, 1 Apr 2022 20:18:47 +0800 Subject: [PATCH 07/18] Densenet169 pytorch1.8 adaption --- .../references/classification/train.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PyTorch/built-in/cv/classification/DenseNet169_ID0454_for_PyTorch/references/classification/train.py b/PyTorch/built-in/cv/classification/DenseNet169_ID0454_for_PyTorch/references/classification/train.py index 11ef66c342..7d58914bd6 100644 --- a/PyTorch/built-in/cv/classification/DenseNet169_ID0454_for_PyTorch/references/classification/train.py +++ b/PyTorch/built-in/cv/classification/DenseNet169_ID0454_for_PyTorch/references/classification/train.py @@ -37,6 +37,8 @@ import time import sys import torch +if torch.__version__ >= "1.8.1": + import torch_npu import torch.utils.data from torch import nn import torchvision -- Gitee From 6b19631040adc26c68cd9c7cd9efbca35bab3115 Mon Sep 17 00:00:00 2001 From: junqiang521 Date: Sat, 2 Apr 2022 10:33:51 +0800 Subject: [PATCH 08/18] yolov3 pytorch1.8 adaption --- .../cv/detection/YoloV3_ID1790_for_PyTorch/tools/train.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PyTorch/built-in/cv/detection/YoloV3_ID1790_for_PyTorch/tools/train.py b/PyTorch/built-in/cv/detection/YoloV3_ID1790_for_PyTorch/tools/train.py index 2fcc80ed27..a4d26fd13e 100644 --- a/PyTorch/built-in/cv/detection/YoloV3_ID1790_for_PyTorch/tools/train.py +++ b/PyTorch/built-in/cv/detection/YoloV3_ID1790_for_PyTorch/tools/train.py @@ -21,6 +21,8 @@ import warnings import mmcv import torch +if torch.__version__ >= "1.8.1": + import torch_npu from mmcv import Config, DictAction from mmcv.runner import get_dist_info, init_dist from mmcv.utils import get_git_hash -- Gitee From 36fb3be7b9ac66a582b8c25b98f69cd294f14502 Mon Sep 17 00:00:00 2001 From: junqiang521 Date: Sat, 2 Apr 2022 11:32:28 +0800 Subject: [PATCH 09/18] yolov4 pytorch1.8 adaption --- .../built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/train.py | 2 ++ .../built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/train_8p.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/train.py b/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/train.py index ed0add743b..ffcaef1e01 100644 --- a/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/train.py +++ b/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/train.py @@ -27,6 +27,8 @@ import torch.nn.functional as F import torch.optim as optim import torch.optim.lr_scheduler as lr_scheduler import torch.utils.data +if torch.__version__ >= "1.8.1": + import torch_npu import yaml import apex from torch.nn.parallel import DistributedDataParallel as DDP diff --git a/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/train_8p.py b/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/train_8p.py index 5e9afdb746..892cc74f67 100644 --- a/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/train_8p.py +++ b/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/train_8p.py @@ -27,6 +27,8 @@ import torch.nn.functional as F import torch.optim as optim import torch.optim.lr_scheduler as lr_scheduler import torch.utils.data +if torch.__version__ >= "1.8.1": + import torch_npu import yaml import apex -- Gitee From 5fe1211ebc4d57871962756d48f0274a2dcceedf Mon Sep 17 00:00:00 2001 From: junqiang521 Date: Sat, 2 Apr 2022 12:14:39 +0800 Subject: [PATCH 10/18] DB pytorch1.8 adaption --- PyTorch/built-in/cv/detection/DB_ID0706_for_PyTorch/train.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PyTorch/built-in/cv/detection/DB_ID0706_for_PyTorch/train.py b/PyTorch/built-in/cv/detection/DB_ID0706_for_PyTorch/train.py index 7f551516c3..81e07773cb 100644 --- a/PyTorch/built-in/cv/detection/DB_ID0706_for_PyTorch/train.py +++ b/PyTorch/built-in/cv/detection/DB_ID0706_for_PyTorch/train.py @@ -20,6 +20,8 @@ import argparse import time import os import torch +if torch.__version__ >= "1.8.1": + import torch_npu import yaml import torch.distributed as dist -- Gitee From db57193057b2b9de46e6af04a852cdb972ff7848 Mon Sep 17 00:00:00 2001 From: junqiang521 Date: Sat, 2 Apr 2022 17:05:32 +0800 Subject: [PATCH 11/18] crnn pytorch1.8 adaption --- PyTorch/built-in/cv/classification/CRNN_for_PyTorch/main.py | 2 ++ PyTorch/built-in/cv/classification/CRNN_for_PyTorch/main_8p.py | 2 ++ .../built-in/cv/classification/CRNN_for_PyTorch/main_anycard.py | 2 ++ 3 files changed, 6 insertions(+) diff --git a/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/main.py b/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/main.py index 66d8b9b4db..3ef0a377ad 100644 --- a/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/main.py +++ b/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/main.py @@ -21,6 +21,8 @@ import time import crnn import utils import torch +if torch.__version__ >= "1.8.1": + import torch_npu import torch.nn.parallel from torch.utils.data import DataLoader from apex import amp diff --git a/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/main_8p.py b/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/main_8p.py index cc46a75bb8..c1cdcb0282 100644 --- a/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/main_8p.py +++ b/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/main_8p.py @@ -21,6 +21,8 @@ import time import crnn import utils import torch +if torch.__version__ >= "1.8.1": + import torch_npu import torch.nn.parallel from torch.utils.data import DataLoader from apex import amp diff --git a/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/main_anycard.py b/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/main_anycard.py index 28d3c6e776..aaca74eeb6 100644 --- a/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/main_anycard.py +++ b/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/main_anycard.py @@ -21,6 +21,8 @@ import time import crnn import utils import torch +if torch.__version__ >= "1.8.1": + import torch_npu import torch.nn.parallel from torch.utils.data import DataLoader from apex import amp -- Gitee From 3a8a4055e3429b33eef55871b0bb759106b5eb8a Mon Sep 17 00:00:00 2001 From: junqiang521 Date: Sun, 3 Apr 2022 10:29:28 +0800 Subject: [PATCH 12/18] lstm pytorch 1.8 adaption --- .../nlp/LSTM_ID0468_for_PyTorch/NPU/1p/steps/test_ctc.py | 2 ++ .../nlp/LSTM_ID0468_for_PyTorch/NPU/1p/steps/train_ctc.py | 2 ++ .../nlp/LSTM_ID0468_for_PyTorch/NPU/8p/steps/test_ctc.py | 2 ++ .../nlp/LSTM_ID0468_for_PyTorch/NPU/8p/steps/train_ctc.py | 2 ++ 4 files changed, 8 insertions(+) diff --git a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/steps/test_ctc.py b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/steps/test_ctc.py index 9a8c28cd76..40845c3a43 100644 --- a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/steps/test_ctc.py +++ b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/steps/test_ctc.py @@ -19,6 +19,8 @@ import os import time import sys import torch +if torch.__version__ >= "1.8.1": + import torch_npu import yaml import argparse import torch.nn as nn diff --git a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/steps/train_ctc.py b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/steps/train_ctc.py index f3471226dc..1aab27976e 100644 --- a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/steps/train_ctc.py +++ b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/1p/steps/train_ctc.py @@ -26,6 +26,8 @@ import argparse import numpy as np import random import torch +if torch.__version__ >= "1.8.1": + import torch_npu import torch.nn as nn import torch.backends.cudnn as cudnn import apex diff --git a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/steps/test_ctc.py b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/steps/test_ctc.py index 070d7055a2..9d483253ae 100644 --- a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/steps/test_ctc.py +++ b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/steps/test_ctc.py @@ -19,6 +19,8 @@ import os import time import sys import torch +if torch.__version__ >= "1.8.1": + import torch_npu import yaml import argparse import torch.nn as nn diff --git a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/steps/train_ctc.py b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/steps/train_ctc.py index 6662ed15e2..4c0d6ace0a 100644 --- a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/steps/train_ctc.py +++ b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/NPU/8p/steps/train_ctc.py @@ -25,6 +25,8 @@ import yaml import argparse import random import torch +if torch.__version__ >= "1.8.1": + import torch_npu import torch.nn as nn import torch.backends.cudnn as cudnn from torch.utils.tensorboard import SummaryWriter -- Gitee From 909d8cab66fd4396a25b121040a444cac1afdd64 Mon Sep 17 00:00:00 2001 From: junqiang521 Date: Wed, 6 Apr 2022 15:18:03 +0800 Subject: [PATCH 13/18] Facenet pytorch1.8 adaption --- .../cv/classification/FaceNet_for_PyTorch/fine_tune_new.py | 2 ++ .../cv/classification/FaceNet_for_PyTorch/fine_tune_new_8p.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/fine_tune_new.py b/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/fine_tune_new.py index cf24ca704c..8834d9d0f7 100644 --- a/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/fine_tune_new.py +++ b/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/fine_tune_new.py @@ -30,6 +30,8 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import torch +if torch.__version__ >= "1.8.1": + import torch_npu import sys import os import random diff --git a/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/fine_tune_new_8p.py b/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/fine_tune_new_8p.py index 912ee61d19..6800b256e2 100644 --- a/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/fine_tune_new_8p.py +++ b/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch/fine_tune_new_8p.py @@ -30,6 +30,8 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import torch +if torch.__version__ >= "1.8.1": + import torch_npu import sys import os import random -- Gitee From a578d54b782ae6e1240e83d01065947017c35754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=BD=AC?= Date: Wed, 6 Apr 2022 14:14:53 +0000 Subject: [PATCH 14/18] update PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/requirements.txt. --- .../cv/detection/YOLOV4_ID0396_for_PyTorch/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/requirements.txt b/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/requirements.txt index 0214cf1dd5..fd08db8dd9 100644 --- a/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/requirements.txt +++ b/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/requirements.txt @@ -4,4 +4,4 @@ matplotlib pycocotools == 2.0.2 tqdm pillow -tensorboard == 1.14 +tensorboard == 1.15 -- Gitee From d8f5439d64382b206197816254e7705e401e3833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=BD=AC?= Date: Wed, 6 Apr 2022 14:15:27 +0000 Subject: [PATCH 15/18] update PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/requirements.txt. --- .../cv/detection/Faster_Mask_RCNN_for_PyTorch/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/requirements.txt b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/requirements.txt index 1d547c4650..9f077f9a83 100644 --- a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/requirements.txt +++ b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/requirements.txt @@ -4,4 +4,4 @@ torchvision==0.2.2.post2 fvcore pycocotools cloudpickle -tensorboard \ No newline at end of file +tensorboard == 1.15 \ No newline at end of file -- Gitee From ea7ecb0653a886faa9b9bacfe56d8bbe451bf301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=BD=AC?= Date: Wed, 6 Apr 2022 14:16:42 +0000 Subject: [PATCH 16/18] update PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/requirements.txt. --- PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/requirements.txt b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/requirements.txt index cdbbb913ef..5aa5ab416e 100644 --- a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/requirements.txt +++ b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/requirements.txt @@ -1,4 +1,4 @@ torchvision kaldiio==2.17.2 editdistance==0.5.3 -tensorboard==1.14.0 \ No newline at end of file +tensorboard==1.15.0 \ No newline at end of file -- Gitee From 0e1247880a0ea36e8d1f04245045df9a46976a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=BD=AC?= Date: Wed, 6 Apr 2022 14:17:22 +0000 Subject: [PATCH 17/18] update PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/requirements.txt. --- .../cv/detection/YOLOV4_ID0396_for_PyTorch/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/requirements.txt b/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/requirements.txt index fd08db8dd9..79eb67fc7b 100644 --- a/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/requirements.txt +++ b/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch/requirements.txt @@ -4,4 +4,4 @@ matplotlib pycocotools == 2.0.2 tqdm pillow -tensorboard == 1.15 +tensorboard == 1.15.0 -- Gitee From 52a3540507de554609cd5b3812e2d2e21af642e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=BD=AC?= Date: Wed, 6 Apr 2022 14:18:58 +0000 Subject: [PATCH 18/18] update PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/requirements.txt. --- .../cv/detection/Faster_Mask_RCNN_for_PyTorch/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/requirements.txt b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/requirements.txt index 9f077f9a83..d7a8589be6 100644 --- a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/requirements.txt +++ b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/requirements.txt @@ -4,4 +4,4 @@ torchvision==0.2.2.post2 fvcore pycocotools cloudpickle -tensorboard == 1.15 \ No newline at end of file +tensorboard == 1.15.0 \ No newline at end of file -- Gitee