|
16 | 16 | import os
|
17 | 17 |
|
18 | 18 | from sagemaker.sklearn import SKLearn
|
| 19 | +from sagemaker.local import LocalSession |
| 20 | + |
19 | 21 | import sagemaker
|
20 | 22 | import boto3
|
21 | 23 | from sklearn import datasets
|
|
27 | 29 | if local_mode:
|
28 | 30 | instance_type = "local"
|
29 | 31 | IAM_ROLE = 'arn:aws:iam::111111111111:role/service-role/AmazonSageMaker-ExecutionRole-20200101T000001'
|
| 32 | + sess = LocalSession() |
| 33 | + sess.config = {'local': {'local_code': True}} # Ensure full code locality, see: https://sagemaker.readthedocs.io/en/stable/overview.html#local-mode |
30 | 34 | else:
|
31 | 35 | instance_type = "ml.m5.xlarge"
|
32 | 36 | IAM_ROLE = 'arn:aws:iam::<ACCOUNT>:role/service-role/AmazonSageMaker-ExecutionRole-XXX'
|
| 37 | + sess = sagemaker.Session() |
| 38 | + bucket = sess.default_bucket() # Set a default S3 bucket |
33 | 39 |
|
34 |
| -sess = sagemaker.Session() |
35 |
| -bucket = sess.default_bucket() # Set a default S3 bucket |
36 | 40 | prefix = 'DEMO-local-and-managed-infrastructure'
|
37 | 41 |
|
38 | 42 | def download_training_and_eval_data():
|
@@ -74,7 +78,8 @@ def main():
|
74 | 78 | sklearn = SKLearn(
|
75 | 79 | entry_point="scikit_learn_california.py",
|
76 | 80 | source_dir='code',
|
77 |
| - framework_version="1.0-1", |
| 81 | + framework_version="1.2-1", |
| 82 | + sagemaker_session=sess, |
78 | 83 | instance_type=instance_type,
|
79 | 84 | role=IAM_ROLE,
|
80 | 85 | hyperparameters={"max_leaf_nodes": 30},
|
@@ -105,7 +110,7 @@ def main():
|
105 | 110 | do_inference_on_local_endpoint(predictor)
|
106 | 111 |
|
107 | 112 | print('About to delete the endpoint to stop paying (if in cloud mode).')
|
108 |
| - predictor.delete_endpoint(predictor.endpoint_name) |
| 113 | + predictor.delete_endpoint() |
109 | 114 |
|
110 | 115 |
|
111 | 116 | if __name__ == "__main__":
|
|
0 commit comments