diff --git a/mindspore/_extends/parse/resources.py b/mindspore/_extends/parse/resources.py index db396ec57c4..d8feca0f9a2 100644 --- a/mindspore/_extends/parse/resources.py +++ b/mindspore/_extends/parse/resources.py @@ -21,6 +21,7 @@ import math from mindspore import RowTensor, SparseTensor from mindspore.ops import functional as F, composite as C from mindspore.ops.composite import multitype_ops +from mindspore._c_expression import security from . import standard_method as M from . import trope as T from .namespace import CellNamespace @@ -112,7 +113,6 @@ convert_object_map = { T.map: C.Map(), T.partial: F.partial, T.zip: C.zip_operation, - T.print: F.print_, T.enumerate: M.enumerate_, T.isinstance: M.isinstance_, @@ -140,3 +140,6 @@ convert_object_map = { RowTensor: F.make_row_tensor, SparseTensor: F.make_sparse_tensor, } + +if not security.enable_security(): + convert_object_map[T.print] = F.print_ diff --git a/mindspore/ops/functional.py b/mindspore/ops/functional.py index 22173821784..8f611e4d29c 100644 --- a/mindspore/ops/functional.py +++ b/mindspore/ops/functional.py @@ -23,6 +23,7 @@ from .primitive import Primitive from . import operations as P from .operations import _grad_ops from .composite import GradOperation +from .._c_expression import security typeof = Primitive('typeof') hastype = Primitive('hastype') @@ -125,7 +126,8 @@ scalar_to_array = P.ScalarToArray() scalar_to_tensor = P.ScalarToTensor() tuple_to_array = P.TupleToArray() scalar_cast = P.ScalarCast() -print_ = P.Print() +if not security.enable_security(): + print_ = P.Print() expand_dims = P.ExpandDims() transpose = P.Transpose() squeeze = P.Squeeze() diff --git a/mindspore/ops/operations/debug_ops.py b/mindspore/ops/operations/debug_ops.py index 39a192db480..34c5a2d18e8 100644 --- a/mindspore/ops/operations/debug_ops.py +++ b/mindspore/ops/operations/debug_ops.py @@ -17,12 +17,12 @@ from types import FunctionType, MethodType from mindspore import context +from mindspore._c_expression import security from ..._checkparam import Validator as validator from ..._checkparam import Rel from ...common import dtype as mstype from ..primitive import prim_attr_register, Primitive, PrimitiveWithInfer - def _check_mode(class_name): """Check for PyNative mode.""" mode = context.get_context('mode') @@ -407,6 +407,9 @@ class Print(PrimitiveWithInfer): @prim_attr_register def __init__(self): """Initialize Print.""" + if security.enable_security(): + raise ValueError( + 'The Print is not supported, please without `-s on` and recompile source.') self.add_prim_attr("side_effect_io", True) def __call__(self, *args): diff --git a/model_zoo/official/cv/centerface/src/centerface.py b/model_zoo/official/cv/centerface/src/centerface.py index aae19169a39..c97ea22302a 100644 --- a/model_zoo/official/cv/centerface/src/centerface.py +++ b/model_zoo/official/cv/centerface/src/centerface.py @@ -178,7 +178,6 @@ class CenterFaceLoss(nn.Cell): self.cls_loss = FocalLoss() self.reg_loss = SmoothL1LossNew() self.reg_loss_cmask = SmoothL1LossNewCMask() - self.print = P.Print() def construct(self, output_hm, output_wh, output_off, output_kps, hm, reg_mask, ind, wh, wight_mask, hm_offset, hps_mask, landmarks): @@ -211,7 +210,6 @@ class CenterFaceWithLossCell(nn.Cell): self.loss = CenterFaceLoss(self.config.wh_weight, self.config.reg_offset, self.config.off_weight, self.config.hm_weight, self.config.lm_weight) self.reduce_sum = P.ReduceSum() - self.print = P.Print() def construct(self, x, hm, reg_mask, ind, wh, wight_mask, hm_offset, hps_mask, landmarks): output_hm, output_wh, output_off, output_kps = self.centerface_network(x) @@ -326,7 +324,6 @@ class CenterFaceWithNms(nn.Cell): self.maxpool2d = P.MaxPoolWithArgmax(kernel_size=3, strides=1, pad_mode='same') self.topk = P.TopK(sorted=True) self.reshape = P.Reshape() - self.print = P.Print() self.test_batch = self.config.test_batch_size self.k = self.config.K diff --git a/model_zoo/official/cv/centerface/src/losses.py b/model_zoo/official/cv/centerface/src/losses.py index 62e91ba9910..28aec74fb66 100644 --- a/model_zoo/official/cv/centerface/src/losses.py +++ b/model_zoo/official/cv/centerface/src/losses.py @@ -26,7 +26,6 @@ class FocalLoss(nn.Cell): self.log = P.Log() self.pow = P.Pow() self.sum = P.ReduceSum() - self.print = P.Print() def construct(self, pred, gt): """Construct method""" diff --git a/model_zoo/official/cv/centerface/src/mobile_v2.py b/model_zoo/official/cv/centerface/src/mobile_v2.py index 367225c727f..29e767ed9d2 100644 --- a/model_zoo/official/cv/centerface/src/mobile_v2.py +++ b/model_zoo/official/cv/centerface/src/mobile_v2.py @@ -59,7 +59,6 @@ class ConvBNReLU(nn.Cell): layers = [conv, nn.BatchNorm2d(out_planes).add_flags_recursive(fp32=True), nn.ReLU6()] #, momentum=0.9 self.features = nn.SequentialCell(layers) self.in_planes = in_planes - self.print = P.Print() def construct(self, x): x = self.features(x) diff --git a/model_zoo/official/cv/ctpn/src/CTPN/bbox_assign_sample.py b/model_zoo/official/cv/ctpn/src/CTPN/bbox_assign_sample.py index 7ca88d3bc1f..a21555f26d0 100644 --- a/model_zoo/official/cv/ctpn/src/CTPN/bbox_assign_sample.py +++ b/model_zoo/official/cv/ctpn/src/CTPN/bbox_assign_sample.py @@ -96,7 +96,6 @@ class BboxAssignSample(nn.Cell): self.range_pos_size = Tensor(np.arange(self.num_expected_pos).astype(np.float16)) self.check_gt_one = Tensor(np.array(-1 * np.ones((self.num_gts, 4)), dtype=np.float16)) self.check_anchor_two = Tensor(np.array(-2 * np.ones((self.num_bboxes, 4)), dtype=np.float16)) - self.print = P.Print() def construct(self, gt_bboxes_i, gt_labels_i, valid_mask, bboxes, gt_valids): diff --git a/model_zoo/official/cv/ctpn/src/CTPN/proposal_generator.py b/model_zoo/official/cv/ctpn/src/CTPN/proposal_generator.py index f61af38e52f..295291eac19 100644 --- a/model_zoo/official/cv/ctpn/src/CTPN/proposal_generator.py +++ b/model_zoo/official/cv/ctpn/src/CTPN/proposal_generator.py @@ -124,7 +124,6 @@ class Proposal(nn.Cell): self.min_float_num = -65536.0 self.topK_mask = Tensor(self.min_float_num * np.ones(total_max_topk_input, np.float16)) self.shape = P.Shape() - self.print = P.Print() def construct(self, rpn_cls_score_total, rpn_bbox_pred_total, anchor_list): proposals_tuple = () diff --git a/model_zoo/official/cv/ctpn/src/CTPN/rpn.py b/model_zoo/official/cv/ctpn/src/CTPN/rpn.py index 90d568a7c8e..65a0eeff07c 100644 --- a/model_zoo/official/cv/ctpn/src/CTPN/rpn.py +++ b/model_zoo/official/cv/ctpn/src/CTPN/rpn.py @@ -52,7 +52,6 @@ class RpnRegClsBlock(nn.Cell): self.shape1 = (-1, config.num_step, config.rnn_batch_size) self.shape2 = (config.batch_size, -1, config.rnn_batch_size, config.num_step) self.transpose = P.Transpose() - self.print = P.Print() def construct(self, x): x = self.reshape(x, self.shape) @@ -143,7 +142,6 @@ class RPN(nn.Cell): self.loss = Tensor(np.zeros((1,)).astype(np.float16)) self.clsloss = Tensor(np.zeros((1,)).astype(np.float16)) self.regloss = Tensor(np.zeros((1,)).astype(np.float16)) - self.print = P.Print() def _make_rpn_layer(self, num_layers, in_channels, feat_channels, num_anchors, cls_out_channels): """ diff --git a/model_zoo/official/cv/openpose/src/loss.py b/model_zoo/official/cv/openpose/src/loss.py index 312dba9a633..d975ab3c5a5 100644 --- a/model_zoo/official/cv/openpose/src/loss.py +++ b/model_zoo/official/cv/openpose/src/loss.py @@ -120,7 +120,6 @@ class openpose_loss(MyLoss): self.square = P.Square() self.reduceMean = P.ReduceMean() self.reduceSum = P.ReduceSum() - self.print = P.Print() self.shape = P.Shape() self.maxoftensor = P.ArgMaxWithValue(-1) diff --git a/model_zoo/official/cv/openpose/src/openposenet.py b/model_zoo/official/cv/openpose/src/openposenet.py index e30b98fef32..10a3c19d569 100644 --- a/model_zoo/official/cv/openpose/src/openposenet.py +++ b/model_zoo/official/cv/openpose/src/openposenet.py @@ -37,7 +37,6 @@ class OpenPoseNet(nn.Cell): self.stage_6 = Stage_x() self.shape = P.Shape() self.cat = P.Concat(axis=1) - self.print = P.Print() if loadvgg and vggpath: param_dict = load_checkpoint(vggpath) param_dict_new = {} diff --git a/model_zoo/official/cv/posenet/src/posenet.py b/model_zoo/official/cv/posenet/src/posenet.py index bed571b5dc9..d55fbb20c01 100644 --- a/model_zoo/official/cv/posenet/src/posenet.py +++ b/model_zoo/official/cv/posenet/src/posenet.py @@ -120,7 +120,6 @@ class PoseNet(nn.Cell): self.dropout5 = nn.Dropout(0.5) self.cls_fc_pose_xyz = nn.Dense(2048, 3) self.cls_fc_pose_wpqr = nn.Dense(2048, 4) - self.print = P.Print() def construct(self, x): """construct""" diff --git a/model_zoo/official/cv/vit/src/vit.py b/model_zoo/official/cv/vit/src/vit.py index 3273c069cc2..876cb7c52ec 100644 --- a/model_zoo/official/cv/vit/src/vit.py +++ b/model_zoo/official/cv/vit/src/vit.py @@ -82,7 +82,6 @@ class DropPath(Cell): self.rand = P.UniformReal(seed=seed) # seed must be 0, if set to other value, it's not rand for multiple call self.shape = P.Shape() self.floor = P.Floor() - self.print = P.Print() def construct(self, x): if self.training: diff --git a/model_zoo/official/nlp/fasttext/src/fasttext_train.py b/model_zoo/official/nlp/fasttext/src/fasttext_train.py index 0bfaeb792d1..9f4132b2dc7 100644 --- a/model_zoo/official/nlp/fasttext/src/fasttext_train.py +++ b/model_zoo/official/nlp/fasttext/src/fasttext_train.py @@ -69,7 +69,6 @@ class FastTextNetWithLoss(nn.Cell): self.fasttext = FastText(vocab_size, embedding_dims, num_class) self.loss_func = nn.SoftmaxCrossEntropyWithLogits(sparse=True, reduction='mean') self.squeeze = P.Squeeze(axis=1) - self.print = P.Print() def construct(self, src_tokens, src_tokens_lengths, label_idx): """ diff --git a/model_zoo/official/nlp/gru/src/seq2seq.py b/model_zoo/official/nlp/gru/src/seq2seq.py index 97c117d0101..0e0058281eb 100644 --- a/model_zoo/official/nlp/gru/src/seq2seq.py +++ b/model_zoo/official/nlp/gru/src/seq2seq.py @@ -84,7 +84,6 @@ class Encoder(nn.Cell): self.fc = nn.Dense(2*self.hidden_size, self.hidden_size).to_float(config.compute_type) self.shape = P.Shape() self.transpose = P.Transpose() - self.p = P.Print() self.cast = P.Cast() self.text_len = config.max_length self.squeeze = P.Squeeze(axis=0) @@ -131,7 +130,6 @@ class Decoder(nn.Cell): self.text_len = config.max_length self.shape = P.Shape() self.transpose = P.Transpose() - self.p = P.Print() self.cast = P.Cast() self.concat = P.Concat(axis=2) self.squeeze = P.Squeeze(axis=0) diff --git a/model_zoo/official/nlp/textcnn/src/textcnn.py b/model_zoo/official/nlp/textcnn/src/textcnn.py index b4e8d9dec38..3d627de355e 100644 --- a/model_zoo/official/nlp/textcnn/src/textcnn.py +++ b/model_zoo/official/nlp/textcnn/src/textcnn.py @@ -115,7 +115,6 @@ class TextCNN(nn.Cell): self.fc = nn.Dense(96*3, self.num_classes) self.drop = nn.Dropout(keep_prob=0.5) - self.print = P.Print() self.reducemax = P.ReduceMax(keep_dims=False) def make_layer(self, kernel_height): diff --git a/model_zoo/research/cv/DDM/net/deeplabv2_mindspore.py b/model_zoo/research/cv/DDM/net/deeplabv2_mindspore.py index 621d823cf1a..2faf7876805 100644 --- a/model_zoo/research/cv/DDM/net/deeplabv2_mindspore.py +++ b/model_zoo/research/cv/DDM/net/deeplabv2_mindspore.py @@ -124,7 +124,6 @@ class ResNetMulti(nn.Cell): self.layer5 = ClassifierModule(1024, [6, 12, 18, 24], [6, 12, 18, 24], num_classes) self.layer6 = ClassifierModule(2048, [6, 12, 18, 24], [6, 12, 18, 24], num_classes) - self.p = P.Print() self.shape = Shape() self.pad = nn.Pad(((0, 0), (0, 0), (1, 1), (1, 1)), "CONSTANT") diff --git a/model_zoo/research/cv/FaceAttribute/src/FaceAttribute/loss_factory.py b/model_zoo/research/cv/FaceAttribute/src/FaceAttribute/loss_factory.py index ca11e60f32d..a4246519329 100644 --- a/model_zoo/research/cv/FaceAttribute/src/FaceAttribute/loss_factory.py +++ b/model_zoo/research/cv/FaceAttribute/src/FaceAttribute/loss_factory.py @@ -42,7 +42,6 @@ class CriterionsFaceAttri(nn.Cell): # loss self.ce_ignore_loss = CrossEntropyWithIgnoreIndex() - self.printn = P.Print() def construct(self, x0, x1, x2, label): '''Construct function.''' diff --git a/model_zoo/research/cv/FaceAttribute/train.py b/model_zoo/research/cv/FaceAttribute/train.py index 672d86bdb65..42d37f8f03a 100644 --- a/model_zoo/research/cv/FaceAttribute/train.py +++ b/model_zoo/research/cv/FaceAttribute/train.py @@ -26,7 +26,6 @@ from mindspore.nn import TrainOneStepCell from mindspore.context import ParallelMode from mindspore.train.callback import ModelCheckpoint, RunContext, CheckpointConfig from mindspore.train.serialization import load_checkpoint, load_param_into_net -from mindspore.ops import operations as P from mindspore.common import dtype as mstype from src.FaceAttribute.resnet18 import get_resnet18 from src.FaceAttribute.loss_factory import get_loss @@ -55,7 +54,6 @@ class BuildTrainNetwork(nn.Cell): super(BuildTrainNetwork, self).__init__() self.network = my_network self.criterion = my_criterion - self.print = P.Print() def construct(self, input_data, label): logit0, logit1, logit2 = self.network(input_data) diff --git a/model_zoo/research/cv/FaceDetection/src/FaceDetection/yolo_postprocess.py b/model_zoo/research/cv/FaceDetection/src/FaceDetection/yolo_postprocess.py index ac8ab9ea365..6790ee3eade 100644 --- a/model_zoo/research/cv/FaceDetection/src/FaceDetection/yolo_postprocess.py +++ b/model_zoo/research/cv/FaceDetection/src/FaceDetection/yolo_postprocess.py @@ -42,7 +42,6 @@ class YoloPostProcess(Cell): """ def __init__(self, num_classes, cur_anchors, conf_thresh, network_size, reduction, anchors_mask): super(YoloPostProcess, self).__init__() - self.print = P.Print() self.num_classes = num_classes self.anchors = cur_anchors self.conf_thresh = conf_thresh diff --git a/model_zoo/research/cv/FaceDetection/src/network_define.py b/model_zoo/research/cv/FaceDetection/src/network_define.py index 0284586929a..c46449c5767 100644 --- a/model_zoo/research/cv/FaceDetection/src/network_define.py +++ b/model_zoo/research/cv/FaceDetection/src/network_define.py @@ -174,7 +174,6 @@ class BuildTestNetwork(nn.Cell): '''BuildTestNetwork''' def __init__(self, network, reduction_0, reduction_1, reduction_2, anchors, anchors_mask, num_classes, args): super(BuildTestNetwork, self).__init__() - self.print = P.Print() self.network = network self.reduction_0 = reduction_0 self.reduction_1 = reduction_1 diff --git a/model_zoo/research/cv/IPT/src/utils.py b/model_zoo/research/cv/IPT/src/utils.py index e2d77b0d887..431998b8160 100644 --- a/model_zoo/research/cv/IPT/src/utils.py +++ b/model_zoo/research/cv/IPT/src/utils.py @@ -37,7 +37,6 @@ class MyTrain(nn.Cell): self.model = model self.con_loss = con_loss self.criterion = criterion - self.p = P.Print() self.cast = P.Cast() def construct(self, lr, hr, idx): diff --git a/model_zoo/research/cv/ManiDP/src/resnet.py b/model_zoo/research/cv/ManiDP/src/resnet.py index baaa84f6117..02f13751db4 100755 --- a/model_zoo/research/cv/ManiDP/src/resnet.py +++ b/model_zoo/research/cv/ManiDP/src/resnet.py @@ -91,7 +91,6 @@ class MaskBlock(nn.Cell): self.relu = P.ReLU() self.thre = thres[num] - self.print = P.Print() def construct(self, x): """construct""" diff --git a/model_zoo/research/cv/inception_resnet_v2/src/inception_resnet_v2.py b/model_zoo/research/cv/inception_resnet_v2/src/inception_resnet_v2.py index caae2d9d9e5..d9098c8b480 100644 --- a/model_zoo/research/cv/inception_resnet_v2/src/inception_resnet_v2.py +++ b/model_zoo/research/cv/inception_resnet_v2/src/inception_resnet_v2.py @@ -245,7 +245,6 @@ class InceptionC(nn.Cell): self.concat = P.Concat(1) if not self.noReLU: self.relu = nn.ReLU() - self.print = P.Print() def construct(self, x): x0 = self.branch0(x) diff --git a/tests/st/auto_monad/test_auto_monad.py b/tests/st/auto_monad/test_auto_monad.py index 0b8c907bf71..755686bbd1b 100644 --- a/tests/st/auto_monad/test_auto_monad.py +++ b/tests/st/auto_monad/test_auto_monad.py @@ -28,6 +28,7 @@ from mindspore.common.parameter import Parameter from mindspore.common.initializer import initializer from mindspore.ops.primitive import constexpr from capture import Capture, capture, check_output +from tests.security_utils import security_off_wrap context.set_context(mode=context.GRAPH_MODE, device_target="Ascend") @@ -48,6 +49,7 @@ def _with_save_graphs(): clean_all_ir_files('./') +@security_off_wrap def test_print(): class Print(Cell): def __init__(self): @@ -71,6 +73,7 @@ def test_print(): check_output(cap.output, patterns) +@security_off_wrap def test_print_add(): class Print_Add(Cell): def __init__(self): @@ -98,6 +101,7 @@ def test_print_add(): check_output(cap.output, patterns) +@security_off_wrap def test_print_assign(): class Print_Assign(Cell): def __init__(self): @@ -125,6 +129,7 @@ def test_print_assign(): check_output(cap.output, patterns) +@security_off_wrap def test_print_assign_add(): class Print_Assign_Add(Cell): def __init__(self): @@ -155,6 +160,7 @@ def test_print_assign_add(): check_output(cap.output, patterns) +@security_off_wrap def test_print_while(): class Print_While(Cell): def __init__(self): @@ -189,6 +195,7 @@ def test_print_while(): check_output(cap.output, patterns) +@security_off_wrap def test_print_if(): class Print_If(Cell): def __init__(self): @@ -219,6 +226,7 @@ def test_print_if(): check_output(cap.output, patterns) +@security_off_wrap def test_print_assign_while(): class Print_Assign_While(Cell): def __init__(self): @@ -262,6 +270,7 @@ def test_print_assign_while(): check_output(cap.output, patterns) +@security_off_wrap def test_print_assign_if(): class Print_Assign_If(Cell): def __init__(self): @@ -517,6 +526,7 @@ def test_for(): np.testing.assert_array_equal(out.asnumpy(), expect.asnumpy()) +@security_off_wrap def test_print_for(): class Print_For(Cell): def __init__(self): @@ -553,6 +563,7 @@ def test_print_for(): check_output(cap.output, patterns) +@security_off_wrap def test_print_assign_for(): class Print_Assign_For(Cell): def __init__(self): @@ -739,6 +750,7 @@ def test_multi_assign_addn(): np.testing.assert_almost_equal(out.asnumpy(), expect.asnumpy()) +@security_off_wrap def test_multi_assign_print(): class Multi_Assign_Print(Cell): def __init__(self): diff --git a/tests/st/auto_monad/test_auto_monad_mindtester.py b/tests/st/auto_monad/test_auto_monad_mindtester.py index cce91ea07d1..76df8175729 100644 --- a/tests/st/auto_monad/test_auto_monad_mindtester.py +++ b/tests/st/auto_monad/test_auto_monad_mindtester.py @@ -24,6 +24,7 @@ from mindspore.common.initializer import initializer from mindspore.train.model import Model from mindspore.ops.composite import GradOperation from mindspore.common import ParameterTuple +from tests.security_utils import security_off_wrap context.set_context(mode=context.GRAPH_MODE) @@ -346,6 +347,7 @@ class SideEffectIOCellAddnNet(Cell): return grad_out +@security_off_wrap @pytest.mark.level1 @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @@ -460,7 +462,7 @@ class SideEffectPrintInHighOrdeAddnNet(Cell): grad_out = grad_net(params, grad_ys) return grad_out - +@security_off_wrap @pytest.mark.level1 @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training diff --git a/tests/st/ops/gpu/test_print_op.py b/tests/st/ops/gpu/test_print_op.py index 48c325ab29c..7a764fd68d0 100644 --- a/tests/st/ops/gpu/test_print_op.py +++ b/tests/st/ops/gpu/test_print_op.py @@ -21,6 +21,7 @@ from mindspore import Tensor import mindspore.nn as nn from mindspore.ops import operations as P import mindspore.context as context +from tests.security_utils import security_off_wrap class PrintNetOneInput(nn.Cell): @@ -53,6 +54,8 @@ class PrintNetIndex(nn.Cell): return x + +@security_off_wrap def print_testcase(nptype): # large shape x = np.arange(20808).reshape(6, 3, 34, 34).astype(nptype) @@ -85,6 +88,7 @@ class PrintNetString(nn.Cell): return x +@security_off_wrap def print_testcase_string(nptype): x = np.ones(18).astype(nptype) y = np.arange(9).reshape(3, 3).astype(nptype) @@ -106,6 +110,7 @@ class PrintTypes(nn.Cell): return x +@security_off_wrap @pytest.mark.level0 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard @@ -118,6 +123,7 @@ def test_print_multiple_types(): net(x, y, z) +@security_off_wrap @pytest.mark.level1 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard @@ -125,6 +131,7 @@ def test_print_bool(): print_testcase(np.bool) +@security_off_wrap @pytest.mark.level1 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard @@ -132,6 +139,7 @@ def test_print_int8(): print_testcase(np.int8) +@security_off_wrap @pytest.mark.level1 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard @@ -139,6 +147,7 @@ def test_print_int16(): print_testcase(np.int16) +@security_off_wrap @pytest.mark.level1 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard @@ -146,6 +155,7 @@ def test_print_int32(): print_testcase(np.int32) +@security_off_wrap @pytest.mark.level1 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard @@ -153,6 +163,7 @@ def test_print_int64(): print_testcase(np.int64) +@security_off_wrap @pytest.mark.level1 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard @@ -160,6 +171,7 @@ def test_print_uint8(): print_testcase(np.uint8) +@security_off_wrap @pytest.mark.level1 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard @@ -167,6 +179,7 @@ def test_print_uint16(): print_testcase(np.uint16) +@security_off_wrap @pytest.mark.level1 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard @@ -174,6 +187,7 @@ def test_print_uint32(): print_testcase(np.uint32) +@security_off_wrap @pytest.mark.level1 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard @@ -181,6 +195,7 @@ def test_print_uint64(): print_testcase(np.uint64) +@security_off_wrap @pytest.mark.level1 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard @@ -188,6 +203,7 @@ def test_print_float16(): print_testcase(np.float16) +@security_off_wrap @pytest.mark.level1 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard @@ -195,6 +211,7 @@ def test_print_float32(): print_testcase(np.float32) +@security_off_wrap @pytest.mark.level1 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard diff --git a/tests/ut/python/parallel/test_print.py b/tests/ut/python/parallel/test_print.py index 9da75777f86..8bdf89073fa 100644 --- a/tests/ut/python/parallel/test_print.py +++ b/tests/ut/python/parallel/test_print.py @@ -19,7 +19,7 @@ from mindspore import context, Tensor, Parameter from mindspore.common.api import _cell_graph_executor from mindspore.nn import Cell, TrainOneStepCell, Momentum, BatchNorm2d, BatchNorm1d from mindspore.ops import operations as P - +from tests.security_utils import security_off_wrap class Net(Cell): def __init__(self, conv2d_weight, out_channel, kernel_size, pad_mode, stride, @@ -53,6 +53,7 @@ def compile_net(net): context.reset_auto_parallel_context() +@security_off_wrap def test_batchnorm_data_parallel(): context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=8, global_rank=0) strategy1 = ((8, 1, 1, 1), (1, 1, 1, 1)) @@ -61,6 +62,7 @@ def test_batchnorm_data_parallel(): compile_net(net) +@security_off_wrap def test_batchnorm_model_parallel1(): context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=8, global_rank=0) strategy1 = ((2, 2, 1, 1), (2, 2, 1, 1)) @@ -69,6 +71,7 @@ def test_batchnorm_model_parallel1(): compile_net(net) +@security_off_wrap def test_batchnorm_model_parallel2(): context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=32, global_rank=0) strategy1 = ((2, 2, 2, 2), (2, 2, 1, 1)) diff --git a/tests/ut/python/pipeline/infer/test_auto_monad.py b/tests/ut/python/pipeline/infer/test_auto_monad.py index a71f340f36c..8cecce0de1d 100644 --- a/tests/ut/python/pipeline/infer/test_auto_monad.py +++ b/tests/ut/python/pipeline/infer/test_auto_monad.py @@ -9,6 +9,7 @@ from mindspore.ops import operations as P from mindspore.ops import functional as F from mindspore import Tensor from mindspore.common.parameter import Parameter, ParameterTuple +from tests.security_utils import security_off_wrap grad_all_list = C.GradOperation(get_all=True, get_by_list=True) grad_by_list = C.GradOperation(get_by_list=True) @@ -117,6 +118,7 @@ def test_insert_gradient_of(): print(grad_net(Tensor(input_data))) +@security_off_wrap def test_user_defined_bprop(): class UserDefinedNet(nn.Cell): def __init__(self): @@ -151,6 +153,7 @@ def test_user_defined_bprop(): # user defined bprop don't have the same size of parameters with primal's +@security_off_wrap def test_user_defined_bad_bprop(): class UserDefinedNet(nn.Cell): def __init__(self): @@ -186,6 +189,7 @@ def test_user_defined_bad_bprop(): # shoul compile success and Print in presented in the final function graph. +@security_off_wrap @pytest.mark.skip(reason="isolated nodes exception") def test_unused_var(): class UnusedVar(nn.Cell): @@ -212,6 +216,7 @@ def test_unused_var(): # shoul compile success and Print in presented in the final function graph. +@security_off_wrap @pytest.mark.skip(reason="isolated nodes exception") def test_hof_unused_var(): class UnusedVar(nn.Cell): @@ -241,6 +246,7 @@ def test_hof_unused_var(): # shoul compile success and Print in presented in the final function graph. +@security_off_wrap @pytest.mark.skip(reason="isolated nodes exception") def test_partial_hof_unused_var(): class UnusedVar(nn.Cell): diff --git a/tests/ut/python/pynative_mode/test_stop_gradient.py b/tests/ut/python/pynative_mode/test_stop_gradient.py index b045abdcbc1..d6ebe607311 100644 --- a/tests/ut/python/pynative_mode/test_stop_gradient.py +++ b/tests/ut/python/pynative_mode/test_stop_gradient.py @@ -27,6 +27,7 @@ from mindspore.ops import composite as C from mindspore.ops import operations as P from mindspore.ops.functional import stop_gradient from mindspore.ops.primitive import prim_attr_register, PrimitiveWithInfer +from tests.security_utils import security_off_wrap from ..ut_filter import non_graph_engine from ....mindspore_test_framework.utils.bprop_util import bprop @@ -429,6 +430,7 @@ def test_stop_gradient_11(): Tensor(np.ones([2]).astype(np.float32))) +@security_off_wrap def test_stop_print(): class StopPrint(nn.Cell): def __init__(self): diff --git a/tests/ut/python/utils/test_serialize.py b/tests/ut/python/utils/test_serialize.py index 35df9722701..3db1b51b49d 100644 --- a/tests/ut/python/utils/test_serialize.py +++ b/tests/ut/python/utils/test_serialize.py @@ -34,6 +34,7 @@ from mindspore.ops import operations as P from mindspore.train.callback import _CheckpointManager from mindspore.train.serialization import save_checkpoint, load_checkpoint, load_param_into_net, \ export, _save_graph, load +from tests.security_utils import security_off_wrap from ..ut_filter import non_graph_engine context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") @@ -419,6 +420,7 @@ class PrintNet(nn.Cell): return int8, uint8, int16, uint16, int32, uint32, int64, uint64, flt16, flt32, flt64, bool_, scale1, scale2 +@security_off_wrap def test_print(): print_net = PrintNet() int8 = Tensor(np.random.randint(100, size=(10, 10), dtype="int8"))