switch positon of the codes for second_order

pull/1315/head
z00478463 5 years ago
parent 27c13794d2
commit da62a44d85

@ -16,6 +16,7 @@
network config setting, will be used in train.py and eval.py network config setting, will be used in train.py and eval.py
""" """
from easydict import EasyDict as ed from easydict import EasyDict as ed
config = ed({ config = ed({
"class_num": 1000, "class_num": 1000,
"batch_size": 32, "batch_size": 32,

@ -13,24 +13,26 @@
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
from mindspore.nn.loss.loss import _Loss import mindspore.nn as nn
from mindspore.ops import operations as P
from mindspore.ops import functional as F
from mindspore import Tensor from mindspore import Tensor
from mindspore.common import dtype as mstype from mindspore.common import dtype as mstype
import mindspore.nn as nn from mindspore.nn.loss.loss import _Loss
from mindspore.ops import functional as F
from mindspore.ops import operations as P
class CrossEntropy(_Loss): class CrossEntropy(_Loss):
def __init__(self, smooth_factor=0., num_classes=1000): def __init__(self, smooth_factor=0., num_classes=1000):
super(CrossEntropy, self).__init__() super(CrossEntropy, self).__init__()
self.onehot = P.OneHot() self.onehot = P.OneHot()
self.on_value = Tensor(1.0 - smooth_factor, mstype.float32) self.on_value = Tensor(1.0 - smooth_factor, mstype.float32)
self.off_value = Tensor(1.0 * smooth_factor / (num_classes -1), mstype.float32) self.off_value = Tensor(1.0 * smooth_factor / (num_classes - 1), mstype.float32)
#self.cast = P.Cast() # self.cast = P.Cast()
self.ce = nn.SoftmaxCrossEntropyWithLogits() self.ce = nn.SoftmaxCrossEntropyWithLogits()
self.mean = P.ReduceMean(False) self.mean = P.ReduceMean(False)
def construct(self, logit, label): def construct(self, logit, label):
#one_hot_label = self.onehot(self.cast(label, mstype.int32), # one_hot_label = self.onehot(self.cast(label, mstype.int32),
# F.shape(logit)[1], self.on_value, self.off_value)、 # F.shape(logit)[1], self.on_value, self.off_value)、
one_hot_label = self.onehot(label, F.shape(logit)[1], self.on_value, self.off_value) one_hot_label = self.onehot(label, F.shape(logit)[1], self.on_value, self.off_value)
loss = self.ce(logit, one_hot_label) loss = self.ce(logit, one_hot_label)

@ -12,10 +12,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
from te import tik
from topi.cce import util
from mindspore.ops.op_info_register import op_info_register from mindspore.ops.op_info_register import op_info_register
@op_info_register("""{ @op_info_register("""{
"op_name": "CusBatchMatMul", "op_name": "CusBatchMatMul",
"imply_type": "TBE", "imply_type": "TBE",
@ -71,11 +70,5 @@ from mindspore.ops.op_info_register import op_info_register
} }
] ]
}""") }""")
def CusBatchMatMul(input_x1, input_x2, output, transpose_a=False, transpose_b=True, kernel_name="batchmatmul"): def CusBatchMatMul(input_x1, input_x2, output, transpose_a=False, transpose_b=True, kernel_name="batchmatmul"):
return return

@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
from te import tik
from topi.cce import util
from mindspore.ops.op_info_register import op_info_register from mindspore.ops.op_info_register import op_info_register
@op_info_register("""{ @op_info_register("""{
"op_name": "CusCholeskyTrsm", "op_name": "CusCholeskyTrsm",
"imply_type": "TBE", "imply_type": "TBE",
@ -58,7 +58,5 @@ from mindspore.ops.op_info_register import op_info_register
} }
] ]
}""") }""")
def CusCholeskyTrsm(input_x, output, kernel_name):
def CusCholeskyTrsm(input_x,output, kernel_name):
return return

@ -12,42 +12,27 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
import numpy as np
from mindspore.ops import prim_attr_register, PrimitiveWithInfer from mindspore.ops import prim_attr_register, PrimitiveWithInfer
from mindspore import Tensor
import mindspore as ms
from mindspore.ops.composite import multitype_ops as C from mindspore.ops.composite import multitype_ops as C
# y = x^2 # y = x^2
class CusBatchMatMul(PrimitiveWithInfer): class CusBatchMatMul(PrimitiveWithInfer):
"""CusMatMulCube definition""" """CusMatMulCube definition"""
@prim_attr_register @prim_attr_register
def __init__(self): def __init__(self):
"""init CusMatMulCube""" """init CusMatMulCube"""
self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y']) self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y'])
# self.transpose_a = transpose_a
# self.transpose_b = transpose_b
from .batch_matmul_impl import CusBatchMatMul
def get_bprop(self): def get_bprop(self):
def bprop(x1, x2, out, dout): def bprop(x1, x2, out, dout):
return (C.zeros_like(x1),C.zeros_like(x2)) return (C.zeros_like(x1), C.zeros_like(x2))
return bprop return bprop
def infer_shape(self, data1_shape, data2_shape): def infer_shape(self, data1_shape, data2_shape):
#shape = [1, data1_shape[1], data2_shape[2], 16, 16]
#return shape
# if self.transpose_a == True:
# k1, m = data1_shape
# else:
# m, k1 = data1_shape
# if self.transpose_b == True:
# n, k2 = data2_shape
# else:
# k2, n = data2_shape
# assert k1==k2
# shape = [m, n]
return data1_shape return data1_shape
def infer_dtype(self, data1_dtype, data2_dtype): def infer_dtype(self, data1_dtype, data2_dtype):
return data1_dtype return data1_dtype
# return ms.common.dtype.tensor_type(getattr(ms, "float32"))

@ -12,24 +12,23 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
import numpy as np
from mindspore.ops import prim_attr_register, PrimitiveWithInfer from mindspore.ops import prim_attr_register, PrimitiveWithInfer
from mindspore import Tensor
class CusCholeskyTrsm(PrimitiveWithInfer): class CusCholeskyTrsm(PrimitiveWithInfer):
"""CusCholeskyTrsm definition""" """CusCholeskyTrsm definition"""
@prim_attr_register @prim_attr_register
def __init__(self): def __init__(self):
"""init CusCholeskyTrsm""" """init CusCholeskyTrsm"""
self.init_prim_io_names(inputs=['x1'], outputs=['y']) self.init_prim_io_names(inputs=['x1'], outputs=['y'])
from .cholesky_trsm import CusCholeskyTrsm
def infer_shape(self, data1_shape): def infer_shape(self, data1_shape):
m,n = data1_shape m, n = data1_shape
if m >= 128: if m >= 128:
return [m//128,128,128] return [m // 128, 128, 128]
else: else:
return [1,64,64] return [1, 64, 64]
def infer_dtype(self, data1_dtype): def infer_dtype(self, data1_dtype):
return data1_dtype return data1_dtype

@ -12,31 +12,30 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
import numpy as np
from mindspore.ops import prim_attr_register, PrimitiveWithInfer from mindspore.ops import prim_attr_register, PrimitiveWithInfer
from mindspore import Tensor
from mindspore.ops.composite import multitype_ops as C from mindspore.ops.composite import multitype_ops as C
class CusFusedAbsMax1(PrimitiveWithInfer): class CusFusedAbsMax1(PrimitiveWithInfer):
"""CusCholeskyTrsm definition""" """CusCholeskyTrsm definition"""
@prim_attr_register @prim_attr_register
def __init__(self, origin_shape = [-1,-1]): def __init__(self, origin_shape=[-1, -1]):
"""init CusCholeskyTrsm""" """init CusCholeskyTrsm"""
self.init_prim_io_names(inputs=['x1'], outputs=['y']) self.init_prim_io_names(inputs=['x1'], outputs=['y'])
from .fused_abs_max1 import CusFusedAbsMax1
self.origin_shape = origin_shape self.origin_shape = origin_shape
def get_bprop(self): def get_bprop(self):
def bprop(x, out, dout): def bprop(x, out, dout):
return (C.zeros_like(x),) return (C.zeros_like(x),)
return bprop return bprop
def infer_shape(self, data1_shape): def infer_shape(self, data1_shape):
if len(data1_shape) == 2: if len(data1_shape) == 2:
return [1,] return [1, ]
else: else:
return [32, 64] return [32, 64]
# return [128,128]
def infer_dtype(self, data1_dtype): def infer_dtype(self, data1_dtype):
return data1_dtype return data1_dtype

@ -13,26 +13,26 @@
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
import numpy as np
from mindspore.ops import prim_attr_register, PrimitiveWithInfer from mindspore.ops import prim_attr_register, PrimitiveWithInfer
from mindspore import Tensor
from mindspore.ops.composite import multitype_ops as C from mindspore.ops.composite import multitype_ops as C
class CusImg2Col(PrimitiveWithInfer): class CusImg2Col(PrimitiveWithInfer):
"""CusImg2Col definition""" """CusImg2Col definition"""
@prim_attr_register @prim_attr_register
def __init__(self, ksizes, strides, dilates = (1, 1, 1, 1), mode="NC1HWC0"): def __init__(self, ksizes, strides, dilates=(1, 1, 1, 1), mode="NC1HWC0"):
"""init CusImg2Col""" """init CusImg2Col"""
self.init_prim_io_names(inputs=['x1'], outputs=['y']) self.init_prim_io_names(inputs=['x1'], outputs=['y'])
self.ksizes = ksizes self.ksizes = ksizes
self.strides = strides self.strides = strides
self.dilates = dilates self.dilates = dilates
self.mode = mode self.mode = mode
from .img2col_impl import CusImg2Col
def get_bprop(self): def get_bprop(self):
def bprop(x, out, dout): def bprop(x, out, dout):
return (C.zeros_like(x),) return (C.zeros_like(x),)
return bprop return bprop
def infer_shape(self, data1_shape): def infer_shape(self, data1_shape):

@ -12,30 +12,31 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
import numpy as np
from mindspore.ops import prim_attr_register, PrimitiveWithInfer
from mindspore import Tensor
import mindspore as ms import mindspore as ms
from mindspore.ops import prim_attr_register, PrimitiveWithInfer
from mindspore.ops.composite import multitype_ops as C from mindspore.ops.composite import multitype_ops as C
# y = x^2 # y = x^2
class CusMatMulCube(PrimitiveWithInfer): class CusMatMulCube(PrimitiveWithInfer):
"""CusMatMulCube definition""" """CusMatMulCube definition"""
@prim_attr_register @prim_attr_register
def __init__(self, transpose_a=False, transpose_b=False): def __init__(self, transpose_a=False, transpose_b=False):
"""init CusMatMulCube""" """init CusMatMulCube"""
self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y']) self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y'])
self.transpose_a = transpose_a self.transpose_a = transpose_a
self.transpose_b = transpose_b self.transpose_b = transpose_b
from .matmul_cube_impl import CusMatMulCube
def get_bprop(self): def get_bprop(self):
def bprop(x1, x2, out, dout): def bprop(x1, x2, out, dout):
return (C.zeros_like(x1),C.zeros_like(x2)) return (C.zeros_like(x1), C.zeros_like(x2))
return bprop return bprop
def infer_shape(self, data1_shape, data2_shape): def infer_shape(self, data1_shape, data2_shape):
#shape = [1, data1_shape[1], data2_shape[2], 16, 16] # shape = [1, data1_shape[1], data2_shape[2], 16, 16]
#return shape # return shape
if self.transpose_a == True: if self.transpose_a == True:
k1, m = data1_shape k1, m = data1_shape
else: else:
@ -44,7 +45,7 @@ class CusMatMulCube(PrimitiveWithInfer):
n, k2 = data2_shape n, k2 = data2_shape
else: else:
k2, n = data2_shape k2, n = data2_shape
assert k1==k2 assert k1 == k2
shape = [m, n] shape = [m, n]
return shape return shape

@ -12,23 +12,24 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
import numpy as np
from mindspore.ops import prim_attr_register, PrimitiveWithInfer
from mindspore import Tensor
import mindspore as ms import mindspore as ms
from mindspore.ops import prim_attr_register, PrimitiveWithInfer
from mindspore.ops.composite import multitype_ops as C from mindspore.ops.composite import multitype_ops as C
# y = x^2 # y = x^2
class CusMatMulCubeDenseLeft(PrimitiveWithInfer): class CusMatMulCubeDenseLeft(PrimitiveWithInfer):
"""CusMatMulCube definition""" """CusMatMulCube definition"""
@prim_attr_register @prim_attr_register
def __init__(self): def __init__(self):
"""init CusMatMulCube""" """init CusMatMulCube"""
self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y']) self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y'])
from .matmul_cube_dense_left import CusMatMulCubeDenseLeft
def get_bprop(self): def get_bprop(self):
def bprop(x1, x2, out, dout): def bprop(x1, x2, out, dout):
return (C.zeros_like(x1),C.zeros_like(x2)) return (C.zeros_like(x1), C.zeros_like(x2))
return bprop return bprop
def infer_shape(self, data1_shape, data2_shape): def infer_shape(self, data1_shape, data2_shape):

@ -12,23 +12,23 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
import numpy as np
from mindspore.ops import prim_attr_register, PrimitiveWithInfer
from mindspore import Tensor
import mindspore as ms import mindspore as ms
from mindspore.ops import prim_attr_register, PrimitiveWithInfer
from mindspore.ops.composite import multitype_ops as C from mindspore.ops.composite import multitype_ops as C
# y = x^2
class CusMatMulCubeFraczRightMul(PrimitiveWithInfer): class CusMatMulCubeFraczRightMul(PrimitiveWithInfer):
"""CusMatMulCubeFraczRightMul definition""" """CusMatMulCubeFraczRightMul definition"""
@prim_attr_register @prim_attr_register
def __init__(self): def __init__(self):
"""init CusMatMulCubeFraczRightMul""" """init CusMatMulCubeFraczRightMul"""
self.init_prim_io_names(inputs=['x1', 'x2', 'x3'], outputs=['y']) self.init_prim_io_names(inputs=['x1', 'x2', 'x3'], outputs=['y'])
from .matmul_cube_fracz_right_mul_impl import CusMatMulCubeFraczRightMul
def get_bprop(self): def get_bprop(self):
def bprop(x1, x2, x3, out, dout): def bprop(x1, x2, x3, out, dout):
return (C.zeros_like(x1),C.zeros_like(x2),C.zeros_like(x3)) return (C.zeros_like(x1), C.zeros_like(x2), C.zeros_like(x3))
return bprop return bprop
def infer_shape(self, data1_shape, data2_shape, data3_shape): def infer_shape(self, data1_shape, data2_shape, data3_shape):

@ -12,27 +12,27 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
import numpy as np
from mindspore.ops import prim_attr_register, PrimitiveWithInfer from mindspore.ops import prim_attr_register, PrimitiveWithInfer
from mindspore import Tensor
import mindspore as ms
from mindspore.ops.composite import multitype_ops as C from mindspore.ops.composite import multitype_ops as C
# y = x^2
class CusMatrixCombine(PrimitiveWithInfer): class CusMatrixCombine(PrimitiveWithInfer):
"""CusMatMulCube definition""" """CusMatMulCube definition"""
@prim_attr_register @prim_attr_register
def __init__(self): def __init__(self):
"""init CusMatMulCube""" """init CusMatMulCube"""
self.init_prim_io_names(inputs=['x'], outputs=['y']) self.init_prim_io_names(inputs=['x'], outputs=['y'])
from .matrix_combine_impl import CusMatrixCombine
def get_bprop(self): def get_bprop(self):
def bprop(x, out, dout): def bprop(x, out, dout):
return (C.zeros_like(x),) return (C.zeros_like(x),)
return bprop return bprop
def infer_shape(self, data_shape): def infer_shape(self, data_shape):
a, b, c = data_shape a, b, c = data_shape
shape = [a*b, a*c] shape = [a * b, a * c]
return shape return shape

@ -14,22 +14,22 @@
# ============================================================================ # ============================================================================
import numpy as np
from mindspore.ops import prim_attr_register, PrimitiveWithInfer from mindspore.ops import prim_attr_register, PrimitiveWithInfer
from mindspore import Tensor
from mindspore.ops.composite import multitype_ops as C from mindspore.ops.composite import multitype_ops as C
class CusTranspose02314(PrimitiveWithInfer): class CusTranspose02314(PrimitiveWithInfer):
"""CusTranspose02314 definition""" """CusTranspose02314 definition"""
@prim_attr_register @prim_attr_register
def __init__(self): def __init__(self):
"""init CusTranspose02314""" """init CusTranspose02314"""
self.init_prim_io_names(inputs=['x1'], outputs=['y']) self.init_prim_io_names(inputs=['x1'], outputs=['y'])
from .transpose02314_impl import CusTranspose02314
def get_bprop(self): def get_bprop(self):
def bprop(x, out, dout): def bprop(x, out, dout):
return (C.zeros_like(x),) return (C.zeros_like(x),)
return bprop return bprop
def infer_shape(self, data1_shape): def infer_shape(self, data1_shape):
@ -38,8 +38,6 @@ class CusTranspose02314(PrimitiveWithInfer):
c0 = 16 c0 = 16
c1 = c // 16 c1 = c // 16
shape = (n * h * w, c1 * c0) shape = (n * h * w, c1 * c0)
# axis_0, axis_1, axis_2, axis_3, axis_4 = data1_shape
# shape = (axis_0, axis_2, axis_3, axis_1, axis_4)
return shape return shape
def infer_dtype(self, data1_dtype): def infer_dtype(self, data1_dtype):

@ -13,9 +13,9 @@
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
from te import tik
from topi.cce import util
from mindspore.ops.op_info_register import op_info_register from mindspore.ops.op_info_register import op_info_register
@op_info_register("""{ @op_info_register("""{
"op_name": "CusFusedAbsMax1", "op_name": "CusFusedAbsMax1",
"imply_type": "TBE", "imply_type": "TBE",
@ -64,5 +64,5 @@ from mindspore.ops.op_info_register import op_info_register
} }
] ]
}""") }""")
def CusFusedAbsMax1(input_x, output, origin_shape = None, kernel_name="fused_abs_max1"): def CusFusedAbsMax1(input_x, output, origin_shape=None, kernel_name="fused_abs_max1"):
return return

@ -13,9 +13,9 @@
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
from te import tik
from topi.cce import util
from mindspore.ops.op_info_register import op_info_register from mindspore.ops.op_info_register import op_info_register
@op_info_register("""{ @op_info_register("""{
"op_name": "CusImg2ColNC1HWC0", "op_name": "CusImg2ColNC1HWC0",
"imply_type": "TBE", "imply_type": "TBE",
@ -82,6 +82,5 @@ from mindspore.ops.op_info_register import op_info_register
} }
] ]
}""") }""")
def CusImg2ColNC1HWC0(input_x, output, ksizes, strides, dilates, padding, kernel_name="img2col"): def CusImg2ColNC1HWC0(input_x, output, ksizes, strides, dilates, padding, kernel_name="img2col"):
return return

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
""" """
copyright 2019 Huawei Technologies Co., Ltd copyright 2020 Huawei Technologies Co., Ltd
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -19,21 +19,14 @@ matmul
""" """
from __future__ import absolute_import from __future__ import absolute_import
import te.lang.cce from mindspore.ops.op_info_register import op_info_register
import te.platform.cce_params as cce
from te.platform.fusion_manager import fusion_manager
from te import tvm
from topi import generic
from topi.cce import util from topi.cce import util
from impl.matmul_vector import matmul_vector_cce
from te import tik
from mindspore.ops.op_info_register import op_info_register
# General limitation of the size for input shape: 2**31 # General limitation of the size for input shape: 2**31
SHAPE_SIZE_LIMIT = 2147483648 SHAPE_SIZE_LIMIT = 2147483648
NoneType = type(None) NoneType = type(None)
@op_info_register("""{ @op_info_register("""{
"op_name": "CusMatMulCubeDenseLeft", "op_name": "CusMatMulCubeDenseLeft",
"imply_type": "TBE", "imply_type": "TBE",
@ -102,8 +95,7 @@ NoneType = type(None)
} }
] ]
}""") }""")
@util.check_input_type(dict, dict, (dict, NoneType), dict, bool, bool, str) @util.check_input_type(dict, dict, (dict, NoneType), dict, bool, bool, str)
def CusMatMulCubeDenseLeft(input_x1, input_x2, bias=None, output_y={}, trans_a=False, trans_b=False, kernel_name="matmulcube"): def CusMatMulCubeDenseLeft(input_x1, input_x2, bias=None, output_y={}, trans_a=False, trans_b=False,
kernel_name="matmulcube"):
return return

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
""" """
copyright 2019 Huawei Technologies Co., Ltd copyright 2020 Huawei Technologies Co., Ltd
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -19,12 +19,8 @@ matmul
""" """
from __future__ import absolute_import from __future__ import absolute_import
import te.platform.cce_params as cce
from te import tvm
from topi.cce import util
from te import tik
from mindspore.ops.op_info_register import op_info_register from mindspore.ops.op_info_register import op_info_register
from topi.cce import util
# General limitation of the size for input shape: 2**31 # General limitation of the size for input shape: 2**31
SHAPE_SIZE_LIMIT = 2147483648 SHAPE_SIZE_LIMIT = 2147483648
@ -99,7 +95,6 @@ NoneType = type(None)
} }
] ]
}""") }""")
# pylint: disable=locally-disabled,too-many-arguments, too-many-locals, too-many-statements # pylint: disable=locally-disabled,too-many-arguments, too-many-locals, too-many-statements
@util.check_input_type(dict, dict, (dict, NoneType), dict, bool, bool, str) @util.check_input_type(dict, dict, (dict, NoneType), dict, bool, bool, str)
def CusMatMulCubeFraczLeftCast(input_x1, input_x2, bias=None, output_y={}, trans_a=False, trans_b=False, def CusMatMulCubeFraczLeftCast(input_x1, input_x2, bias=None, output_y={}, trans_a=False, trans_b=False,

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
""" """
copyright 2019 Huawei Technologies Co., Ltd copyright 2020 Huawei Technologies Co., Ltd
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -19,15 +19,8 @@ matmul
""" """
from __future__ import absolute_import from __future__ import absolute_import
import te.lang.cce
import te.platform.cce_params as cce
from te.platform.fusion_manager import fusion_manager
from te import tvm
from topi import generic
from topi.cce import util
from te import tik
from impl.matmul_vector import matmul_vector_cce
from mindspore.ops.op_info_register import op_info_register from mindspore.ops.op_info_register import op_info_register
# General limitation of the size for input shape: 2**31 # General limitation of the size for input shape: 2**31
SHAPE_SIZE_LIMIT = 2147483648 SHAPE_SIZE_LIMIT = 2147483648
NoneType = type(None) NoneType = type(None)
@ -114,8 +107,6 @@ NoneType = type(None)
} }
] ]
}""") }""")
def CusMatMulCubeFraczRightMul(input_x1, input_x2, input_x3, bias=None, output_y={}, trans_a=False, trans_b=False,
def CusMatMulCubeFraczRightMul(input_x1, input_x2, input_x3, bias=None, output_y={}, trans_a=False, trans_b=False, kernel_name="matmulcube"): kernel_name="matmulcube"):
return return

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
""" """
copyright 2019 Huawei Technologies Co., Ltd copyright 2020 Huawei Technologies Co., Ltd
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -19,19 +19,14 @@ matmul
""" """
from __future__ import absolute_import from __future__ import absolute_import
import te.lang.cce
import te.platform.cce_params as cce
from te import tvm
from topi import generic
from topi.cce import util
from impl.matmul_vector import matmul_vector_cce
from mindspore.ops.op_info_register import op_info_register from mindspore.ops.op_info_register import op_info_register
from topi.cce import util
# General limitation of the size for input shape: 2**31 # General limitation of the size for input shape: 2**31
SHAPE_SIZE_LIMIT = 2147483648 SHAPE_SIZE_LIMIT = 2147483648
NoneType = type(None) NoneType = type(None)
@op_info_register("""{ @op_info_register("""{
"op_name": "CusMatMulCube", "op_name": "CusMatMulCube",
"imply_type": "TBE", "imply_type": "TBE",
@ -112,7 +107,6 @@ NoneType = type(None)
} }
] ]
}""") }""")
# pylint: disable=locally-disabled,too-many-arguments, too-many-locals, too-many-statements # pylint: disable=locally-disabled,too-many-arguments, too-many-locals, too-many-statements
@util.check_input_type(dict, dict, (dict, NoneType), dict, bool, bool, str) @util.check_input_type(dict, dict, (dict, NoneType), dict, bool, bool, str)
def CusMatMulCube(input_x1, input_x2, bias=None, output_y={}, trans_a=False, trans_b=False, kernel_name="matmulcube"): def CusMatMulCube(input_x1, input_x2, bias=None, output_y={}, trans_a=False, trans_b=False, kernel_name="matmulcube"):

@ -13,9 +13,9 @@
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
from te import tik
from topi.cce import util
from mindspore.ops.op_info_register import op_info_register from mindspore.ops.op_info_register import op_info_register
@op_info_register("""{ @op_info_register("""{
"op_name": "CusMatrixCombine", "op_name": "CusMatrixCombine",
"imply_type": "TBE", "imply_type": "TBE",
@ -58,7 +58,5 @@ from mindspore.ops.op_info_register import op_info_register
} }
] ]
}""") }""")
def CusMatrixCombine(input_x, output, kernel_name="matrix_combine"):
def CusMatrixCombine(input_x, output,kernel_name="matrix_combine"):
return return

@ -13,9 +13,9 @@
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
from te import tik
from topi.cce import util
from mindspore.ops.op_info_register import op_info_register from mindspore.ops.op_info_register import op_info_register
@op_info_register("""{ @op_info_register("""{
"op_name": "CusTranspose02314", "op_name": "CusTranspose02314",
"imply_type": "TBE", "imply_type": "TBE",
@ -58,6 +58,5 @@ from mindspore.ops.op_info_register import op_info_register
} }
] ]
}""") }""")
def CusTranspose02314(input_x, output, kernel_name="transpose021354"): def CusTranspose02314(input_x, output, kernel_name="transpose021354"):
return return

@ -16,11 +16,12 @@
create train or eval dataset. create train or eval dataset.
""" """
import os import os
import mindspore.common.dtype as mstype import mindspore.common.dtype as mstype
import mindspore.dataset.engine as de import mindspore.dataset.engine as de
import mindspore.dataset.transforms.vision.c_transforms as V_C
import mindspore.dataset.transforms.c_transforms as C2 import mindspore.dataset.transforms.c_transforms as C2
from config_imagenet import config import mindspore.dataset.transforms.vision.c_transforms as V_C
def create_dataset(dataset_path, do_train, repeat_num=1, batch_size=32): def create_dataset(dataset_path, do_train, repeat_num=1, batch_size=32):
""" """
@ -61,7 +62,7 @@ def create_dataset(dataset_path, do_train, repeat_num=1, batch_size=32):
V_C.Normalize(mean=mean, std=std), V_C.Normalize(mean=mean, std=std),
V_C.HWC2CHW() V_C.HWC2CHW()
] ]
#type_cast_op = C2.TypeCast(mstype.float16) # type_cast_op = C2.TypeCast(mstype.float16)
type_cast_op = C2.TypeCast(mstype.int32) type_cast_op = C2.TypeCast(mstype.int32)
ds = ds.map(input_columns="image", operations=transform_img, num_parallel_workers=8) ds = ds.map(input_columns="image", operations=transform_img, num_parallel_workers=8)

@ -13,14 +13,17 @@
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
"""learning rate generator""" """learning rate generator"""
import numpy as np
import math import math
import numpy as np
def linear_warmup_lr(current_step, warmup_steps, base_lr, init_lr): def linear_warmup_lr(current_step, warmup_steps, base_lr, init_lr):
lr_inc = (float(base_lr) - float(init_lr)) / float(warmup_steps) lr_inc = (float(base_lr) - float(init_lr)) / float(warmup_steps)
lr = float(init_lr) + lr_inc * current_step lr = float(init_lr) + lr_inc * current_step
return lr return lr
def cosine_annealing_lr(lr, steps_per_epoch, warmup_epochs, max_epoch, T_max, eta_min=0, num_periods=0.5): def cosine_annealing_lr(lr, steps_per_epoch, warmup_epochs, max_epoch, T_max, eta_min=0, num_periods=0.5):
base_lr = lr base_lr = lr
warmup_init_lr = 0 warmup_init_lr = 0
@ -39,6 +42,7 @@ def cosine_annealing_lr(lr, steps_per_epoch, warmup_epochs, max_epoch, T_max, et
lr_each_step.append(lr) lr_each_step.append(lr)
return np.array(lr_each_step).astype(np.float32) return np.array(lr_each_step).astype(np.float32)
def warmup_cosine_annealing_lr(lr, steps_per_epoch, warmup_epochs, max_epoch, T_max, eta_min=0, num_periods=0.5): def warmup_cosine_annealing_lr(lr, steps_per_epoch, warmup_epochs, max_epoch, T_max, eta_min=0, num_periods=0.5):
base_lr = lr base_lr = lr
warmup_init_lr = 0 warmup_init_lr = 0
@ -57,6 +61,7 @@ def warmup_cosine_annealing_lr(lr, steps_per_epoch, warmup_epochs, max_epoch, T_
lr_each_step.append(lr) lr_each_step.append(lr)
return np.array(lr_each_step).astype(np.float32) return np.array(lr_each_step).astype(np.float32)
def get_lr(global_step, lr_init, lr_end, lr_max, warmup_epochs, total_epochs, steps_per_epoch, lr_decay_mode): def get_lr(global_step, lr_init, lr_end, lr_max, warmup_epochs, total_epochs, steps_per_epoch, lr_decay_mode):
""" """
generate learning rate array generate learning rate array

@ -13,13 +13,13 @@
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
"""Dataset help for minddata dataset""" """Dataset help for minddata dataset"""
from mindspore._checkparam import check_bool
from mindspore import context from mindspore import context
from mindspore.train.parallel_utils import ParallelMode from mindspore._checkparam import check_bool
from mindspore.train._utils import _exec_datagraph, _get_types_and_shapes, _to_tensor, \
_construct_tensor_list, _to_full_shapes, _to_full_tensor
from mindspore.nn.wrap import GetNextSingleOp from mindspore.nn.wrap import GetNextSingleOp
from mindspore.parallel._utils import _get_device_num, _get_global_rank, _get_parallel_mode from mindspore.parallel._utils import _get_device_num, _get_global_rank, _get_parallel_mode
from mindspore.train._utils import _exec_datagraph, _get_types_and_shapes, _to_tensor, \
_construct_tensor_list, _to_full_shapes, _to_full_tensor
from mindspore.train.parallel_utils import ParallelMode
class DatasetHelper: class DatasetHelper:
@ -41,6 +41,7 @@ class DatasetHelper:
>>> for inputs in dataset_helper: >>> for inputs in dataset_helper:
>>> outputs = network(*inputs) >>> outputs = network(*inputs)
""" """
def __init__(self, dataset, first_order_iter=0, dataset_sink_mode=True): def __init__(self, dataset, first_order_iter=0, dataset_sink_mode=True):
check_bool(dataset_sink_mode) check_bool(dataset_sink_mode)
@ -70,6 +71,7 @@ class DatasetHelper:
class _DatasetIter: class _DatasetIter:
"""Base iter for dataset help""" """Base iter for dataset help"""
def __init__(self, dataset): def __init__(self, dataset):
self.loop_size = 1 self.loop_size = 1
if not hasattr(dataset, '__ME_INITED__'): if not hasattr(dataset, '__ME_INITED__'):
@ -107,25 +109,28 @@ class _DatasetIter:
loop_count = 1 loop_count = 1
if hasattr(dataset, '__loop_size__'): if hasattr(dataset, '__loop_size__'):
loop_size = dataset.__loop_size__ loop_size = dataset.__loop_size__
loop_count = int(dataset.get_dataset_size()/loop_size) loop_count = int(dataset.get_dataset_size() / loop_size)
return loop_count return loop_count
class _DatasetIterMSLoopSink(_DatasetIter): class _DatasetIterMSLoopSink(_DatasetIter):
"""Iter for context (enable_loop_sink=True)""" """Iter for context (enable_loop_sink=True)"""
def __init__(self, dataset, first_order_iter): def __init__(self, dataset, first_order_iter):
super(_DatasetIterMSLoopSink, self).__init__(dataset) super(_DatasetIterMSLoopSink, self).__init__(dataset)
# self.loop_count = self.get_loop_count(dataset) # self.loop_count = self.get_loop_count(dataset)
loop_size = dataset.__loop_size__ + first_order_iter loop_size = dataset.__loop_size__ + first_order_iter
self.loop_count = int(dataset.get_dataset_size()/loop_size) * 2 self.loop_count = int(dataset.get_dataset_size() / loop_size) * 2
def op(): def op():
return tuple() return tuple()
self.op = op self.op = op
class _DatasetIterMS(_DatasetIter): class _DatasetIterMS(_DatasetIter):
"""Iter for context (enable_loop_sink=False)""" """Iter for context (enable_loop_sink=False)"""
def __init__(self, dataset, first_order_order): def __init__(self, dataset, first_order_order):
super(_DatasetIterMS, self).__init__(dataset) super(_DatasetIterMS, self).__init__(dataset)
self.loop_count = dataset.get_dataset_size() self.loop_count = dataset.get_dataset_size()
@ -136,6 +141,7 @@ class _DatasetIterMS(_DatasetIter):
class _DatasetIterGE(_DatasetIter): class _DatasetIterGE(_DatasetIter):
"""Iter for ge""" """Iter for ge"""
def __init__(self, dataset): def __init__(self, dataset):
super(_DatasetIterGE, self).__init__(dataset) super(_DatasetIterGE, self).__init__(dataset)
self.loop_count = self.get_loop_count(dataset) self.loop_count = self.get_loop_count(dataset)
@ -148,11 +154,13 @@ class _DatasetIterGE(_DatasetIter):
def op(): def op():
return tensor_list_run return tensor_list_run
self.op = op self.op = op
class _DatasetIterFeed: class _DatasetIterFeed:
"""Iter for feed data""" """Iter for feed data"""
def __init__(self, dataset, first_order_order): def __init__(self, dataset, first_order_order):
self.dataset = dataset self.dataset = dataset
self.device_num = _get_device_num() self.device_num = _get_device_num()

@ -12,28 +12,30 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
from mindspore.nn.cell import Cell import mindspore.common.dtype as mstype
from mindspore.communication.management import GlobalComm, get_group_size from mindspore.communication.management import GlobalComm, get_group_size
from mindspore.nn.cell import Cell
from mindspore.ops import functional as F, composite as C, operations as P from mindspore.ops import functional as F, composite as C, operations as P
from mindspore.ops.operations.comm_ops import AllReduce, ReduceOp from mindspore.ops.operations.comm_ops import AllReduce, ReduceOp
import mindspore.common.dtype as mstype
from mindspore.communication import create_group
reduce_opt = C.MultitypeFuncGraph("reduce_opt") reduce_opt = C.MultitypeFuncGraph("reduce_opt")
_all_reduce_A = AllReduce() _all_reduce_A = AllReduce()
def _init_optimizer_allreduce(group): def _init_optimizer_allreduce(group):
global _all_reduce_A global _all_reduce_A
_all_reduce_A = AllReduce(ReduceOp.SUM, GlobalComm.WORLD_COMM_GROUP) _all_reduce_A = AllReduce(ReduceOp.SUM, GlobalComm.WORLD_COMM_GROUP)
_all_reduce_A.add_prim_attr('fusion', group) _all_reduce_A.add_prim_attr('fusion', group)
@reduce_opt.register("Function", "Number", "Tensor") @reduce_opt.register("Function", "Number", "Tensor")
def _tensors_allreduce_mean(mul, degree, grad): def _tensors_allreduce_mean(mul, degree, grad):
degree = F.scalar_cast(degree, F.dtype(grad)) degree = F.scalar_cast(degree, F.dtype(grad))
grad = _all_reduce_A(grad) grad = _all_reduce_A(grad)
cast_op = P.Cast() cast_op = P.Cast()
return mul(grad, cast_op(F.scalar_to_array(1.0/degree), F.dtype(grad))) return mul(grad, cast_op(F.scalar_to_array(1.0 / degree), F.dtype(grad)))
@reduce_opt.register("Bool", "Tensor") @reduce_opt.register("Bool", "Tensor")
def _tensors_allreduce(allreduce_filter, grad): def _tensors_allreduce(allreduce_filter, grad):
@ -41,8 +43,10 @@ def _tensors_allreduce(allreduce_filter, grad):
return _all_reduce_A(grad) return _all_reduce_A(grad)
return grad return grad
_get_datatype = C.MultitypeFuncGraph("_get_datatype") _get_datatype = C.MultitypeFuncGraph("_get_datatype")
@_get_datatype.register("Tensor") @_get_datatype.register("Tensor")
def _tensors_get_datatype(grad): def _tensors_get_datatype(grad):
""" """

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

Loading…
Cancel
Save