Skip to content

Commit f94245c

Browse files
committed
fix: use request url so that we dont have to pass aws creds
1 parent 1f9b88f commit f94245c

File tree

6 files changed

+88
-80
lines changed

6 files changed

+88
-80
lines changed

doc/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
from datetime import datetime
1818
import sys
1919
import os
20-
from jumpstart.utils import create_jumpstart_model_table
21-
20+
from doc_utils.jumpstart_doc_utils import create_jumpstart_model_table
2221
sys.path.append(os.path.join(os.path.dirname(__file__), "/doc/"))
2322

2423
project = "sagemaker"
File renamed without changes.
File renamed without changes.

doc/doc_utils/jumpstart_doc_utils.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
from __future__ import absolute_import
14+
from urllib import request
15+
import json
16+
from packaging.version import Version
17+
18+
JUMPSTART_REGION = "eu-west-2"
19+
SDK_MANIFEST_FILE = "models_manifest.json"
20+
JUMPSTART_BUCKET_BASE_URL = 'https://jumpstart-cache-prod-{}.s3.{}.amazonaws.com'.format(JUMPSTART_REGION, JUMPSTART_REGION)
21+
22+
23+
def get_jumpstart_sdk_manifest():
24+
url = '{}/{}'.format(JUMPSTART_BUCKET_BASE_URL, SDK_MANIFEST_FILE)
25+
with request.urlopen(url) as f:
26+
models_manifest = f.read().decode("utf-8")
27+
return json.loads(models_manifest)
28+
29+
30+
def get_jumpstart_sdk_spec(key):
31+
url = '{}/{}'.format(JUMPSTART_BUCKET_BASE_URL, key)
32+
with request.urlopen(url) as f:
33+
model_spec = f.read().decode("utf-8")
34+
return json.loads(model_spec)
35+
36+
37+
def create_jumpstart_model_table():
38+
sdk_manifest = get_jumpstart_sdk_manifest()
39+
sdk_manifest_top_versions_for_models = {}
40+
41+
for model in sdk_manifest:
42+
if model["model_id"] not in sdk_manifest_top_versions_for_models:
43+
sdk_manifest_top_versions_for_models[model["model_id"]] = model
44+
else:
45+
if Version(
46+
sdk_manifest_top_versions_for_models[model["model_id"]]["version"]
47+
) < Version(model["version"]):
48+
sdk_manifest_top_versions_for_models[model["model_id"]] = model
49+
50+
file_content = []
51+
52+
file_content.append("==================================\n")
53+
file_content.append("JumpStart Available Model Table\n")
54+
file_content.append("==================================\n")
55+
file_content.append(
56+
"""
57+
JumpStart for the SageMaker Python SDK uses model ids and model versions to access the necessary
58+
utilities. This table serves to provide the core material plus some extra information that can be useful
59+
in selecting the correct model id and corresponding parameters.\n
60+
"""
61+
)
62+
file_content.append(
63+
"""
64+
If you want to automatically use the latest version of the model, use "*" for the `model_version` attribute.
65+
We highly suggest pinning an exact model version however.\n
66+
"""
67+
)
68+
file_content.append("\n")
69+
file_content.append(".. list-table:: Available Models\n")
70+
file_content.append(" :widths: 50 20 20 20\n")
71+
file_content.append(" :header-rows: 1\n")
72+
file_content.append(" :class: datatable\n")
73+
file_content.append("\n")
74+
file_content.append(" * - Model ID\n")
75+
file_content.append(" - Fine Tunable?\n")
76+
file_content.append(" - Latest Version\n")
77+
file_content.append(" - Min SDK Version\n")
78+
79+
for model in sorted(sdk_manifest, key=lambda elt: elt["model_id"]):
80+
model_spec = get_jumpstart_sdk_spec(model["spec_key"])
81+
file_content.append(" * - {}\n".format(model["model_id"]))
82+
file_content.append(" - {}\n".format(model_spec["training_supported"]))
83+
file_content.append(" - {}\n".format(model["version"]))
84+
file_content.append(" - {}\n".format(model["min_version"]))
85+
86+
f = open("doc_utils/jumpstart.rst", "w")
87+
f.writelines(file_content)

doc/jumpstart/utils.py

Lines changed: 0 additions & 77 deletions
This file was deleted.

doc/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
sphinx==3.1.1
22
sphinx-rtd-theme==0.5.0
33
docutils==0.15.2
4-
boto3==1.20.21
54
packaging==20.9

0 commit comments

Comments
 (0)