-
Notifications
You must be signed in to change notification settings - Fork 33
/
test_environment.py
78 lines (59 loc) · 2.32 KB
/
test_environment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import logging
import subprocess
from datetime import timedelta
import boto3
import sagemaker
from sagemaker.pytorch import PyTorchProcessor
from sagemaker_ssh_helper.wrapper import SSHProcessorWrapper
# noinspection DuplicatedCode
def test_processing_different_region_clean():
boto3_session = boto3.session.Session(region_name='eu-west-2')
sagemaker_session = sagemaker.Session(boto_session=boto3_session)
torch_processor = PyTorchProcessor(
sagemaker_session=sagemaker_session,
base_job_name='pytorch-processing',
framework_version='1.9.1',
py_version='py38',
instance_count=1,
instance_type="ml.m5.xlarge",
max_runtime_in_seconds=int(timedelta(minutes=15).total_seconds()),
)
torch_processor.run(
source_dir="source_dir/processing/",
dependencies=[SSHProcessorWrapper.dependency_dir()],
code="process_framework.py",
logs=True,
wait=True
)
# noinspection DuplicatedCode
def test_processing_different_region_ssh():
boto3_session = boto3.session.Session(region_name='eu-west-2')
sagemaker_session = sagemaker.Session(boto_session=boto3_session)
torch_processor = PyTorchProcessor(
sagemaker_session=sagemaker_session,
base_job_name='ssh-pytorch-processing',
framework_version='1.9.1',
py_version='py38',
instance_count=1,
instance_type="ml.m5.xlarge",
max_runtime_in_seconds=int(timedelta(minutes=15).total_seconds())
)
wait_time = 3600
ssh_wrapper = SSHProcessorWrapper.create(torch_processor, connection_wait_time_seconds=wait_time)
torch_processor.run(
source_dir="source_dir/processing/",
dependencies=[SSHProcessorWrapper.dependency_dir()],
code="process_framework.py",
logs=True,
wait=False
)
ssh_wrapper.start_ssm_connection_and_continue(15022)
ssh_wrapper.wait_processing_job()
def test_caller_script():
from sagemaker_ssh_helper.env import get_caller_script_name
assert get_caller_script_name() == 'test_environment.py'
assert get_caller_script_name(2) == 'pytest_monitor.py'
def test_aws_config():
output = subprocess.check_output("aws configure list".split(" ")).decode("latin1")
logging.info(f"AWS config:\n{output}")
logging.info(sagemaker.Session().default_bucket())