parent
bd845dd0b7
commit
14fe72f383
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,26 +1,26 @@
|
|||||||
# Copyright 2020 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.
|
||||||
# You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# 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 os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.level0
|
@pytest.mark.level0
|
||||||
@pytest.mark.platform_x86_ascend_training
|
@pytest.mark.platform_x86_ascend_training
|
||||||
@pytest.mark.platform_arm_ascend_training
|
@pytest.mark.platform_arm_ascend_training
|
||||||
@pytest.mark.env_single
|
@pytest.mark.env_single
|
||||||
def test_expand_loss():
|
def test_expand_loss():
|
||||||
sh_path = os.path.split(os.path.realpath(__file__))[0]
|
sh_path = os.path.split(os.path.realpath(__file__))[0]
|
||||||
ret = os.system(f"sh {sh_path}/run_auto_parallel_loss_expand.sh")
|
ret = os.system(f"sh {sh_path}/run_auto_parallel_loss_expand.sh")
|
||||||
assert (ret == 0)
|
assert ret == 0
|
||||||
|
@ -1,22 +1,21 @@
|
|||||||
# Copyright 2020 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.
|
||||||
# You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# 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 os
|
import os
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
def test_expand_loss():
|
||||||
def test_expand_loss():
|
ret = os.system("sh run_onehot_model_parallel.sh")
|
||||||
ret = os.system("sh run_onehot_model_parallel.sh")
|
assert ret == 0
|
||||||
assert (ret == 0)
|
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
# Copyright 2020 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.
|
||||||
# You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# 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 sys
|
import sys
|
||||||
|
|
||||||
sys.path.append("../../..")
|
sys.path.append("../../..")
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,120 +1,120 @@
|
|||||||
# Copyright 2019 Huawei Technologies Co., Ltd
|
# Copyright 2019 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.
|
||||||
# You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# 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
|
import os
|
||||||
import os
|
import numpy as np
|
||||||
|
|
||||||
import mindspore as ms
|
import mindspore as ms
|
||||||
import mindspore.communication.management as distributedTool
|
import mindspore.communication.management as distributedTool
|
||||||
from mindspore import context
|
from mindspore import context
|
||||||
from mindspore.common.tensor import Tensor
|
from mindspore.common.tensor import Tensor
|
||||||
from mindspore.nn import Cell
|
from mindspore.nn import Cell
|
||||||
from mindspore.nn import Dropout
|
from mindspore.nn import Dropout
|
||||||
|
|
||||||
device_num = 4
|
device_num = 4
|
||||||
device_id = int(os.environ["RANK_ID"])
|
device_id = int(os.environ["RANK_ID"])
|
||||||
path = "./output/"
|
path = "./output/"
|
||||||
|
|
||||||
|
|
||||||
def setup_module():
|
def setup_module():
|
||||||
print("~~~~~~~~~~~set up~~~~~~~~~~~~~")
|
print("~~~~~~~~~~~set up~~~~~~~~~~~~~")
|
||||||
context.set_context(mode=context.GRAPH_MODE)
|
context.set_context(mode=context.GRAPH_MODE)
|
||||||
context.set_auto_parallel_context(device_num=device_num, global_rank=device_id)
|
context.set_auto_parallel_context(device_num=device_num, global_rank=device_id)
|
||||||
distributedTool.init()
|
distributedTool.init()
|
||||||
distributedTool.create_group("0-3", [0, 1, 2, 3])
|
distributedTool.create_group("0-3", [0, 1, 2, 3])
|
||||||
print("~~~~~~~~~~~set up finished~~~~~~~~~~~~~")
|
print("~~~~~~~~~~~set up finished~~~~~~~~~~~~~")
|
||||||
|
|
||||||
|
|
||||||
def teardown_module():
|
def teardown_module():
|
||||||
print("~~~~~~~~~~~~tear down~~~~~~~~~~")
|
print("~~~~~~~~~~~~tear down~~~~~~~~~~")
|
||||||
|
|
||||||
|
|
||||||
class Net(Cell):
|
class Net(Cell):
|
||||||
def __init__(self, keep_prob, seed0, seed1, strategy=None):
|
def __init__(self, keep_prob, seed0, seed1, strategy=None):
|
||||||
super(Net, self).__init__()
|
super(Net, self).__init__()
|
||||||
self.drop = Dropout(keep_prob, seed0, seed1, dtype=ms.float32, strategy=strategy)
|
self.drop = Dropout(keep_prob, seed0, seed1, dtype=ms.float32, strategy=strategy)
|
||||||
|
|
||||||
def construct(self, input):
|
def construct(self, input_):
|
||||||
x = self.drop(input)
|
x = self.drop(input_)
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=comparison-with-itself
|
# pylint: disable=comparison-with-itself
|
||||||
class DropoutFactory:
|
class DropoutFactory:
|
||||||
def __init__(self, input_shape, keep_prob, seed0, seed1, strategy0=None):
|
def __init__(self, input_shape, keep_prob, seed0, seed1, strategy0=None):
|
||||||
size = 1
|
size = 1
|
||||||
prefix = ""
|
prefix = ""
|
||||||
for s in input_shape:
|
for s in input_shape:
|
||||||
prefix = prefix + str(s)
|
prefix = prefix + str(s)
|
||||||
size = size * s
|
size = size * s
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
number_range = min(10, size)
|
number_range = min(10, size)
|
||||||
self.input_np = np.reshape(np.arange(0, size) % number_range, input_shape).astype(np.float32)
|
self.input_np = np.reshape(np.arange(0, size) % number_range, input_shape).astype(np.float32)
|
||||||
self.keep_prob = keep_prob
|
self.keep_prob = keep_prob
|
||||||
self.seed0 = seed0
|
self.seed0 = seed0
|
||||||
self.seed1 = seed1
|
self.seed1 = seed1
|
||||||
self.strategy0 = strategy0
|
self.strategy0 = strategy0
|
||||||
need_dev_num = 1
|
need_dev_num = 1
|
||||||
for s in strategy0[1]:
|
for s in strategy0[1]:
|
||||||
need_dev_num = need_dev_num * s
|
need_dev_num = need_dev_num * s
|
||||||
self.x_id = device_id % need_dev_num
|
self.x_id = device_id % need_dev_num
|
||||||
self.out_id = device_id % need_dev_num
|
self.out_id = device_id % need_dev_num
|
||||||
|
|
||||||
def get_parallel_blocks(self, input_, strategy):
|
def get_parallel_blocks(self, input_, strategy):
|
||||||
blocks = [input_]
|
blocks = [input_]
|
||||||
i = 0
|
i = 0
|
||||||
for stra in strategy:
|
for stra in strategy:
|
||||||
temp = []
|
temp = []
|
||||||
while len(blocks) > 0:
|
while len(blocks) > 0:
|
||||||
block = blocks.pop(0)
|
block = blocks.pop(0)
|
||||||
temp.extend(np.split(block, stra, axis=i))
|
temp.extend(np.split(block, stra, axis=i))
|
||||||
blocks.extend(temp)
|
blocks.extend(temp)
|
||||||
i += 1
|
i += 1
|
||||||
return blocks
|
return blocks
|
||||||
|
|
||||||
def d4_tensor_compare(self, input, out_me):
|
def d4_tensor_compare(self, input_, out_me):
|
||||||
[a, b, c, d] = input.shape
|
[a, b, c, d] = input_.shape
|
||||||
for i in range(a):
|
for i in range(a):
|
||||||
for j in range(b):
|
for j in range(b):
|
||||||
for k in range(c):
|
for k in range(c):
|
||||||
for e in range(d):
|
for e in range(d):
|
||||||
if out_me[i, j, k, e] == 0:
|
if out_me[i, j, k, e] == 0:
|
||||||
assert True == True
|
assert True
|
||||||
else:
|
else:
|
||||||
assert np.allclose(out_me[i, j, k, e], input[i, j, k, e] * (1 / 0.4), 0.0001, 0.0001)
|
assert np.allclose(out_me[i, j, k, e], input_[i, j, k, e] * (1 / 0.4), 0.0001, 0.0001)
|
||||||
|
|
||||||
def forward_mindspore_parallel_impl(self):
|
def forward_mindspore_parallel_impl(self):
|
||||||
x = Tensor(self.input_np)
|
x = Tensor(self.input_np)
|
||||||
inputs_x = self.get_parallel_blocks(self.input_np, self.strategy0[1])
|
inputs_x = self.get_parallel_blocks(self.input_np, self.strategy0[1])
|
||||||
x1 = Tensor(inputs_x[self.x_id])
|
x1 = Tensor(inputs_x[self.x_id])
|
||||||
net = Net(0.4, 0, 0, strategy=self.strategy0)
|
net = Net(0.4, 0, 0, strategy=self.strategy0)
|
||||||
context.set_auto_parallel_context(parallel_mode="semi_auto_parallel")
|
context.set_auto_parallel_context(parallel_mode="semi_auto_parallel")
|
||||||
net.set_auto_parallel()
|
net.set_auto_parallel()
|
||||||
out = net(x, parallel_inputs_compile=[x], parallel_inputs_run=[x1])
|
out = net(x, parallel_inputs_compile=[x], parallel_inputs_run=[x1])
|
||||||
return out.asnumpy()
|
return out.asnumpy()
|
||||||
|
|
||||||
def forward_cmp(self):
|
def forward_cmp(self):
|
||||||
out_mindspore_parallel = self.forward_mindspore_parallel_impl()
|
out_mindspore_parallel = self.forward_mindspore_parallel_impl()
|
||||||
input_blocks = self.get_parallel_blocks(self.input_np, self.strategy0[1])
|
input_blocks = self.get_parallel_blocks(self.input_np, self.strategy0[1])
|
||||||
self.d4_tensor_compare(input_blocks[self.out_id], out_mindspore_parallel)
|
self.d4_tensor_compare(input_blocks[self.out_id], out_mindspore_parallel)
|
||||||
|
|
||||||
|
|
||||||
def test_reid_dropout_forward_seed_F32_64_512_8_8():
|
def test_reid_dropout_forward_seed_F32_64_512_8_8():
|
||||||
fact = DropoutFactory(input_shape=(64, 512, 8, 8), keep_prob=0.4, seed0=0, seed1=0, strategy0=(0, (4, 1, 1, 1)))
|
fact = DropoutFactory(input_shape=(64, 512, 8, 8), keep_prob=0.4, seed0=0, seed1=0, strategy0=(0, (4, 1, 1, 1)))
|
||||||
fact.forward_cmp()
|
fact.forward_cmp()
|
||||||
|
|
||||||
|
|
||||||
def test_reid_dropout_forward_seed_F32_64_512_8_8_repeat():
|
def test_reid_dropout_forward_seed_F32_64_512_8_8_repeat():
|
||||||
fact = DropoutFactory(input_shape=(64, 512, 8, 8), keep_prob=0.4, seed0=0, seed1=0, strategy0=(0, (2, 1, 1, 1)))
|
fact = DropoutFactory(input_shape=(64, 512, 8, 8), keep_prob=0.4, seed0=0, seed1=0, strategy0=(0, (2, 1, 1, 1)))
|
||||||
fact.forward_cmp()
|
fact.forward_cmp()
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue