1313import gzip
1414import io
1515import json
16- import numpy as np
1716import os
1817import pickle
1918import sys
2019
2120import boto3
21+ import numpy as np
22+ import pytest
2223
2324import sagemaker
24- from sagemaker .estimator import Estimator
2525from sagemaker .amazon .amazon_estimator import registry
2626from sagemaker .amazon .common import write_numpy_to_dense_tensor
27+ from sagemaker .estimator import Estimator
2728from sagemaker .utils import name_from_base
28- from tests .integ import DATA_DIR , REGION
29+ from tests .integ import DATA_DIR
2930from tests .integ .timeout import timeout , timeout_and_delete_endpoint_by_name
3031
3132
33+ @pytest .fixture (scope = 'module' )
34+ def region (sagemaker_session ):
35+ return sagemaker_session .boto_session .region_name
36+
37+
3238def fm_serializer (data ):
3339 js = {'instances' : []}
3440 for row in data :
3541 js ['instances' ].append ({'features' : row .tolist ()})
3642 return json .dumps (js )
3743
3844
39- def test_byo_estimator ():
45+ def test_byo_estimator (sagemaker_session , region ):
4046 """Use Factorization Machines algorithm as an example here.
4147
4248 First we need to prepare data for training. We take standard data set, convert it to the
@@ -47,10 +53,9 @@ def test_byo_estimator():
4753 Default predictor is updated with json serializer and deserializer.
4854
4955 """
50- image_name = registry (REGION ) + "/factorization-machines:1"
56+ image_name = registry (region ) + "/factorization-machines:1"
5157
5258 with timeout (minutes = 15 ):
53- sagemaker_session = sagemaker .Session (boto_session = boto3 .Session (region_name = REGION ))
5459 data_path = os .path .join (DATA_DIR , 'one_p_mnist' , 'mnist.pkl.gz' )
5560 pickle_args = {} if sys .version_info .major == 2 else {'encoding' : 'latin1' }
5661
@@ -100,13 +105,12 @@ def test_byo_estimator():
100105 assert prediction ['score' ] is not None
101106
102107
103- def test_async_byo_estimator ():
104- image_name = registry (REGION ) + "/factorization-machines:1"
108+ def test_async_byo_estimator (sagemaker_session , region ):
109+ image_name = registry (region ) + "/factorization-machines:1"
105110 endpoint_name = name_from_base ('byo' )
106111 training_job_name = ""
107112
108113 with timeout (minutes = 5 ):
109- sagemaker_session = sagemaker .Session (boto_session = boto3 .Session (region_name = REGION ))
110114 data_path = os .path .join (DATA_DIR , 'one_p_mnist' , 'mnist.pkl.gz' )
111115 pickle_args = {} if sys .version_info .major == 2 else {'encoding' : 'latin1' }
112116
0 commit comments