|
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
|
| 19 | +import warnings |
| 20 | +from packaging import version |
18 | 21 |
|
19 |
| - |
| 22 | +from sagemaker import image_uris |
| 23 | +import sagemaker.fw_utils as fw |
| 24 | +from sagemaker.pytorch import PyTorch |
| 25 | +from sagemaker.tensorflow import TensorFlow |
20 | 26 | from sagemaker.debugger.profiler_config import ProfilerConfig, FrameworkProfile
|
21 | 27 |
|
22 | 28 | from sagemaker.debugger.metrics_config import (
|
@@ -643,3 +649,162 @@ def test_validation():
|
643 | 649 |
|
644 | 650 | with pytest.raises(AssertionError, match=ErrorMessages.INVALID_CPROFILE_TIMER.value):
|
645 | 651 | PythonProfilingConfig(cprofile_timer="bad_cprofile_timer")
|
| 652 | + |
| 653 | + |
| 654 | +DATA_DIR = os.path.join(os.path.dirname(__file__), "..", "data") |
| 655 | +SCRIPT_PATH = os.path.join(DATA_DIR, "dummy_script.py") |
| 656 | +INSTANCE_COUNT = 1 |
| 657 | +INSTANCE_TYPE = "ml.p3.2xlarge" |
| 658 | +ROLE = "Dummy" |
| 659 | +REGION = "us-west-2" |
| 660 | + |
| 661 | + |
| 662 | +def _check_framework_profile_deprecation_warning(framework_version, framework_name, warn_list): |
| 663 | + """Check the collected warnings for a framework fromfile DeprecationWarning""" |
| 664 | + |
| 665 | + thresh = version.parse("2.12") if framework_name == "tensorflow" else version.parse("2.0") |
| 666 | + actual = version.parse(framework_version) |
| 667 | + |
| 668 | + if actual >= thresh: |
| 669 | + # should find a Framework profiling deprecation warning |
| 670 | + for w in warn_list: |
| 671 | + if issubclass(w.category, DeprecationWarning): |
| 672 | + if "Framework profiling" in str(w.message): |
| 673 | + return |
| 674 | + assert 0 # Should have found a deprecation and exited above |
| 675 | + |
| 676 | + |
| 677 | +def test_create_pytorch_estimator_with_framework_profile( |
| 678 | + sagemaker_session, |
| 679 | + pytorch_inference_version, |
| 680 | + pytorch_inference_py_version, |
| 681 | + default_framework_profile, |
| 682 | +): |
| 683 | + profiler_config = ProfilerConfig(framework_profile_params=default_framework_profile) |
| 684 | + |
| 685 | + with warnings.catch_warnings(record=True) as warn_list: |
| 686 | + warnings.simplefilter("always") |
| 687 | + framework_version = pytorch_inference_version |
| 688 | + pytorch = PyTorch( |
| 689 | + entry_point=SCRIPT_PATH, |
| 690 | + framework_version=framework_version, |
| 691 | + py_version=pytorch_inference_py_version, |
| 692 | + role=ROLE, |
| 693 | + sagemaker_session=sagemaker_session, |
| 694 | + instance_count=INSTANCE_COUNT, |
| 695 | + instance_type=INSTANCE_TYPE, |
| 696 | + base_job_name="job", |
| 697 | + profiler_config=profiler_config, |
| 698 | + ) |
| 699 | + |
| 700 | + _check_framework_profile_deprecation_warning( |
| 701 | + framework_version, pytorch._framework_name, warn_list |
| 702 | + ) |
| 703 | + |
| 704 | + |
| 705 | +def test_create_pytorch_estimator_w_image_with_framework_profile( |
| 706 | + sagemaker_session, |
| 707 | + pytorch_inference_version, |
| 708 | + pytorch_inference_py_version, |
| 709 | + gpu_pytorch_instance_type, |
| 710 | + default_framework_profile, |
| 711 | +): |
| 712 | + image_uri = image_uris.retrieve( |
| 713 | + "pytorch", |
| 714 | + REGION, |
| 715 | + version=pytorch_inference_version, |
| 716 | + py_version=pytorch_inference_py_version, |
| 717 | + instance_type=gpu_pytorch_instance_type, |
| 718 | + image_scope="inference", |
| 719 | + ) |
| 720 | + |
| 721 | + profiler_config = ProfilerConfig(framework_profile_params=default_framework_profile) |
| 722 | + |
| 723 | + with warnings.catch_warnings(record=True) as warn_list: |
| 724 | + warnings.simplefilter("always") |
| 725 | + pytorch = PyTorch( |
| 726 | + entry_point=SCRIPT_PATH, |
| 727 | + role=ROLE, |
| 728 | + sagemaker_session=sagemaker_session, |
| 729 | + instance_count=INSTANCE_COUNT, |
| 730 | + instance_type=gpu_pytorch_instance_type, |
| 731 | + image_uri=image_uri, |
| 732 | + profiler_config=profiler_config, |
| 733 | + ) |
| 734 | + |
| 735 | + framework_version = None |
| 736 | + _, _, image_tag, _ = fw.framework_name_from_image(image_uri) |
| 737 | + |
| 738 | + if image_tag is not None: |
| 739 | + framework_version = fw.framework_version_from_tag(image_tag) |
| 740 | + |
| 741 | + if framework_version is not None: |
| 742 | + _check_framework_profile_deprecation_warning( |
| 743 | + framework_version, pytorch._framework_name, warn_list |
| 744 | + ) |
| 745 | + |
| 746 | + |
| 747 | +def test_create_tf_estimator_with_framework_profile_212( |
| 748 | + sagemaker_session, |
| 749 | + default_framework_profile, |
| 750 | +): |
| 751 | + profiler_config = ProfilerConfig(framework_profile_params=default_framework_profile) |
| 752 | + |
| 753 | + with warnings.catch_warnings(record=True) as warn_list: |
| 754 | + warnings.simplefilter("always") |
| 755 | + framework_version = "2.12" |
| 756 | + tf = TensorFlow( |
| 757 | + entry_point=SCRIPT_PATH, |
| 758 | + role=ROLE, |
| 759 | + framework_version=framework_version, |
| 760 | + py_version="py39", |
| 761 | + sagemaker_session=sagemaker_session, |
| 762 | + instance_count=INSTANCE_COUNT, |
| 763 | + instance_type=INSTANCE_TYPE, |
| 764 | + profiler_config=profiler_config, |
| 765 | + ) |
| 766 | + |
| 767 | + _check_framework_profile_deprecation_warning( |
| 768 | + framework_version, tf._framework_name, warn_list |
| 769 | + ) |
| 770 | + |
| 771 | + |
| 772 | +def test_create_tf_estimator_w_image_with_framework_profile( |
| 773 | + sagemaker_session, |
| 774 | + tensorflow_inference_version, |
| 775 | + tensorflow_inference_py_version, |
| 776 | + default_framework_profile, |
| 777 | +): |
| 778 | + image_uri = image_uris.retrieve( |
| 779 | + "tensorflow", |
| 780 | + REGION, |
| 781 | + version=tensorflow_inference_version, |
| 782 | + py_version=tensorflow_inference_py_version, |
| 783 | + instance_type=INSTANCE_TYPE, |
| 784 | + image_scope="inference", |
| 785 | + ) |
| 786 | + |
| 787 | + profiler_config = ProfilerConfig(framework_profile_params=default_framework_profile) |
| 788 | + |
| 789 | + with warnings.catch_warnings(record=True) as warn_list: |
| 790 | + warnings.simplefilter("always") |
| 791 | + tf = TensorFlow( |
| 792 | + entry_point=SCRIPT_PATH, |
| 793 | + role=ROLE, |
| 794 | + sagemaker_session=sagemaker_session, |
| 795 | + instance_count=INSTANCE_COUNT, |
| 796 | + instance_type=INSTANCE_TYPE, |
| 797 | + image_uri=image_uri, |
| 798 | + profiler_config=profiler_config, |
| 799 | + ) |
| 800 | + |
| 801 | + framework_version = None |
| 802 | + _, _, image_tag, _ = fw.framework_name_from_image(image_uri) |
| 803 | + |
| 804 | + if image_tag is not None: |
| 805 | + framework_version = fw.framework_version_from_tag(image_tag) |
| 806 | + |
| 807 | + if framework_version is not None: |
| 808 | + _check_framework_profile_deprecation_warning( |
| 809 | + framework_version, tf._framework_name, warn_list |
| 810 | + ) |
0 commit comments