|
12 | 12 | # language governing permissions and limitations under the License.
|
13 | 13 | from __future__ import absolute_import
|
14 | 14 |
|
| 15 | +import io |
15 | 16 | import json
|
16 | 17 | import os
|
17 | 18 |
|
| 19 | +import numpy as np |
| 20 | + |
18 | 21 | import pytest
|
| 22 | +import sagemaker.amazon.common as smac |
| 23 | + |
19 | 24 |
|
20 | 25 | import sagemaker
|
21 | 26 | from sagemaker import image_uris
|
22 | 27 | from sagemaker.estimator import Estimator
|
| 28 | +from sagemaker.s3 import S3Uploader |
23 | 29 | from sagemaker.serializers import SimpleBaseSerializer
|
24 | 30 | from sagemaker.utils import unique_name_from_base
|
25 | 31 | from tests.integ import DATA_DIR, TRAINING_DEFAULT_TIMEOUT_MINUTES, datasets
|
@@ -102,6 +108,61 @@ def test_byo_estimator(sagemaker_session, region, cpu_instance_type, training_se
|
102 | 108 | assert prediction["score"] is not None
|
103 | 109 |
|
104 | 110 |
|
| 111 | +def test_estimator_register_publish_training_details( |
| 112 | + sagemaker_session, region, cpu_instance_type, training_set |
| 113 | +): |
| 114 | + |
| 115 | + bucket = sagemaker_session.default_bucket() |
| 116 | + prefix = "model-card-sample-notebook" |
| 117 | + |
| 118 | + raw_data = ( |
| 119 | + (0.5, 0), |
| 120 | + (0.75, 0), |
| 121 | + (1.0, 0), |
| 122 | + (1.25, 0), |
| 123 | + (1.50, 0), |
| 124 | + (1.75, 0), |
| 125 | + (2.0, 0), |
| 126 | + (2.25, 1), |
| 127 | + (2.5, 0), |
| 128 | + (2.75, 1), |
| 129 | + (3.0, 0), |
| 130 | + (3.25, 1), |
| 131 | + (3.5, 0), |
| 132 | + (4.0, 1), |
| 133 | + (4.25, 1), |
| 134 | + (4.5, 1), |
| 135 | + (4.75, 1), |
| 136 | + (5.0, 1), |
| 137 | + (5.5, 1), |
| 138 | + ) |
| 139 | + training_data = np.array(raw_data).astype("float32") |
| 140 | + labels = training_data[:, 1] |
| 141 | + |
| 142 | + # upload data to S3 bucket |
| 143 | + buf = io.BytesIO() |
| 144 | + smac.write_numpy_to_dense_tensor(buf, training_data, labels) |
| 145 | + buf.seek(0) |
| 146 | + s3_train_data = f"s3://{bucket}/{prefix}/train" |
| 147 | + S3Uploader.upload_bytes(b=buf, s3_uri=s3_train_data, sagemaker_session=sagemaker_session) |
| 148 | + output_location = f"s3://{bucket}/{prefix}/output" |
| 149 | + container = image_uris.retrieve("linear-learner", region) |
| 150 | + estimator = sagemaker.estimator.Estimator( |
| 151 | + container, |
| 152 | + role="SageMakerRole", |
| 153 | + instance_count=1, |
| 154 | + instance_type="ml.m4.xlarge", |
| 155 | + output_path=output_location, |
| 156 | + sagemaker_session=sagemaker_session, |
| 157 | + ) |
| 158 | + estimator.set_hyperparameters( |
| 159 | + feature_dim=2, mini_batch_size=10, predictor_type="binary_classifier" |
| 160 | + ) |
| 161 | + estimator.fit({"train": s3_train_data}) |
| 162 | + print(f"Training job name: {estimator.latest_training_job.name}") |
| 163 | + estimator.register() |
| 164 | + |
| 165 | + |
105 | 166 | def test_async_byo_estimator(sagemaker_session, region, cpu_instance_type, training_set):
|
106 | 167 | image_uri = image_uris.retrieve("factorization-machines", region)
|
107 | 168 | endpoint_name = unique_name_from_base("byo")
|
|
0 commit comments