Skip to content

Commit 91dee00

Browse files
committed
Update byo integ test to use sagemaker upload_data method
1 parent 7baf682 commit 91dee00

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

tests/data/dummy_tensor

311 KB
Binary file not shown.

tests/integ/test_byo_estimator.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@
1313
from __future__ import absolute_import
1414

1515
import gzip
16-
import io
1716
import json
1817
import os
1918
import pickle
2019
import sys
2120

22-
import boto3
23-
import numpy as np
2421
import pytest
2522

2623
import sagemaker
@@ -57,6 +54,7 @@ def test_byo_estimator(sagemaker_session, region):
5754
5855
"""
5956
image_name = registry(region) + "/factorization-machines:1"
57+
training_data_path = os.path.join(DATA_DIR, 'dummy_tensor')
6058

6159
with timeout(minutes=15):
6260
data_path = os.path.join(DATA_DIR, 'one_p_mnist', 'mnist.pkl.gz')
@@ -65,19 +63,11 @@ def test_byo_estimator(sagemaker_session, region):
6563
with gzip.open(data_path, 'rb') as f:
6664
train_set, _, _ = pickle.load(f, **pickle_args)
6765

68-
# take 100 examples for faster execution
69-
vectors = np.array([t.tolist() for t in train_set[0][:100]]).astype('float32')
70-
labels = np.where(np.array([t.tolist() for t in train_set[1][:100]]) == 0, 1.0, 0.0).astype('float32')
71-
72-
buf = io.BytesIO()
73-
write_numpy_to_dense_tensor(buf, vectors, labels)
74-
buf.seek(0)
75-
76-
bucket = sagemaker_session.default_bucket()
7766
prefix = 'test_byo_estimator'
7867
key = 'recordio-pb-data'
79-
boto3.resource('s3').Bucket(bucket).Object(os.path.join(prefix, 'train', key)).upload_fileobj(buf)
80-
s3_train_data = 's3://{}/{}/train/{}'.format(bucket, prefix, key)
68+
69+
s3_train_data = sagemaker_session.upload_data(path=training_data_path,
70+
key_prefix=os.path.join(prefix, 'train', key))
8171

8272
estimator = Estimator(image_name=image_name,
8373
role='SageMakerRole', train_instance_count=1,
@@ -111,6 +101,7 @@ def test_byo_estimator(sagemaker_session, region):
111101
def test_async_byo_estimator(sagemaker_session, region):
112102
image_name = registry(region) + "/factorization-machines:1"
113103
endpoint_name = name_from_base('byo')
104+
training_data_path = os.path.join(DATA_DIR, 'dummy_tensor')
114105
training_job_name = ""
115106

116107
with timeout(minutes=5):
@@ -120,19 +111,11 @@ def test_async_byo_estimator(sagemaker_session, region):
120111
with gzip.open(data_path, 'rb') as f:
121112
train_set, _, _ = pickle.load(f, **pickle_args)
122113

123-
# take 100 examples for faster execution
124-
vectors = np.array([t.tolist() for t in train_set[0][:100]]).astype('float32')
125-
labels = np.where(np.array([t.tolist() for t in train_set[1][:100]]) == 0, 1.0, 0.0).astype('float32')
126-
127-
buf = io.BytesIO()
128-
write_numpy_to_dense_tensor(buf, vectors, labels)
129-
buf.seek(0)
130-
131-
bucket = sagemaker_session.default_bucket()
132114
prefix = 'test_byo_estimator'
133115
key = 'recordio-pb-data'
134-
boto3.resource('s3').Bucket(bucket).Object(os.path.join(prefix, 'train', key)).upload_fileobj(buf)
135-
s3_train_data = 's3://{}/{}/train/{}'.format(bucket, prefix, key)
116+
117+
s3_train_data = sagemaker_session.upload_data(path=training_data_path,
118+
key_prefix=os.path.join(prefix, 'train', key))
136119

137120
estimator = Estimator(image_name=image_name,
138121
role='SageMakerRole', train_instance_count=1,

0 commit comments

Comments
 (0)