Repository navigation
Commit f8df0a7
authored
Bedrock fix (#5642)
* fix(bedrock): Poll for model Active status before creating deployment
Add _wait_for_model_active() to poll get_custom_model until the model
reaches Active status before calling create_custom_model_deployment.
This fixes ValidationException when the custom model is not yet ready
for deployment after create_custom_model returns.
* feat(bedrock): Harden BedrockModelBuilder for production readiness
Extract _is_nova_model() helper to eliminate duplicated Nova
detection logic across deploy() and _get_s3_artifacts(). Uses
getattr with safe defaults instead of fragile hasattr chains.
Add input validation to deploy() and create_deployment():
- Raise ValueError when model_package is not set
- Raise ValueError when custom_model_name or role_arn missing
for Nova deployments
- Raise ValueError when model_arn is empty in create_deployment
Move json and urlparse imports to module level (were previously
imported inside _get_checkpoint_uri_from_manifest). Replace
f-string logging with lazy %s formatting throughout.
Initialize status=None before the polling loop in
_wait_for_model_active to avoid UnboundLocalError if the loop
body never executes.
Rewrite unit tests (43 tests) with full coverage:
- _is_nova_model: recipe_name, hub_content_name, case
insensitivity, missing base_model, None fields
- __init__: None model, TrainingJob, ModelPackage
- Client singletons: caching, injection
- _fetch_model_package: ModelPackage, TrainingJob, ModelTrainer,
unknown type
- _get_s3_artifacts: None package, non-Nova, Nova delegation,
Nova fallback
- _get_checkpoint_uri_from_manifest: success, missing key,
NoSuchKey, not TrainingJob, no artifacts, invalid JSON
- _wait_for_model_active: immediate, polling, Failed, timeout
- create_deployment: polling chain, extra kwargs, empty/None ARN
- deploy: non-Nova, Nova full chain, hub_content_name detection,
default deployment name, tags, missing params, None stripping
Add integration tests for Nova E2E deployment:
- Training job existence and status verification
- Builder creation and Nova detection via _is_nova_model
- S3 artifacts checkpoint validation
- Full deploy-with-polling flow (marked @pytest.mark.slow)
- Timeout behavior on bogus ARN
- Validation error paths (no model_package, empty model_arn)
- Resource cleanup fixture for deployments and custom models
* feat(bedrock): Add deployment status polling after CreateCustomModelDeployment
Previously create_deployment() only polled for the custom model
to reach Active status before calling CreateCustomModelDeployment,
but did not wait for the deployment itself to become Active. This
caused callers to receive a deployment ARN that was still in
Creating state, requiring manual polling in user code.
Add _wait_for_deployment_active() that polls
get_custom_model_deployment until status reaches Active, raises
RuntimeError on Failed, and times out after max_wait seconds
(default 3600s, poll interval 30s).
Wire it into create_deployment() so the full flow is now:
1. _wait_for_model_active (poll model creation)
2. create_custom_model_deployment (API call)
3. _wait_for_deployment_active (poll deployment creation)
Gracefully skips deployment polling if the API response does not
contain a customModelDeploymentArn.
Unit tests (48 passing):
- _wait_for_deployment_active: immediate Active, polling,
Failed status, timeout
- create_deployment: full model+deployment polling chain,
skip polling when no ARN in response
- deploy Nova chain: updated to verify deployment polling
* fix(integ): Fix region handling and add get-or-create Nova training job
The TestModelCustomizationDeployment integ tests were failing with
DescribeTrainingJob 'Requested resource not found' because the
SageMaker SDK caches the first session's region internally. The
session-scoped cleanup_e2e_endpoints fixture (autouse) was creating
a session in us-east-1 (default) before the class fixtures could
set us-west-2, causing all subsequent TrainingJob.get calls to hit
the wrong region.
Fix by setting AWS_DEFAULT_REGION=us-west-2 in the
cleanup_e2e_endpoints fixture before any SageMaker session is
created.
Add tests/integ/conftest.py with a session-scoped
nova_training_job_name fixture that implements get-or-create:
- Checks if sdk-integ-nova-micro-sft exists and is Completed
- If InProgress, waits for completion
- If not found, uploads minimal training data to S3 and launches
a Nova Micro SFT training job via SFTTrainer
- Reused across test_bedrock_nova_e2e.py and
TestBedrockNovaDeployment in test_model_customization_deployment
Update both Nova test files to use the shared fixture instead of
hardcoded training job names.
* fix(integ): Use SAGEMAKER_REGION for cross-region training job lookup
The SageMaker SDK's SageMakerClient reads SAGEMAKER_REGION env var
at init time and caches the region for all subsequent API calls.
The cleanup_e2e_endpoints session fixture was the first to create
a SageMakerClient (in the default region), which then poisoned all
subsequent TrainingJob.get calls regardless of the region parameter.
Fix by setting SAGEMAKER_REGION=us-west-2 in cleanup_e2e_endpoints
before any SDK session is created, since all resources in this test
file live in us-west-2. The env var is restored after cleanup.
In CodeBuild (us-west-2) this is a no-op since the default region
already matches. The other test files (triton, tei, tgi) are not
affected since they have their own fixtures and don't import from
this file.
* refactor(integ): Replace Nova integ tests with example notebook
Remove us-east-1 Nova integration tests that cannot run in the
us-west-2 CodeBuild environment:
- Delete tests/integ/test_bedrock_nova_e2e.py
- Delete tests/integ/conftest.py (Nova get-or-create fixture)
- Remove TestBedrockNovaDeployment class from
test_model_customization_deployment.py
Add example_notebooks/bedrock_nova_deployment.ipynb covering the
full Nova workflow: SFTTrainer fine-tuning, BedrockModelBuilder
deploy with model+deployment polling, inference, and cleanup.
The BedrockModelBuilder source code and unit tests (48 passing)
are unchanged. The us-west-2 integ tests for non-Nova Bedrock
deployment (TestModelCustomizationDeployment) remain.
* 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
* 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
* fix(serve): Update Nova Bedrock deployment notebook with working e2e flow
Simplify notebook to use existing completed training job with
BedrockModelBuilder deploy flow. Fix Nova inference content format
to use array of {text: ...} objects. Remove broken SFTTrainer cells
that fail due to botocore service model mismatch.1 parent 3e1aef8 commit f8df0a7
8 files changed
Lines changed: 5575 additions & 369 deletions
File tree
- sagemaker-serve
- example_notebooks
- src/sagemaker/serve
- tests
- integ
- unit
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
0 commit comments