|
12 | 12 | # language governing permissions and limitations under the License.
|
13 | 13 | from __future__ import absolute_import
|
14 | 14 |
|
| 15 | +import os |
15 | 16 | import pytest
|
16 | 17 | import re
|
17 | 18 | import time
|
18 | 19 |
|
19 |
| - |
| 20 | +from sagemaker import image_uris |
| 21 | +from sagemaker.pytorch import PyTorch |
| 22 | +from sagemaker.tensorflow import TensorFlow |
20 | 23 | from sagemaker.debugger.profiler_config import ProfilerConfig, FrameworkProfile
|
21 | 24 |
|
22 | 25 | from sagemaker.debugger.metrics_config import (
|
@@ -643,3 +646,119 @@ def test_validation():
|
643 | 646 |
|
644 | 647 | with pytest.raises(AssertionError, match=ErrorMessages.INVALID_CPROFILE_TIMER.value):
|
645 | 648 | PythonProfilingConfig(cprofile_timer="bad_cprofile_timer")
|
| 649 | + |
| 650 | + |
| 651 | +DATA_DIR = os.path.join(os.path.dirname(__file__), "..", "data") |
| 652 | +SCRIPT_PATH = os.path.join(DATA_DIR, "dummy_script.py") |
| 653 | +INSTANCE_COUNT = 1 |
| 654 | +INSTANCE_TYPE = "ml.p3.2xlarge" |
| 655 | +ROLE = "Dummy" |
| 656 | +REGION = "us-west-2" |
| 657 | + |
| 658 | + |
| 659 | +def test_create_pytorch_estimator_with_framework_profile( |
| 660 | + sagemaker_session, |
| 661 | + pytorch_inference_version, |
| 662 | + pytorch_inference_py_version, |
| 663 | + default_framework_profile, |
| 664 | +): |
| 665 | + profiler_config = ProfilerConfig(framework_profile_params=default_framework_profile) |
| 666 | + |
| 667 | + container_log_level = '"logging.INFO"' |
| 668 | + source_dir = "s3://mybucket/source" |
| 669 | + pytorch = PyTorch( |
| 670 | + entry_point=SCRIPT_PATH, |
| 671 | + framework_version=pytorch_inference_version, |
| 672 | + py_version=pytorch_inference_py_version, |
| 673 | + role=ROLE, |
| 674 | + sagemaker_session=sagemaker_session, |
| 675 | + instance_count=INSTANCE_COUNT, |
| 676 | + instance_type=INSTANCE_TYPE, |
| 677 | + base_job_name="job", |
| 678 | + profiler_config=profiler_config, |
| 679 | + ) |
| 680 | + |
| 681 | + |
| 682 | +def test_create_pytorch_estimator_w_image_with_framework_profile( |
| 683 | + sagemaker_session, |
| 684 | + pytorch_inference_version, |
| 685 | + pytorch_inference_py_version, |
| 686 | + gpu_pytorch_instance_type, |
| 687 | + default_framework_profile, |
| 688 | +): |
| 689 | + image_uri = image_uris.retrieve( |
| 690 | + "pytorch", |
| 691 | + REGION, |
| 692 | + version=pytorch_inference_version, |
| 693 | + py_version=pytorch_inference_py_version, |
| 694 | + instance_type=gpu_pytorch_instance_type, |
| 695 | + image_scope="inference", |
| 696 | + ) |
| 697 | + |
| 698 | + profiler_config = ProfilerConfig(framework_profile_params=default_framework_profile) |
| 699 | + |
| 700 | + pytorch = PyTorch( |
| 701 | + entry_point=SCRIPT_PATH, |
| 702 | + role=ROLE, |
| 703 | + sagemaker_session=sagemaker_session, |
| 704 | + instance_count=INSTANCE_COUNT, |
| 705 | + instance_type=gpu_pytorch_instance_type, |
| 706 | + image_uri=image_uri, |
| 707 | + profiler_config=profiler_config, |
| 708 | + ) |
| 709 | + |
| 710 | + |
| 711 | +""" |
| 712 | +def test_create_tf_estimator_with_framework_profile( |
| 713 | + sagemaker_session, |
| 714 | + tensorflow_inference_version, |
| 715 | + tensorflow_inference_py_version, |
| 716 | + default_framework_profile, |
| 717 | +): |
| 718 | + profiler_config = ProfilerConfig(framework_profile_params=default_framework_profile) |
| 719 | +
|
| 720 | + tf = TensorFlow( |
| 721 | + entry_point=SCRIPT_PATH, |
| 722 | + role=ROLE, |
| 723 | + framework_version=tensorflow_inference_version, |
| 724 | + py_version=tensorflow_inference_py_version, |
| 725 | + sagemaker_session=sagemaker_session, |
| 726 | + instance_count=INSTANCE_COUNT, |
| 727 | + instance_type=INSTANCE_TYPE, |
| 728 | + profiler_config=profiler_config, |
| 729 | + ) |
| 730 | +... ValueError: TF 1.5 supports only legacy mode. |
| 731 | +Please supply the image URI directly with |
| 732 | +'image_uri=520713654638.dkr.ecr.us-west-2.amazonaws.com/sagemaker-tensorflow:1.5-cpu-py2' |
| 733 | + and set 'model_dir=False' etc etc |
| 734 | +""" |
| 735 | + |
| 736 | + |
| 737 | +def test_create_tf_estimator_w_image_with_framework_profile( |
| 738 | + sagemaker_session, |
| 739 | + tensorflow_inference_version, |
| 740 | + tensorflow_inference_py_version, |
| 741 | + default_framework_profile, |
| 742 | +): |
| 743 | + image_uri = image_uris.retrieve( |
| 744 | + "tensorflow", |
| 745 | + REGION, |
| 746 | + version=tensorflow_inference_version, |
| 747 | + py_version=tensorflow_inference_py_version, |
| 748 | + instance_type=INSTANCE_TYPE, |
| 749 | + image_scope="inference", |
| 750 | + ) |
| 751 | + |
| 752 | + assert image_uri is not None |
| 753 | + |
| 754 | + profiler_config = ProfilerConfig(framework_profile_params=default_framework_profile) |
| 755 | + |
| 756 | + tf = TensorFlow( |
| 757 | + entry_point=SCRIPT_PATH, |
| 758 | + role=ROLE, |
| 759 | + sagemaker_session=sagemaker_session, |
| 760 | + instance_count=INSTANCE_COUNT, |
| 761 | + instance_type=INSTANCE_TYPE, |
| 762 | + image_uri=image_uri, |
| 763 | + profiler_config=profiler_config, |
| 764 | + ) |
0 commit comments