Skip to content

Commit

Permalink
feat: add device_target config and set default to Ascend.
Browse files Browse the repository at this point in the history
  • Loading branch information
IASZHT committed Jul 25, 2024
1 parent 6e2a4c7 commit 614507b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def create_parser():
help='Interval for print training log. Unit: step (default=100)')
group.add_argument('--seed', type=int, default=42,
help='Seed value for determining randomness in numpy, random, and mindspore (default=42)')
group.add_argument('--device_target', type=str, default='Ascend',
help='Device target for validating, which can be Ascend, GPU or CPU. (default=Ascend)')

# Dataset parameters
group = parser.add_argument_group('Dataset parameters')
Expand Down Expand Up @@ -94,7 +96,7 @@ def create_parser():
'Example: "randaug-m10-n2-w0-mstd0.5-mmax10-inc0", "autoaug-mstd0.5" or autoaugr-mstd0.5.')
group.add_argument('--aug_splits', type=int, default=0,
help='Number of augmentation splits (default: 0, valid: 3 (currently, only support 3 splits))'
'it should be set with one auto_augment')
'it should be set with one auto_augment')
group.add_argument('--re_prob', type=float, default=0.0,
help='Probability of performing erasing (default=0.0)')
group.add_argument('--re_scale', type=tuple, default=(0.02, 0.33),
Expand Down Expand Up @@ -267,6 +269,8 @@ def create_parser():
help='Whether to shuffle the evaluation data (default=False)')

return parser_config, parser


# fmt: on


Expand Down
7 changes: 7 additions & 0 deletions validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def check_batch_size(num_samples, ori_batch_size=32, refine=True):


def validate(args):
try:
ms.set_context(device_target=args.device_target)
except Exception as e:
print(e, "Please check whether the Ascend environment is installed and configured correctly. \
Now the process will use the CPU to perform calculations.")
ms.set_context(device_target="CPU")

ms.set_context(mode=args.mode)
if args.mode == ms.GRAPH_MODE:
ms.set_context(jit_config={"jit_level": "O2"})
Expand Down

0 comments on commit 614507b

Please sign in to comment.