clean pylint

pull/1197/head
jinyaohui 5 years ago
parent 93f6fc0ab0
commit bcfaff97f9

@ -166,7 +166,7 @@ class BertAttentionMask(nn.Cell):
super(BertAttentionMask, self).__init__()
self.has_attention_mask = has_attention_mask
self.multiply_data = Tensor([-1000.0,], dtype=dtype)
self.multiply_data = Tensor([-1000.0, ], dtype=dtype)
self.multiply = P.Mul()
if self.has_attention_mask:
@ -189,6 +189,7 @@ class BertAttentionMask(nn.Cell):
return attention_scores
class BertAttentionMaskBackward(nn.Cell):
def __init__(self,
attention_mask_shape,
@ -196,7 +197,7 @@ class BertAttentionMaskBackward(nn.Cell):
dtype=mstype.float32):
super(BertAttentionMaskBackward, self).__init__()
self.has_attention_mask = has_attention_mask
self.multiply_data = Tensor([-1000.0,], dtype=dtype)
self.multiply_data = Tensor([-1000.0, ], dtype=dtype)
self.multiply = P.Mul()
self.attention_mask = Tensor(np.ones(shape=attention_mask_shape).astype(np.float32))
if self.has_attention_mask:
@ -218,6 +219,7 @@ class BertAttentionMaskBackward(nn.Cell):
attention_scores = self.add(adder, attention_scores)
return attention_scores
class BertAttentionSoftmax(nn.Cell):
def __init__(self,
batch_size,

@ -20,7 +20,7 @@ import numpy as np
from mindspore.model_zoo.Bert_NEZHA import GetNextSentenceOutput, BertNetworkWithLoss
from mindspore.model_zoo.Bert_NEZHA.bert_model import BertConfig, \
EmbeddingLookup, EmbeddingPostprocessor, BertOutput, \
BertAttention, BertSelfAttention, SaturateCast, TruncatedNormal,\
BertAttention, BertSelfAttention, SaturateCast, TruncatedNormal, \
BertEncoderCell, BertTransformer, CreateAttentionMaskFromInputMask, BertModel
from mindspore import context, nn
@ -373,9 +373,9 @@ verification_set = {
'id': 'BertDense_CICase',
'group': 'bert',
'block': BertDense(
hidden_size=8,
intermediate_size=8,
initializer_range=0.02),
hidden_size=8,
intermediate_size=8,
initializer_range=0.02),
'reduce_output': False
},
{

@ -19,17 +19,18 @@ import numpy as np
import mindspore.common.dtype as mstype
from mindspore import context
from mindspore.model_zoo.Bert_NEZHA.bert_model import BertAttention, SaturateCast, \
EmbeddingLookup, BertModel, \
BertConfig, EmbeddingPostprocessor, \
BertTransformer, BertEncoderCell, \
BertSelfAttention, CreateAttentionMaskFromInputMask, \
RelaPosMatrixGenerator, BertOutput, \
RelaPosEmbeddingsGenerator
EmbeddingLookup, BertModel, \
BertConfig, EmbeddingPostprocessor, \
BertTransformer, BertEncoderCell, \
BertSelfAttention, CreateAttentionMaskFromInputMask, \
RelaPosMatrixGenerator, BertOutput, \
RelaPosEmbeddingsGenerator
from ..mindspore_test import mindspore_test
from ..pipeline.forward.compare_forward import pipeline_for_compare_forward_with_npy_for_group_by_group_config_using_group_policy
from ..pipeline.forward.compare_forward import \
pipeline_for_compare_forward_with_npy_for_group_by_group_config_using_group_policy
from .bert_attention_submodules import BertAttentionQueryKeyMul, BertAttentionRelativePositionKeys, BertAttentionMask, \
BertAttentionSoftmax, BertAttentionRelativePositionValues, BertDense
BertAttentionSoftmax, BertAttentionRelativePositionValues, BertDense
verification_set = {
'inputs': [

@ -22,6 +22,7 @@ from ..pipeline.gradient.compare_gradient import \
pipeline_for_compare_inputs_grad_with_numerical_diff_for_group_by_group_config, \
pipeline_for_compare_inputs_jacobian_with_numerical_diff_for_group_by_group_config
from ..mindspore_test import mindspore_test
# from ...vm_impl import *

@ -18,9 +18,11 @@
from ..mindspore_test import mindspore_test
from ..pipeline.forward.verify_exception import pipeline_for_verify_exception_for_case_by_case_config
def func_raise_exception(x, y):
raise ValueError()
verification_set = [
('func_raise_exception', {
'block': (func_raise_exception, {'exception': ValueError}),
@ -28,6 +30,7 @@ verification_set = [
})
]
@mindspore_test(pipeline_for_verify_exception_for_case_by_case_config)
def test_check_exception():
return verification_set

@ -42,6 +42,7 @@ verification_set = [
})
]
@mindspore_test(pipeline_for_check_model_loss_for_case_by_case_config)
def test_lamb_loss():
context.set_context(mode=context.GRAPH_MODE)

@ -40,6 +40,7 @@ verification_set = [
})
]
@mindspore_test(pipeline_for_check_model_loss_for_case_by_case_config)
def test_model_loss():
context.set_context(mode=context.GRAPH_MODE)

@ -21,6 +21,8 @@ import numpy as np
from ..mindspore_test import mindspore_test
from ..pipeline.forward.verify_shapetype import pipeline_for_verify_shapetype_for_group_by_group_config
# from ...vm_impl import *
# functions could be operations or NN cell

@ -53,6 +53,7 @@ verification_set = [
})
]
@mindspore_test(pipeline_for_compare_inputs_grad_with_npy_for_case_by_case_config)
def test_reid_check_gradient():
context.set_context(mode=context.PYNATIVE_MODE)

@ -21,6 +21,7 @@ import pytest
from ...components.icomponent import IExectorComponent
from ...utils import keyword
class CheckExceptionsEC(IExectorComponent):
"""
Check if the function raises the expected Exception and the error message contains specified keywords if not None.
@ -32,6 +33,7 @@ class CheckExceptionsEC(IExectorComponent):
'error_keywords': ['TensorAdd', 'shape']
}
"""
def __call__(self):
f = self.function[keyword.block]
args = self.inputs[keyword.desc_inputs]

@ -19,6 +19,7 @@ from ...components.icomponent import IExectorComponent
from ...utils.check_gradient import check_gradient, ScalarGradChecker
from ...utils.config_util import get_grad_checking_options
class CheckGradientForScalarFunctionEC(IExectorComponent):
"""
Check gradient against numeric with respect to inputs for scalar function, execute and verify.
@ -26,6 +27,7 @@ class CheckGradientForScalarFunctionEC(IExectorComponent):
Examples:
'block': scalar_function
"""
def __call__(self):
f, args, delta, max_error, input_selector, output_selector, sampling_times, _ = \
get_grad_checking_options(self.function, self.inputs)

@ -19,6 +19,7 @@ from ...components.icomponent import IExectorComponent
from ...utils.check_gradient import check_gradient, OperationGradChecker
from ...utils.config_util import get_grad_checking_options
class CheckGradientWrtInputsEC(IExectorComponent):
"""
Check gradient against numeric with respect to inputs, execute and verify.
@ -35,6 +36,7 @@ class CheckGradientWrtInputsEC(IExectorComponent):
key_act=None,
initializer_range=0.02)
"""
def __call__(self):
f, args, delta, max_error, input_selector, output_selector, \
sampling_times, reduce_output = get_grad_checking_options(self.function, self.inputs)

@ -19,6 +19,7 @@ from ...components.icomponent import IExectorComponent
from ...utils.check_gradient import check_gradient, NNGradChecker
from ...utils.config_util import get_grad_checking_options
class CheckGradientWrtParamsEC(IExectorComponent):
"""
Check gradient against numeric with respect to params, execute and verify.
@ -35,6 +36,7 @@ class CheckGradientWrtParamsEC(IExectorComponent):
key_act=None,
initializer_range=0.02)
"""
def __call__(self):
f, args, delta, max_error, input_selector, output_selector, \
sampling_times, reduce_output = get_grad_checking_options(self.function, self.inputs)

@ -19,6 +19,7 @@ from ...components.icomponent import IExectorComponent
from ...utils.check_gradient import check_jacobian, ScalarGradChecker
from ...utils.config_util import get_grad_checking_options
class CheckJacobianForScalarFunctionEC(IExectorComponent):
"""
Check jacobian against numeric with respect to inputs for scalar_func, execute and verify.
@ -26,6 +27,7 @@ class CheckJacobianForScalarFunctionEC(IExectorComponent):
Examples:
'block': scalar_function
"""
def __call__(self):
f, args, delta, max_error, input_selector, output_selector, _, _ = \
get_grad_checking_options(self.function, self.inputs)

@ -19,6 +19,7 @@ from ...components.icomponent import IExectorComponent
from ...utils.check_gradient import check_jacobian, OperationGradChecker
from ...utils.config_util import get_grad_checking_options
class CheckJacobianWrtInputsEC(IExectorComponent):
"""
Check jacobian against numeric with respect to inputs, execute and verify.
@ -35,6 +36,7 @@ class CheckJacobianWrtInputsEC(IExectorComponent):
key_act=None,
initializer_range=0.02)
"""
def __call__(self):
f, args, delta, max_error, input_selector, output_selector, _, _ = \
get_grad_checking_options(self.function, self.inputs)

@ -19,6 +19,7 @@ from ...components.icomponent import IExectorComponent
from ...utils.check_gradient import check_jacobian, NNGradChecker
from ...utils.config_util import get_grad_checking_options
class CheckJacobianWrtParamsEC(IExectorComponent):
"""
Check jacobian against numeric with respect to params, execute and verify.
@ -35,6 +36,7 @@ class CheckJacobianWrtParamsEC(IExectorComponent):
key_act=None,
initializer_range=0.02)
"""
def __call__(self):
f, args, delta, max_error, input_selector, output_selector, _, _ = \
get_grad_checking_options(self.function, self.inputs)

@ -19,6 +19,7 @@ from ...components.icomponent import IExectorComponent
from ...utils.model_util import Model
from ...utils import keyword
class LossVerifierEC(IExectorComponent):
"""
Verify if the model can converge to expected loss.
@ -32,6 +33,7 @@ class LossVerifierEC(IExectorComponent):
'loss_upper_bound': 0.03,
}
"""
def __call__(self):
model = self.function[keyword.block][keyword.model]
loss = self.function[keyword.block][keyword.loss]

@ -18,10 +18,12 @@
from ...components.icomponent import IExectorComponent
from ...utils import keyword
class IdentityEC(IExectorComponent):
"""
Execute function/inputs.
"""
def __call__(self):
result_id = self.function[keyword.id] + '-' + self.inputs[keyword.id]
group = self.function[keyword.group] + '-' + self.inputs[keyword.group]

@ -18,10 +18,12 @@
from ...components.icomponent import IExectorComponent
from ...utils import keyword
class IdentityBackwardEC(IExectorComponent):
"""
Execute function/inputs, with all bprops attached, the bprop function created by BC should handle these bprops.
"""
def __call__(self):
result_id = self.function[keyword.id] + '-' + self.inputs[keyword.id]
group = self.function[keyword.group] + '-' + self.inputs[keyword.group]

@ -18,10 +18,12 @@
from ...components.icomponent import IERPolicyComponent
from ...utils import keyword
class GroupCartesianProductERPC(IERPolicyComponent):
"""
Combine expect/result by do cartesian product on group.
"""
def __call__(self):
ret = [(s1, s2) for s1 in self.expect for s2 in self.result if s1[keyword.group] == s2[keyword.group]]
return ret

@ -18,10 +18,12 @@
from ...components.icomponent import IERPolicyComponent
from ...utils import keyword
class IdCartesianProductERPC(IERPolicyComponent):
"""
Combine expect/result by do cartesian product on id.
"""
def __call__(self):
ret = [(s1, s2) for s1 in self.expect for s2 in self.result if s1[keyword.id] == s2[keyword.id]]
return ret

@ -21,6 +21,7 @@ from ...components.icomponent import IFacadeComponent
from ...utils.facade_util import get_block_config, fill_block_config
from ...utils import keyword
class MeFacadeFC(IFacadeComponent):
"""
Transform ME style config to mindspore_test_framework style.
@ -47,6 +48,7 @@ class MeFacadeFC(IFacadeComponent):
}
})
"""
def __call__(self):
ret = get_block_config()
for config in self.verification_set:

@ -18,6 +18,7 @@
from ...components.icomponent import IBuilderComponent
from ...utils.block_util import compile_block, gen_net, create_funcs
class CompileBlockBC(IBuilderComponent):
"""
Build a function that do mindspore compile.
@ -42,5 +43,6 @@ class CompileBlockBC(IBuilderComponent):
dtype=mstype.float32,
compute_type=mstype.float32)
"""
def __call__(self):
return create_funcs(self.verification_set, gen_net, compile_block)

@ -19,6 +19,7 @@ from mindspore.ops.composite import GradOperation
from ...components.icomponent import IBuilderComponent
from ...utils.block_util import compile_block, gen_grad_net, create_funcs
class CompileBackwardBlockWrtInputsBC(IBuilderComponent):
"""
Build a function that do mindspore gradient compile with respect to inputs.
@ -43,6 +44,7 @@ class CompileBackwardBlockWrtInputsBC(IBuilderComponent):
dtype=mstype.float32,
compute_type=mstype.float32)
"""
def __call__(self):
grad_op = GradOperation('grad', get_all=True, sens_param=True)
return create_funcs(self.verification_set, gen_grad_net, compile_block, grad_op)

@ -19,6 +19,7 @@ from mindspore.ops.composite import GradOperation
from ...components.icomponent import IBuilderComponent
from ...utils.block_util import compile_block, gen_grad_net, create_funcs
class CompileBackwardBlockWrtParamsBC(IBuilderComponent):
"""
Build a function that do mindspore gradient compile with respect to params.
@ -43,6 +44,7 @@ class CompileBackwardBlockWrtParamsBC(IBuilderComponent):
dtype=mstype.float32,
compute_type=mstype.float32)
"""
def __call__(self, verification_set):
grad_op = GradOperation('grad', get_by_list=True, sens_param=True)
return create_funcs(self.verification_set, gen_grad_net, compile_block, grad_op)

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save