This repository was archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
[v1.x] Add more CV models to onnxruntime inference test, add bert model test. #19697
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b7b88e
Add more CV models to onnxruntime inference test, add bert model test.
0be9b3d
Remove print.
a5fac09
Install gluonnlp in onnx environment.
1034556
Wrap tests in try/finally block, convert PosixPath to str.
bc8d003
Add pytest-compatible with_seed() from master branch, decorate functi…
61887e4
Assert both outputs are accurate.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you 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. | ||
|
|
||
| import functools | ||
| import logging | ||
| import os | ||
| import random | ||
|
|
||
| import mxnet as mx | ||
| import numpy as np | ||
|
|
||
|
|
||
| def with_seed(seed=None): | ||
| """ | ||
| A decorator for test functions that manages rng seeds. | ||
|
|
||
| Parameters | ||
| ---------- | ||
|
|
||
| seed : the seed to pass to np.random and mx.random | ||
|
|
||
|
|
||
| This tests decorator sets the np, mx and python random seeds identically | ||
| prior to each test, then outputs those seeds if the test fails or | ||
| if the test requires a fixed seed (as a reminder to make the test | ||
| more robust against random data). | ||
|
|
||
| @with_seed() | ||
| def test_ok_with_random_data(): | ||
| ... | ||
|
|
||
| @with_seed(1234) | ||
| def test_not_ok_with_random_data(): | ||
| ... | ||
|
|
||
| Use of the @with_seed() decorator for all tests creates | ||
| tests isolation and reproducability of failures. When a | ||
| test fails, the decorator outputs the seed used. The user | ||
| can then set the environment variable MXNET_TEST_SEED to | ||
| the value reported, then rerun the test with: | ||
|
|
||
| pytest --verbose --capture=no <test_module_name.py>::<failing_test> | ||
|
|
||
| To run a test repeatedly, set MXNET_TEST_COUNT=<NNN> in the environment. | ||
| To see the seeds of even the passing tests, add '--log-level=DEBUG' to pytest. | ||
| """ | ||
| def test_helper(orig_test): | ||
| @functools.wraps(orig_test) | ||
| def test_new(*args, **kwargs): | ||
| test_count = int(os.getenv('MXNET_TEST_COUNT', '1')) | ||
| env_seed_str = os.getenv('MXNET_TEST_SEED') | ||
| for i in range(test_count): | ||
| if seed is not None: | ||
| this_test_seed = seed | ||
| log_level = logging.INFO | ||
| elif env_seed_str is not None: | ||
| this_test_seed = int(env_seed_str) | ||
| log_level = logging.INFO | ||
| else: | ||
| this_test_seed = np.random.randint(0, np.iinfo(np.int32).max) | ||
| log_level = logging.DEBUG | ||
| post_test_state = np.random.get_state() | ||
| np.random.seed(this_test_seed) | ||
| mx.random.seed(this_test_seed) | ||
| random.seed(this_test_seed) | ||
| # 'pytest --logging-level=DEBUG' shows this msg even with an ensuing core dump. | ||
| test_count_msg = '{} of {}: '.format(i+1,test_count) if test_count > 1 else '' | ||
| pre_test_msg = ('{}Setting test np/mx/python random seeds, use MXNET_TEST_SEED={}' | ||
| ' to reproduce.').format(test_count_msg, this_test_seed) | ||
| on_err_test_msg = ('{}Error seen with seeded test, use MXNET_TEST_SEED={}' | ||
| ' to reproduce.').format(test_count_msg, this_test_seed) | ||
| logging.log(log_level, pre_test_msg) | ||
| try: | ||
| orig_test(*args, **kwargs) | ||
| except: | ||
| # With exceptions, repeat test_msg at WARNING level to be sure it's seen. | ||
| if log_level < logging.WARNING: | ||
| logging.warning(on_err_test_msg) | ||
| raise | ||
| finally: | ||
| # Provide test-isolation for any test having this decorator | ||
| mx.nd.waitall() | ||
| np.random.set_state(post_test_state) | ||
| return test_new | ||
| return test_helper | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.