|
12 | 12 | # language governing permissions and limitations under the License.
|
13 | 13 | from __future__ import absolute_import
|
14 | 14 |
|
15 |
| -import base64 |
16 | 15 | import glob
|
17 | 16 | import logging
|
18 | 17 | import os
|
19 | 18 | import shutil
|
20 |
| -import subprocess |
21 |
| -import sys |
22 | 19 | import tempfile
|
23 | 20 | import time
|
24 | 21 | import uuid
|
25 | 22 |
|
26 | 23 | import boto3
|
27 | 24 | import pytest
|
28 | 25 |
|
29 |
| -import docker |
30 |
| - |
31 |
| -from tests.integ import lock |
32 |
| -from tests.integ.utils import create_repository |
33 | 26 | from tests.integ import DATA_DIR
|
34 | 27 |
|
35 | 28 | from sagemaker.experiments import trial_component, trial, experiment
|
36 |
| -from sagemaker.s3 import S3Uploader |
37 | 29 | from sagemaker.utils import retry_with_backoff
|
38 | 30 | from tests.integ.sagemaker.experiments.helpers import name, names
|
39 | 31 |
|
@@ -137,96 +129,16 @@ def tempdir():
|
137 | 129 | shutil.rmtree(temp_dir)
|
138 | 130 |
|
139 | 131 |
|
140 |
| -@pytest.fixture(scope="module") |
141 |
| -def bucket(sagemaker_session): |
142 |
| - return sagemaker_session.default_bucket() |
143 |
| - |
144 |
| - |
145 |
| -@pytest.fixture(scope="module") |
146 |
| -def training_input_s3_uri(sagemaker_session, tempdir, bucket): |
147 |
| - filepath = os.path.join(tempdir, name()) |
148 |
| - with open(filepath, "w") as w: |
149 |
| - w.write("Hello World!") |
150 |
| - s3_uri = f"s3://{bucket}/experiments/training-input/{name()}" |
151 |
| - return S3Uploader.upload( |
152 |
| - local_path=filepath, desired_s3_uri=s3_uri, sagemaker_session=sagemaker_session |
153 |
| - ) |
154 |
| - |
155 |
| - |
156 |
| -@pytest.fixture(scope="module") |
157 |
| -def training_output_s3_uri(bucket): |
158 |
| - return f"s3://{bucket}/experiments/training-output/" |
159 |
| - |
160 |
| - |
161 |
| -# TODO we should remove the boto model file once the Run API changes release |
162 |
| -BOTO_MODEL_LOCAL_PATH = os.path.join(DATA_DIR, "experiment", "sagemaker-2017-07-24.normal.json") |
163 |
| -METRICS_MODEL_LOCAL_PATH = os.path.join( |
164 |
| - DATA_DIR, "experiment", "sagemaker-metrics-2022-09-30.normal.json" |
165 |
| -) |
166 |
| -IMAGE_REPO_NAME = "sagemaker-experiments-test" |
167 |
| -IMAGE_VERSION = "1.0.92" # We should bump it up if need to update the docker image |
168 |
| -SM_SDK_TAR_NAME_IN_IMAGE = "sagemaker-dev.tar.gz" |
169 |
| -SM_BOTO_MODEL_PATH_IN_IMAGE = "boto/sagemaker-2017-07-24.normal.json" |
170 |
| -SM_METRICS_MODEL_PATH_IN_IMAGE = "boto/sagemaker-metrics-2022-09-30.normal.json" |
| 132 | +_EXP_PLUS_SDK_TAR = "sagemaker-beta-1.0.tar.gz" |
171 | 133 |
|
172 | 134 |
|
173 | 135 | @pytest.fixture(scope="module")
|
174 |
| -def docker_image(sagemaker_session): |
175 |
| - # requires docker to be running |
176 |
| - docker_client = docker.from_env() |
177 |
| - ecr_client = sagemaker_session.boto_session.client("ecr") |
178 |
| - |
179 |
| - token = ecr_client.get_authorization_token() |
180 |
| - username, password = ( |
181 |
| - base64.b64decode(token["authorizationData"][0]["authorizationToken"]).decode().split(":") |
182 |
| - ) |
183 |
| - registry = token["authorizationData"][0]["proxyEndpoint"] |
184 |
| - repository_name = IMAGE_REPO_NAME |
185 |
| - tag = "{}/{}:{}".format(registry, repository_name, IMAGE_VERSION)[8:] |
186 |
| - docker_dir = os.path.join(DATA_DIR, "experiment", "docker") |
187 |
| - |
188 |
| - with lock.lock(): |
189 |
| - # initialize the docker image repository |
190 |
| - create_repository(ecr_client, repository_name) |
191 |
| - |
192 |
| - # pull existing image for layer cache |
193 |
| - try: |
194 |
| - docker_client.images.pull(tag, auth_config={"username": username, "password": password}) |
195 |
| - print("Docker image with tag {} already exists.".format(tag)) |
196 |
| - return tag |
197 |
| - except docker.errors.NotFound: |
198 |
| - print("Docker image with tag {} does not exist. Will create one.".format(tag)) |
199 |
| - |
200 |
| - # copy boto model under docker dir |
201 |
| - os.makedirs(os.path.join(docker_dir, "boto"), exist_ok=True) |
202 |
| - shutil.copy( |
203 |
| - BOTO_MODEL_LOCAL_PATH, |
204 |
| - os.path.join(docker_dir, SM_BOTO_MODEL_PATH_IN_IMAGE), |
205 |
| - ) |
206 |
| - shutil.copy( |
207 |
| - METRICS_MODEL_LOCAL_PATH, |
208 |
| - os.path.join(docker_dir, SM_METRICS_MODEL_PATH_IN_IMAGE), |
209 |
| - ) |
210 |
| - |
211 |
| - # generate sdk tar file from package and put it under docker dir |
212 |
| - subprocess.check_call([sys.executable, "setup.py", "sdist"]) |
213 |
| - sdist_path = max(glob.glob("dist/sagemaker-*"), key=os.path.getctime) |
214 |
| - shutil.copy(sdist_path, os.path.join(docker_dir, SM_SDK_TAR_NAME_IN_IMAGE)) |
215 |
| - |
216 |
| - docker_client.images.build( |
217 |
| - path=docker_dir, |
218 |
| - dockerfile="Dockerfile", |
219 |
| - tag=tag, |
220 |
| - cache_from=[tag], |
221 |
| - buildargs={ |
222 |
| - "library": SM_SDK_TAR_NAME_IN_IMAGE, |
223 |
| - "botomodel": SM_BOTO_MODEL_PATH_IN_IMAGE, |
224 |
| - "script": "scripts/train_job_script_for_run_clz.py", |
225 |
| - "metricsmodel": SM_METRICS_MODEL_PATH_IN_IMAGE, |
226 |
| - }, |
227 |
| - ) |
228 |
| - docker_client.images.push(tag, auth_config={"username": username, "password": password}) |
229 |
| - return tag |
| 136 | +def job_resource_dir(): |
| 137 | + resource_dir = os.path.join(DATA_DIR, "experiment/resources") |
| 138 | + os.system("python setup.py sdist") |
| 139 | + sdist_path = max(glob.glob("dist/sagemaker-*"), key=os.path.getctime) |
| 140 | + shutil.copy(sdist_path, os.path.join(resource_dir, _EXP_PLUS_SDK_TAR)) |
| 141 | + return resource_dir |
230 | 142 |
|
231 | 143 |
|
232 | 144 | def _delete_associations(arn, sagemaker_session):
|
|
0 commit comments