-
Notifications
You must be signed in to change notification settings - Fork 864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor sanity checks to use pytest #2221
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a066bf7
Remove wait time when stopping and starting torchserve in tests
mreso c558f95
Remove trailing white spaces
mreso e17d88f
Merge branch 'master' into integrate_sanity_tests_with_pytest
chauhang f72fc13
Merge branch 'master' into integrate_sanity_tests_with_pytest
chauhang 064eab6
Merge remote-tracking branch 'origin/master' into integrate_sanity_te…
mreso 15a9fd9
Merge branch 'master' into integrate_sanity_tests_with_pytest
chauhang 1da3429
Merge remote-tracking branch 'origin/master' into integrate_sanity_te…
mreso ee93b77
Skip sanity test folder in regression test
mreso bb81622
Merge branch 'master' into integrate_sanity_tests_with_pytest
mreso 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 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,27 @@ | ||
import json | ||
import sys | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
REPO_ROOT = Path(__file__).parents[3] | ||
|
||
|
||
MAR_CONFIG = REPO_ROOT.joinpath("ts_scripts", "mar_config.json") | ||
|
||
|
||
@pytest.fixture(name="gen_models", scope="module") | ||
def load_gen_models() -> dict: | ||
with open(MAR_CONFIG) as f: | ||
models = json.load(f) | ||
models = {m["model_name"]: m for m in models} | ||
return models | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def ts_scripts_path(): | ||
sys.path.append(REPO_ROOT.as_posix()) | ||
|
||
yield | ||
|
||
sys.path.pop() |
This file contains 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,54 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
import pytest | ||
import test_utils | ||
|
||
REPO_ROOT = Path(__file__).parents[3] | ||
SANITY_MODELS_CONFIG = REPO_ROOT.joinpath("ts_scripts", "configs", "sanity_models.json") | ||
|
||
|
||
def load_resnet18() -> dict: | ||
with open(SANITY_MODELS_CONFIG) as f: | ||
models = json.load(f) | ||
return list(filter(lambda x: x["name"] == "resnet-18", models))[0] | ||
|
||
|
||
@pytest.fixture(name="resnet18") | ||
def generate_resnet18(model_store, gen_models, ts_scripts_path): | ||
model = load_resnet18() | ||
|
||
from ts_scripts.marsgen import generate_model | ||
|
||
generate_model(gen_models[model["name"]], model_store) | ||
|
||
yield model | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def torchserve_with_snapshot(model_store): | ||
test_utils.torchserve_cleanup() | ||
|
||
test_utils.start_torchserve( | ||
model_store=model_store, no_config_snapshots=False, gen_mar=False | ||
) | ||
|
||
yield | ||
|
||
test_utils.torchserve_cleanup() | ||
|
||
|
||
def test_config_snapshotting( | ||
resnet18, model_store, torchserve_with_snapshot, ts_scripts_path | ||
): | ||
from ts_scripts.sanity_utils import run_rest_test | ||
|
||
run_rest_test(resnet18, unregister_model=False) | ||
|
||
test_utils.stop_torchserve() | ||
|
||
test_utils.start_torchserve( | ||
model_store=model_store, no_config_snapshots=False, gen_mar=False | ||
) | ||
|
||
run_rest_test(resnet18, register_model=False) |
This file contains 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,55 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
REPO_ROOT = Path(__file__).parents[3] | ||
SANITY_MODELS_CONFIG = REPO_ROOT.joinpath("ts_scripts", "configs", "sanity_models.json") | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def grpc_client_stubs(ts_scripts_path): | ||
from ts_scripts.shell_utils import rm_file | ||
from ts_scripts.tsutils import generate_grpc_client_stubs | ||
|
||
generate_grpc_client_stubs() | ||
|
||
yield | ||
|
||
rm_file(REPO_ROOT.joinpath("ts_scripts", "*_pb2*.py").as_posix(), True) | ||
|
||
|
||
def load_models() -> dict: | ||
with open(SANITY_MODELS_CONFIG) as f: | ||
models = json.load(f) | ||
return models | ||
|
||
|
||
@pytest.fixture(name="model", params=load_models(), scope="module") | ||
def models_to_validate(request, model_store, gen_models, ts_scripts_path): | ||
model = request.param | ||
|
||
if model["name"] in gen_models: | ||
from ts_scripts.marsgen import generate_model | ||
|
||
generate_model(gen_models[model["name"]], model_store) | ||
|
||
yield model | ||
|
||
|
||
def test_models_with_grpc(model, torchserve, ts_scripts_path, grpc_client_stubs): | ||
from ts_scripts.sanity_utils import run_grpc_test | ||
|
||
run_grpc_test(model) | ||
|
||
|
||
def test_models_with_rest(model, torchserve, ts_scripts_path): | ||
from ts_scripts.sanity_utils import run_rest_test | ||
|
||
run_rest_test(model) | ||
|
||
|
||
def test_gpu_setup(ts_scripts_path): | ||
from ts_scripts.sanity_utils import test_gpu_setup | ||
|
||
test_gpu_setup() |
This file contains 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 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess sanity test will fail without gRPC client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats call is now a fixture
serve/test/pytest/sanity/test_model_registering.py
Line 15 in 15a9fd9