mindspore/tests/ut/python/dataset/test_noop_mode.py

61 lines
2.0 KiB
Python
Raw Normal View History

2022-06-03 09:24:09 +08:00
# Copyright 2020-2022 Huawei Technologies Co., Ltd
2020-07-13 15:06:41 +08:00
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""
Test No-op mode support with Dummy Iterator
"""
import os
import mindspore.dataset as ds
2020-09-27 17:38:22 +08:00
from mindspore import context
2020-07-13 15:06:41 +08:00
DATA_DIR = "../data/dataset/testVOC2012"
def test_noop_pserver():
2022-06-03 09:24:09 +08:00
"""
Feature: No-op mode
Description: Test No-op mode support where the MS_ROLE environment is MS_PSERVER
Expectation: Runs successfully
"""
2020-07-13 15:06:41 +08:00
os.environ['MS_ROLE'] = 'MS_PSERVER'
2020-09-27 17:38:22 +08:00
context.set_ps_context(enable_ps=True)
data1 = ds.VOCDataset(DATA_DIR, task="Segmentation", usage="train", shuffle=False, decode=True)
2020-07-13 15:06:41 +08:00
num = 0
for _ in data1.create_dict_iterator(num_epochs=1):
2020-07-13 15:06:41 +08:00
num += 1
2022-07-01 09:31:44 +08:00
assert num == 1
2020-07-13 15:06:41 +08:00
del os.environ['MS_ROLE']
2020-09-27 17:38:22 +08:00
context.set_ps_context(enable_ps=False)
2020-07-13 15:06:41 +08:00
def test_noop_sched():
2022-06-03 09:24:09 +08:00
"""
Feature: No-op mode
Description: Test No-op mode support where the MS_ROLE environment is MS_SCHED
Expectation: Runs successfully
"""
2020-07-13 15:06:41 +08:00
os.environ['MS_ROLE'] = 'MS_SCHED'
2020-09-27 17:38:22 +08:00
context.set_ps_context(enable_ps=True)
data1 = ds.VOCDataset(DATA_DIR, task="Segmentation", usage="train", shuffle=False, decode=True)
2020-07-13 15:06:41 +08:00
num = 0
for _ in data1.create_dict_iterator(num_epochs=1):
2020-07-13 15:06:41 +08:00
num += 1
2022-07-01 09:31:44 +08:00
assert num == 1
2020-07-13 15:06:41 +08:00
del os.environ['MS_ROLE']
2020-09-27 17:38:22 +08:00
context.set_ps_context(enable_ps=False)
2020-07-13 15:06:41 +08:00
if __name__ == '__main__':
test_noop_pserver()
test_noop_sched()