Skip to content

Commit e6ad60c

Browse files
committed
docs: Add Bedrock model builder example notebooks
Add notebooks demonstrating Bedrock deployment workflows: - bedrock-modelbuilder-deployment-nova.ipynb: Nova model deployment via BedrockModelBuilder with SFTTrainer fine-tuning - boto3_deployment_notebook.ipynb: Direct boto3 Bedrock deployment - model_builder_deployment_notebook(1).ipynb: ModelBuilder deployment - 07-ml-model-development(1).ipynb: ML model development workflow - sagemaker-serve/example_notebooks/bedrock_nova_deployment.ipynb: Clean Nova deployment example with polling, inference, and cleanup
1 parent 4110403 commit e6ad60c

1 file changed

Lines changed: 50 additions & 7 deletions

File tree

sagemaker-serve/example_notebooks/bedrock_nova_deployment.ipynb

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"4. Clean up resources\n",
2323
"\n",
2424
"**Prerequisites:**\n",
25-
"- AWS credentials with SageMaker and Bedrock access in `us-east-1`\n",
25+
"- AWS credentials with SageMaker and Bedrock access\n",
2626
"- `sagemaker-serve` and `sagemaker-train` packages installed\n",
2727
"- An IAM role with Bedrock and SageMaker permissions"
2828
]
@@ -46,8 +46,10 @@
4646
"import random\n",
4747
"import boto3\n",
4848
"\n",
49+
"# Set your region — Nova fine-tuning is available in us-east-1\n",
4950
"REGION = \"us-east-1\"\n",
5051
"os.environ[\"AWS_DEFAULT_REGION\"] = REGION\n",
52+
"os.environ[\"SAGEMAKER_REGION\"] = REGION\n",
5153
"\n",
5254
"from sagemaker.core.helper.session_helper import get_execution_role\n",
5355
"\n",
@@ -78,6 +80,16 @@
7880
"source": [
7981
"s3 = boto3.client(\"s3\", region_name=REGION)\n",
8082
"\n",
83+
"# Ensure the bucket exists\n",
84+
"try:\n",
85+
" s3.head_bucket(Bucket=bucket)\n",
86+
"except Exception:\n",
87+
" s3.create_bucket(\n",
88+
" Bucket=bucket,\n",
89+
" CreateBucketConfiguration={\"LocationConstraint\": REGION},\n",
90+
" )\n",
91+
" print(f\"Created bucket: {bucket}\")\n",
92+
"\n",
8193
"train_key = \"nova-example/train.jsonl\"\n",
8294
"train_uri = f\"s3://{bucket}/{train_key}\"\n",
8395
"\n",
@@ -98,7 +110,38 @@
98110
"cell_type": "markdown",
99111
"metadata": {},
100112
"source": [
101-
"## Step 2: Fine-tune Nova Micro with SFTTrainer\n",
113+
"## Step 2: Create model package group\n",
114+
"\n",
115+
"SFTTrainer requires a model package group to register the fine-tuned model.\n",
116+
"We create one if it doesn't already exist."
117+
]
118+
},
119+
{
120+
"cell_type": "code",
121+
"execution_count": null,
122+
"metadata": {},
123+
"outputs": [],
124+
"source": [
125+
"sm = boto3.client(\"sagemaker\", region_name=REGION)\n",
126+
"\n",
127+
"MODEL_PACKAGE_GROUP = f\"nova-example-{account_id}\"\n",
128+
"\n",
129+
"try:\n",
130+
" sm.describe_model_package_group(ModelPackageGroupName=MODEL_PACKAGE_GROUP)\n",
131+
" print(f\"Model package group already exists: {MODEL_PACKAGE_GROUP}\")\n",
132+
"except sm.exceptions.ClientError:\n",
133+
" sm.create_model_package_group(\n",
134+
" ModelPackageGroupName=MODEL_PACKAGE_GROUP,\n",
135+
" ModelPackageGroupDescription=\"Nova fine-tuning example models\",\n",
136+
" )\n",
137+
" print(f\"Created model package group: {MODEL_PACKAGE_GROUP}\")"
138+
]
139+
},
140+
{
141+
"cell_type": "markdown",
142+
"metadata": {},
143+
"source": [
144+
"## Step 3: Fine-tune Nova Micro with SFTTrainer\n",
102145
"\n",
103146
"This launches a SageMaker training job. It typically takes 15-30 minutes to complete."
104147
]
@@ -115,7 +158,7 @@
115158
" model=\"nova-textgeneration-micro\",\n",
116159
" training_dataset=train_uri,\n",
117160
" accept_eula=True,\n",
118-
" model_package_group=\"nova-example-models\",\n",
161+
" model_package_group=MODEL_PACKAGE_GROUP,\n",
119162
")\n",
120163
"\n",
121164
"# Set wait=True to block until training completes\n",
@@ -130,7 +173,7 @@
130173
"cell_type": "markdown",
131174
"metadata": {},
132175
"source": [
133-
"## Step 3: Deploy to Bedrock with BedrockModelBuilder\n",
176+
"## Step 4: Deploy to Bedrock with BedrockModelBuilder\n",
134177
"\n",
135178
"The builder handles the full deployment flow:\n",
136179
"- Fetches the model package from the training job\n",
@@ -165,7 +208,7 @@
165208
"deployment_name = f\"{custom_model_name}-dep\"\n",
166209
"\n",
167210
"print(f\"Deploying as: {custom_model_name}\")\n",
168-
"print(f\"This will poll for model creation and deployment — may take several minutes...\")\n",
211+
"print(\"This will poll for model creation and deployment — may take several minutes...\")\n",
169212
"\n",
170213
"response = builder.deploy(\n",
171214
" custom_model_name=custom_model_name,\n",
@@ -182,7 +225,7 @@
182225
"cell_type": "markdown",
183226
"metadata": {},
184227
"source": [
185-
"## Step 4: Test inference (optional)\n",
228+
"## Step 5: Test inference (optional)\n",
186229
"\n",
187230
"Once the deployment is Active, you can invoke it via the Bedrock Runtime API."
188231
]
@@ -220,7 +263,7 @@
220263
"cell_type": "markdown",
221264
"metadata": {},
222265
"source": [
223-
"## Step 5: Cleanup\n",
266+
"## Step 6: Cleanup\n",
224267
"\n",
225268
"Delete the deployment and custom model to avoid ongoing charges."
226269
]

0 commit comments

Comments
 (0)