Skip to content

Commit 2e77e27

Browse files
authored
Merge branch 'main' into feat/hyperpod-tf
2 parents 5015000 + f9da5fc commit 2e77e27

16 files changed

Lines changed: 942 additions & 36 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### **Changed**
1414
- updated `sagemaker-model-monitor` module and tested 4 types of monitoring end-to-end
15+
- added baseline generation step function to `sagemaker-model-monitor` module
1516
- updated lambda runtime and depdencies in `sagemaker-templates` module
1617

1718
## v2.0.0

modules/sagemaker/sagemaker-model-cicd/package-lock.json

Lines changed: 24 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/sagemaker/sagemaker-model-monitoring/README.md

Lines changed: 196 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,52 @@ Available monitoring types:
1313
* Model Bias
1414
* Model Explainability
1515

16-
Note that updating parameters will require replacing resources. Deployments may be delayed until any
17-
running monitoring jobs complete (and the resources can be destroyed).
16+
The module includes an optional automated baseline generation feature that creates baseline statistics and constraints for your monitoring jobs.
1817

1918
### Architecture
2019

2120
![SageMaker Model Monitoring Module Architecture](docs/_static/sagemaker-model-monitoring-module-architecture.png "SageMaker Model Monitoring Module Architecture")
2221

22+
1. **SageMaker Endpoint** - The deployed model endpoint being monitored
23+
- **WARNING**: Data capture must be enabled for monitoring to function
24+
- Captures inference requests and responses to S3
25+
26+
2. **Baseline Generation (Optional)** - Automated baseline creation workflow
27+
- **EventBridge Rule**: Triggers baseline generation on a schedule (default: daily at 2 AM UTC)
28+
- **Step Functions State Machine**: Orchestrates the baseline generation process
29+
- **Lambda Function (Docker)**: Invokes SageMaker Processing jobs for baseline calculation
30+
- **SageMaker Processing Jobs**: Analyze training data to generate baseline statistics and constraints
31+
- **S3 Baseline Output**: Stores generated baseline artifacts (constraints.json, statistics.json)
32+
33+
3. **Ground Truth Data (Optional)** - Required for model quality and bias monitoring
34+
- Actual "correct" labels created manually or by a workflow
35+
- Example: actual customer churn for churn prediction models
36+
- Stored in S3 and merged with captured inference data
37+
38+
4. **Monitoring Jobs and Schedules** - Continuous monitoring execution
39+
- **Monitoring Schedules**: Cron-based execution (minimum 1 hour interval)
40+
- **SageMaker Monitoring Jobs**: Compare captured data against baselines
41+
- Supports data quality, model quality, model bias, and model explainability monitoring
42+
43+
5. **Monitoring Outputs** - Results and alerts
44+
- **Violations Report**: Detailed violations file emitted to S3
45+
- **CloudWatch Metrics**: Some monitoring types emit metrics (e.g., data quality drift)
46+
- **CloudWatch Alarms**: Can be configured based on emitted metrics for automated alerting
47+
48+
### Baseline Generation
49+
50+
The module includes an optional automated baseline generation feature that creates baseline statistics and constraints for your monitoring jobs.
51+
52+
![SageMaker Model Monitoring Baseline Generation](docs/_static/sagemaker-model-monitoring-baseline.png "SageMaker Model Monitoring Baseline Generation")
53+
54+
When you provide training data, the module will:
55+
56+
1. Deploy a Step Functions state machine that orchestrates baseline generation
57+
2. Run SageMaker Processing jobs to analyze your training data
58+
3. Generate baseline statistics and constraints files
59+
4. Store the baseline artifacts in your specified S3 location
60+
5. Schedule automatic baseline regeneration (default: daily at 2 AM UTC)
61+
2362
## Inputs/Outputs
2463

2564
### Input Parameters
@@ -45,6 +84,19 @@ One or more of:
4584
- `sagemaker_project_name`: SageMaker project name
4685
- `tags`: Dictionary of tags to apply to resources
4786

87+
#### Baseline Generation Parameters (Optional)
88+
89+
These parameters control the automated baseline generation feature:
90+
91+
- `baseline_training_data_s3_uri`: S3 URI for the training data used to generate baselines (e.g., `s3://bucket/path/to/training-data.csv`)
92+
- `baseline_output_data_s3_uri`: S3 URI where baseline statistics and constraints will be stored (e.g., `s3://bucket/path/to/baseline-output/`)
93+
- `baseline_instance_count`: Number of ML compute instances for baseline generation (default: 1)
94+
- `baseline_instance_type`: ML compute instance type for baseline generation (default: "ml.m5.xlarge")
95+
- `baseline_volume_size_gb`: Size of ML storage volume in GB for baseline generation (default: 20)
96+
- `baseline_max_runtime_seconds`: Maximum runtime in seconds for baseline generation jobs (default: 3600)
97+
98+
**Note**: If `baseline_training_data_s3_uri` and `baseline_output_data_s3_uri` are provided, the module will automatically create a Step Functions state machine to generate and update baselines for all enabled monitoring types.
99+
48100
### Per-job Parameters
49101

50102
#### Data Quality Monitoring Job Parameters
@@ -102,6 +154,8 @@ One or more of:
102154

103155
### Sample manifest declaration
104156

157+
#### Basic Monitoring (without baseline generation)
158+
105159
```yaml
106160
name: monitoring
107161
path: modules/sagemaker/sagemaker-model-monitoring
@@ -116,11 +170,150 @@ parameters:
116170
value: DEMO-xgb-churn-pred-model-monitor-2025-10-23-19-11-16
117171
- name: enable_data_quality_monitor
118172
value: true
119-
- name: data-quality-schedule-expression
173+
- name: data_quality_schedule_expression
120174
value: cron(0 * ? * * *)
121175
- name: data_quality_baseline_s3_uri
122176
value: s3://sagemaker-us-east-2-<REDACTED>/SF-DEMO-xgb-churn-pred-model-monitor/baseline
123177
- name: data_quality_output_s3_uri
124178
value: s3://sagemaker-us-east-2-<REDACTED>/SF-DEMO-xgb-churn-pred-model-monitor/output
179+
```
180+
181+
#### With Automated Baseline Generation
182+
183+
```yaml
184+
name: monitoring
185+
path: modules/sagemaker/sagemaker-model-monitoring
186+
parameters:
187+
- name: sagemaker_project_id
188+
value: SF-DEMO-xgb-churn-pred-model-monitor-2025-10-23-19-11-16
189+
- name: sagemaker_project_name
190+
value: SF-DEMO-xgb-churn-pred-model-monitor-2025-10-23-19-11-16
191+
- name: model_bucket_arn
192+
value: arn:aws:s3:::sagemaker-us-east-2-<REDACTED>
193+
- name: endpoint_name
194+
value: DEMO-xgb-churn-pred-model-monitor-2025-10-23-19-11-16
195+
# Baseline generation parameters
196+
- name: baseline_training_data_s3_uri
197+
value: s3://sagemaker-us-east-2-<REDACTED>/training-data/train.csv
198+
- name: baseline_output_data_s3_uri
199+
value: s3://sagemaker-us-east-2-<REDACTED>/baselines/
200+
- name: baseline_instance_type
201+
value: ml.m5.xlarge
202+
- name: baseline_max_runtime_seconds
203+
value: 3600
204+
# Enable monitoring types
205+
- name: enable_data_quality_monitor
206+
value: true
207+
- name: enable_model_quality_monitor
208+
value: true
209+
# Data quality monitoring
210+
- name: data_quality_schedule_expression
211+
value: cron(0 * ? * * *)
212+
- name: data_quality_baseline_s3_uri
213+
value: s3://sagemaker-us-east-2-<REDACTED>/baselines/data-quality/
214+
- name: data_quality_output_s3_uri
215+
value: s3://sagemaker-us-east-2-<REDACTED>/monitoring-output/data-quality/
216+
# Model quality monitoring
217+
- name: model_quality_schedule_expression
218+
value: cron(0 * ? * * *)
219+
- name: model_quality_baseline_s3_uri
220+
value: s3://sagemaker-us-east-2-<REDACTED>/baselines/model-quality/
221+
- name: model_quality_output_s3_uri
222+
value: s3://sagemaker-us-east-2-<REDACTED>/monitoring-output/model-quality/
223+
- name: model_quality_ground_truth_s3_uri
224+
value: s3://sagemaker-us-east-2-<REDACTED>/ground-truth/
225+
- name: model_quality_problem_type
226+
value: BinaryClassification
227+
```
228+
229+
### Sample Baseline Generation Events
230+
231+
#### Step Functions Event Examples
232+
233+
The baseline generation Step Functions state machine accepts events with the following structure. You can manually trigger the state machine with these event payloads:
234+
235+
**Data Quality Baseline:**
236+
```json
237+
{
238+
"monitor_type": "data_quality",
239+
"endpoint_name": "my-endpoint",
240+
"training_data_uri": "s3://my-bucket/training-data/train.csv",
241+
"baseline_output_uri": "s3://my-bucket/baselines/data-quality/",
242+
"data_quality_params": {
243+
"instance_count": 1,
244+
"instance_type": "ml.m5.xlarge",
245+
"volume_size_gb": 30,
246+
"max_runtime_seconds": 3600
247+
}
248+
}
249+
```
250+
251+
**Model Quality Baseline:**
252+
```json
253+
{
254+
"monitor_type": "model_quality",
255+
"endpoint_name": "my-endpoint",
256+
"training_data_uri": "s3://my-bucket/training-data/train.csv",
257+
"baseline_output_uri": "s3://my-bucket/baselines/model-quality/",
258+
"model_quality_params": {
259+
"instance_count": 1,
260+
"instance_type": "ml.m5.xlarge",
261+
"volume_size_gb": 30,
262+
"max_runtime_seconds": 1800,
263+
"problem_type": "BinaryClassification",
264+
"inference_attribute": "prediction",
265+
"probability_attribute": "probability",
266+
"ground_truth_attribute": "label"
267+
}
268+
}
269+
```
125270

271+
**Model Bias Baseline:**
272+
```json
273+
{
274+
"monitor_type": "model_bias",
275+
"endpoint_name": "my-endpoint",
276+
"training_data_uri": "s3://my-bucket/training-data/train.csv",
277+
"baseline_output_uri": "s3://my-bucket/baselines/model-bias/",
278+
"model_bias_params": {
279+
"instance_count": 1,
280+
"instance_type": "ml.m5.xlarge",
281+
"volume_size_gb": 30,
282+
"max_runtime_seconds": 1800,
283+
"label_header": "label",
284+
"headers": "feature1,feature2,feature3,label",
285+
"dataset_type": "text/csv",
286+
"label_values": "0,1",
287+
"facet_name": "feature1",
288+
"facet_values": "100,200",
289+
"probability_threshold": 0.8,
290+
"model_name": "my-model"
291+
}
292+
}
126293
```
294+
295+
**Model Explainability Baseline:**
296+
```json
297+
{
298+
"monitor_type": "model_explainability",
299+
"endpoint_name": "my-endpoint",
300+
"training_data_uri": "s3://my-bucket/training-data/train.csv",
301+
"baseline_output_uri": "s3://my-bucket/baselines/model-explainability/",
302+
"model_explainability_params": {
303+
"instance_count": 1,
304+
"instance_type": "ml.m5.xlarge",
305+
"volume_size_gb": 30,
306+
"max_runtime_seconds": 1800,
307+
"label_header": "label",
308+
"headers": "feature1,feature2,feature3,label",
309+
"dataset_type": "text/csv",
310+
"model_name": "my-model",
311+
"num_samples": 100,
312+
"agg_method": "mean_abs",
313+
"save_local_shap_values": false,
314+
"shap_baseline": [[0.0]]
315+
}
316+
}
317+
```
318+
319+
**Note**: All parameter fields within the `*_params` objects are optional and will use the defaults shown above if not provided.
142 KB
Loading
62 KB
Loading

0 commit comments

Comments
 (0)