Skip to content

Commit 4d0bfed

Browse files
committed
doc: added support for generation of jumpstart model table on build
1 parent 34b07c0 commit 4d0bfed

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

doc/conf.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616
import pkg_resources
1717
from datetime import datetime
18+
import sys
19+
import os
20+
sys.path.append(os.path.join(os.path.dirname(__file__), '/doc/'))
21+
from jumpstart.utils import create_jumpstart_model_table
1822

1923
project = u"sagemaker"
2024
version = pkg_resources.require(project)[0].version
@@ -71,6 +75,12 @@
7175
# For Adobe Analytics
7276
html_js_files = [
7377
"https://a0.awsstatic.com/s_code/js/3.0/awshome_s_code.js",
78+
"https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js",
79+
"js/datatable.js",
80+
]
81+
82+
html_css_files = [
83+
'https://cdn.datatables.net/1.10.23/css/jquery.dataTables.min.css',
7484
]
7585

7686
html_context = {"css_files": ["_static/theme_overrides.css"]}
@@ -83,3 +93,6 @@
8393

8494
# autosectionlabel
8595
autosectionlabel_prefix_document = True
96+
97+
def setup(app):
98+
create_jumpstart_model_table()

doc/jumpstart/__init__.py

Whitespace-only changes.

doc/jumpstart/jumpstart.rst

Whitespace-only changes.

doc/jumpstart/utils.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import boto3
2+
import json
3+
from packaging.version import Version
4+
5+
JUMPSTART_BUCKET = "jumpstart-cache-prod-us-west-2"
6+
SDK_MANIFEST_FILE = "models_manifest.json"
7+
8+
9+
def get_jumpstart_sdk_manifest():
10+
s3_client = boto3.client("s3")
11+
studio_metadata = (
12+
s3_client.get_object(Bucket=JUMPSTART_BUCKET, Key=SDK_MANIFEST_FILE)["Body"]
13+
.read()
14+
.decode("utf-8")
15+
)
16+
return json.loads(studio_metadata)
17+
18+
19+
def get_jumpstart_sdk_spec(key):
20+
s3_client = boto3.client("s3")
21+
spec = s3_client.get_object(Bucket=JUMPSTART_BUCKET, Key=key)["Body"].read().decode("utf-8")
22+
return json.loads(spec)
23+
24+
def create_jumpstart_model_table():
25+
sdk_manifest = get_jumpstart_sdk_manifest()
26+
sdk_manifest_top_versions_for_models = {}
27+
28+
for model in sdk_manifest:
29+
if model["model_id"] not in sdk_manifest_top_versions_for_models:
30+
sdk_manifest_top_versions_for_models[model["model_id"]] = model
31+
else:
32+
if Version(sdk_manifest_top_versions_for_models[model["model_id"]]["version"]) < Version(
33+
model["version"]
34+
):
35+
sdk_manifest_top_versions_for_models[model["model_id"]] = model
36+
37+
f = open("jumpstart/jumpstart.rst", "w")
38+
39+
f.write('==================================\n')
40+
f.write('JumpStart Available Model Table\n')
41+
f.write('==================================\n')
42+
f.write('\n')
43+
f.write('JumpStart for the SageMaker Python SDK uses model ids and model versions to access the necessary utilities. This table serves to provide the core material plus some extra information that can be useful in selecting the correct model id and corresponding parameters.\n')
44+
f.write('\n')
45+
f.write('If you want to automatically use the latest version of the model, use "*" for the `model_version` attribute. We highly suggest pinning an exact model version however.\n')
46+
f.write('\n')
47+
f.write('.. list-table:: Available Models\n')
48+
f.write(' :widths: 50 20 20 20\n')
49+
f.write(' :header-rows: 1\n')
50+
f.write(' :class: datatable\n')
51+
f.write('\n')
52+
f.write(' * - Model ID\n')
53+
f.write(' - Fine Tunable?\n')
54+
f.write(' - Latest Version\n')
55+
f.write(' - Min SDK Version\n')
56+
57+
for model in sorted(sdk_manifest, key=lambda elt: elt["model_id"]):
58+
model_spec = get_jumpstart_sdk_spec(model["spec_key"])
59+
f.write(' * - {}\n'.format(model["model_id"]))
60+
f.write(' - {}\n'.format(model_spec["training_supported"]))
61+
f.write(' - {}\n'.format(model["version"]))
62+
f.write(' - {}\n'.format(model["min_version"]))
63+
64+
f.close()

doc/requirements.txt

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

0 commit comments

Comments
 (0)