Skip to content

Commit 6ca72b6

Browse files
author
Mohamed Zeidan
committed
Added new column 'deploymeny configs' to the itable that allows user's to view SDK config code
moved location of file and get SDK config works for IDE now
1 parent 0de2138 commit 6ca72b6

File tree

2 files changed

+84
-4
lines changed

2 files changed

+84
-4
lines changed

examples/inference/SDK/inference-jumpstart-e2e.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"outputs": [],
5656
"source": [
5757
"# Import the helper module\n",
58-
"from jumpstart_public_hub_visualization_utils import get_all_public_hub_model_data\n",
58+
"from sagemaker.hyperpod.inference.jumpstart_public_hub_visualization_utils import get_all_public_hub_model_data\n",
5959
"\n",
6060
"# Load and display SageMaker public hub models\n",
6161
"get_all_public_hub_model_data(region=\"us-east-2\")"

examples/inference/SDK/jumpstart_public_hub_visualization_utils.py renamed to src/sagemaker/hyperpod/inference/jumpstart_public_hub_visualization_utils.py

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import itables
2020
import pandas
2121
import logging
22+
import json
2223
from botocore.config import Config
2324
from ipywidgets import Button, Output
2425
from IPython.display import display
@@ -160,6 +161,7 @@ def _get_model_summary(self, full_summary):
160161
"Model Type": model_type,
161162
"Model Description": full_summary["HubContentDescription"],
162163
"Search Keywords": keywords,
164+
"Deployment Configs": self._create_config_link(full_summary["HubContentName"]),
163165
}
164166

165167
def _determine_model_type(self, keywords, model_id):
@@ -180,6 +182,84 @@ def _get_hub_document(self, model_id):
180182
HubContentType="Model",
181183
HubContentName=model_id
182184
)["HubContentDocument"]
185+
186+
def _get_supported_instance_types(self, model_id):
187+
"""Extract supported instance types from hub document."""
188+
try:
189+
hub_doc = self._get_hub_document(model_id)
190+
doc_data = json.loads(hub_doc)
191+
192+
supported_types = doc_data.get("SupportedInferenceInstanceTypes", [])
193+
default_type = doc_data.get("DefaultInferenceInstanceType")
194+
195+
if default_type and default_type in supported_types:
196+
supported_types = [default_type] + [t for t in supported_types if t != default_type]
197+
198+
return {"types": supported_types, "default": default_type, "error": None}
199+
except Exception as e:
200+
return {"types": [], "default": None, "error": str(e)}
201+
202+
def _create_config_link(self, model_id):
203+
"""Create deployment config display using collapsible details for all environments."""
204+
return f'<details><summary style="color: #007bff; cursor: pointer;">View SDK Config</summary><pre style="font-size: 10px; background: #f5f5f5; padding: 5px; margin: 5px 0;">{self._generate_deployment_config(model_id)}</pre></details>'
205+
206+
def _generate_deployment_config(self, model_id):
207+
"""Generate deployment configuration code for a model."""
208+
instance_data = self._get_supported_instance_types(model_id)
209+
supported_types = instance_data["types"]
210+
default_type = instance_data["default"]
211+
error = instance_data["error"]
212+
213+
if error:
214+
instance_type = '<ENTER-INSTANCE-TYPE>'
215+
types_comment = ""
216+
else:
217+
instance_type = default_type if default_type else '\<ENTER-INSTANCE-TYPE\>'
218+
types_comment = self._format_instance_types_comment(supported_types)
219+
220+
config_code = f'''# Deployment configuration for {model_id}
221+
from sagemaker.hyperpod.inference.config.hp_jumpstart_endpoint_config import (
222+
Model, Server, SageMakerEndpoint
223+
)
224+
from sagemaker.hyperpod.inference.hp_jumpstart_endpoint import HPJumpStartEndpoint
225+
226+
{types_comment}
227+
228+
# Create configs - REPLACE PLACEHOLDER VALUE BELOW
229+
model = Model(
230+
model_id='{model_id}',
231+
)
232+
server = Server(
233+
instance_type='{instance_type}',
234+
)
235+
endpoint_name = SageMakerEndpoint(name='ENTER-YOUR-ENDPOINT-NAME')
236+
237+
# Create endpoint spec
238+
js_endpoint = HPJumpStartEndpoint(
239+
model=model,
240+
server=server,
241+
sage_maker_endpoint=endpoint_name,
242+
)
243+
244+
# Deploy the endpoint
245+
js_endpoint.create()'''
246+
return config_code
247+
248+
def _format_instance_types_comment(self, supported_types):
249+
"""Format instance types comment with line breaks for better readability."""
250+
if not supported_types:
251+
return "# No supported instance types found"
252+
253+
if len(supported_types) <= 5:
254+
return f"# Supported instance types: {', '.join(supported_types)}"
255+
256+
# For more than 5 instance types, format with newlines every 5 types
257+
comment_lines = ["# Supported instance types:"]
258+
for i in range(0, len(supported_types), 5):
259+
batch = supported_types[i:i+5]
260+
comment_lines.append(f"# {', '.join(batch)}")
261+
262+
return '\n'.join(comment_lines)
183263

184264

185265
def get_all_public_hub_model_data(region: str):
@@ -198,14 +278,14 @@ def interactive_view(tabular_data: list):
198278
styled_df = _style_dataframe(df)
199279
layout = _get_table_layout(len(tabular_data))
200280

201-
itables.show(styled_df, layout=layout)
281+
itables.show(styled_df, layout=layout, allow_html=True)
202282

203283

204284
def _configure_itables():
205285
"""Configure itables for notebook display."""
206286
itables.init_notebook_mode(all_interactive=True)
207287
itables.options.allow_html = True
208-
288+
209289

210290
def _style_dataframe(df):
211291
"""Apply styling to dataframe."""
@@ -216,4 +296,4 @@ def _style_dataframe(df):
216296

217297
def _get_table_layout(data_length):
218298
"""Get appropriate table layout based on data size."""
219-
return {} if data_length > 10 else {"topStart": None, "topEnd": "search"}
299+
return {} if data_length > 10 else {"topStart": None, "topEnd": "search"}

0 commit comments

Comments
 (0)