Skip to content

Commit 86b2620

Browse files
committed
docs
1 parent fe2f742 commit 86b2620

3 files changed

Lines changed: 194 additions & 3 deletions

File tree

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

Lines changed: 192 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,50 @@ Available monitoring types:
1313
* Model Bias
1414
* Model Explainability
1515

16+
### Baseline Generation
17+
18+
The module includes an optional automated baseline generation feature that creates baseline statistics and constraints for your monitoring jobs. When you provide training data, the module will:
19+
20+
1. Deploy a Step Functions state machine that orchestrates baseline generation
21+
2. Run SageMaker Processing jobs to analyze your training data
22+
3. Generate baseline statistics and constraints files
23+
4. Store the baseline artifacts in your specified S3 location
24+
5. Schedule automatic baseline regeneration (default: daily at 2 AM UTC)
25+
26+
The baseline generation uses a Lambda function deployed as a Docker container image to handle the SageMaker SDK dependencies efficiently.
27+
1628
Note that updating parameters will require replacing resources. Deployments may be delayed until any
1729
running monitoring jobs complete (and the resources can be destroyed).
1830

1931
### Architecture
2032

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

23-
## Inputs/Outputs
35+
1. **SageMaker Endpoint** - The deployed model endpoint being monitored
36+
- **WARNING**: Data capture must be enabled for monitoring to function
37+
- Captures inference requests and responses to S3
38+
39+
2. **Baseline Generation (Optional)** - Automated baseline creation workflow
40+
- **EventBridge Rule**: Triggers baseline generation on a schedule (default: daily at 2 AM UTC)
41+
- **Step Functions State Machine**: Orchestrates the baseline generation process
42+
- **Lambda Function (Docker)**: Invokes SageMaker Processing jobs for baseline calculation
43+
- **SageMaker Processing Jobs**: Analyze training data to generate baseline statistics and constraints
44+
- **S3 Baseline Output**: Stores generated baseline artifacts (constraints.json, statistics.json)
45+
46+
3. **Ground Truth Data (Optional)** - Required for model quality and bias monitoring
47+
- Actual "correct" labels created manually or by a workflow
48+
- Example: actual customer churn for churn prediction models
49+
- Stored in S3 and merged with captured inference data
50+
51+
4. **Monitoring Jobs and Schedules** - Continuous monitoring execution
52+
- **Monitoring Schedules**: Cron-based execution (minimum 1 hour interval)
53+
- **SageMaker Monitoring Jobs**: Compare captured data against baselines
54+
- Supports data quality, model quality, model bias, and model explainability monitoring
55+
56+
5. **Monitoring Outputs** - Results and alerts
57+
- **Violations Report**: Detailed violations file emitted to S3
58+
- **CloudWatch Metrics**: Some monitoring types emit metrics (e.g., data quality drift)
59+
- **CloudWatch Alarms**: Can be configured based on emitted metrics for automated alerting
2460

2561
### Input Parameters
2662

@@ -45,6 +81,19 @@ One or more of:
4581
- `sagemaker_project_name`: SageMaker project name
4682
- `tags`: Dictionary of tags to apply to resources
4783

84+
#### Baseline Generation Parameters (Optional)
85+
86+
These parameters control the automated baseline generation feature:
87+
88+
- `baseline_training_data_s3_uri`: S3 URI for the training data used to generate baselines (e.g., `s3://bucket/path/to/training-data.csv`)
89+
- `baseline_output_data_s3_uri`: S3 URI where baseline statistics and constraints will be stored (e.g., `s3://bucket/path/to/baseline-output/`)
90+
- `baseline_instance_count`: Number of ML compute instances for baseline generation (default: 1)
91+
- `baseline_instance_type`: ML compute instance type for baseline generation (default: "ml.m5.xlarge")
92+
- `baseline_volume_size_gb`: Size of ML storage volume in GB for baseline generation (default: 20)
93+
- `baseline_max_runtime_seconds`: Maximum runtime in seconds for baseline generation jobs (default: 3600)
94+
95+
**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.
96+
4897
### Per-job Parameters
4998

5099
#### Data Quality Monitoring Job Parameters
@@ -102,6 +151,8 @@ One or more of:
102151

103152
### Sample manifest declaration
104153

154+
#### Basic Monitoring (without baseline generation)
155+
105156
```yaml
106157
name: monitoring
107158
path: modules/sagemaker/sagemaker-model-monitoring
@@ -116,11 +167,150 @@ parameters:
116167
value: DEMO-xgb-churn-pred-model-monitor-2025-10-23-19-11-16
117168
- name: enable_data_quality_monitor
118169
value: true
119-
- name: data-quality-schedule-expression
170+
- name: data_quality_schedule_expression
120171
value: cron(0 * ? * * *)
121172
- name: data_quality_baseline_s3_uri
122173
value: s3://sagemaker-us-east-2-<REDACTED>/SF-DEMO-xgb-churn-pred-model-monitor/baseline
123174
- name: data_quality_output_s3_uri
124175
value: s3://sagemaker-us-east-2-<REDACTED>/SF-DEMO-xgb-churn-pred-model-monitor/output
176+
```
177+
178+
#### With Automated Baseline Generation
179+
180+
```yaml
181+
name: monitoring
182+
path: modules/sagemaker/sagemaker-model-monitoring
183+
parameters:
184+
- name: sagemaker_project_id
185+
value: SF-DEMO-xgb-churn-pred-model-monitor-2025-10-23-19-11-16
186+
- name: sagemaker_project_name
187+
value: SF-DEMO-xgb-churn-pred-model-monitor-2025-10-23-19-11-16
188+
- name: model_bucket_arn
189+
value: arn:aws:s3:::sagemaker-us-east-2-<REDACTED>
190+
- name: endpoint_name
191+
value: DEMO-xgb-churn-pred-model-monitor-2025-10-23-19-11-16
192+
# Baseline generation parameters
193+
- name: baseline_training_data_s3_uri
194+
value: s3://sagemaker-us-east-2-<REDACTED>/training-data/train.csv
195+
- name: baseline_output_data_s3_uri
196+
value: s3://sagemaker-us-east-2-<REDACTED>/baselines/
197+
- name: baseline_instance_type
198+
value: ml.m5.xlarge
199+
- name: baseline_max_runtime_seconds
200+
value: 3600
201+
# Enable monitoring types
202+
- name: enable_data_quality_monitor
203+
value: true
204+
- name: enable_model_quality_monitor
205+
value: true
206+
# Data quality monitoring
207+
- name: data_quality_schedule_expression
208+
value: cron(0 * ? * * *)
209+
- name: data_quality_baseline_s3_uri
210+
value: s3://sagemaker-us-east-2-<REDACTED>/baselines/data-quality/
211+
- name: data_quality_output_s3_uri
212+
value: s3://sagemaker-us-east-2-<REDACTED>/monitoring-output/data-quality/
213+
# Model quality monitoring
214+
- name: model_quality_schedule_expression
215+
value: cron(0 * ? * * *)
216+
- name: model_quality_baseline_s3_uri
217+
value: s3://sagemaker-us-east-2-<REDACTED>/baselines/model-quality/
218+
- name: model_quality_output_s3_uri
219+
value: s3://sagemaker-us-east-2-<REDACTED>/monitoring-output/model-quality/
220+
- name: model_quality_ground_truth_s3_uri
221+
value: s3://sagemaker-us-east-2-<REDACTED>/ground-truth/
222+
- name: model_quality_problem_type
223+
value: BinaryClassification
224+
```
225+
226+
### Sample Baseline Generation Events
227+
228+
#### Step Functions Event Examples
229+
230+
The baseline generation Step Functions state machine accepts events with the following structure. You can manually trigger the state machine with these event payloads:
231+
232+
**Data Quality Baseline:**
233+
```json
234+
{
235+
"monitor_type": "data_quality",
236+
"endpoint_name": "my-endpoint",
237+
"training_data_uri": "s3://my-bucket/training-data/train.csv",
238+
"baseline_output_uri": "s3://my-bucket/baselines/data-quality/",
239+
"data_quality_params": {
240+
"instance_count": 1,
241+
"instance_type": "ml.m5.xlarge",
242+
"volume_size_gb": 30,
243+
"max_runtime_seconds": 3600
244+
}
245+
}
246+
```
125247

248+
**Model Quality Baseline:**
249+
```json
250+
{
251+
"monitor_type": "model_quality",
252+
"endpoint_name": "my-endpoint",
253+
"training_data_uri": "s3://my-bucket/training-data/train.csv",
254+
"baseline_output_uri": "s3://my-bucket/baselines/model-quality/",
255+
"model_quality_params": {
256+
"instance_count": 1,
257+
"instance_type": "ml.m5.xlarge",
258+
"volume_size_gb": 30,
259+
"max_runtime_seconds": 1800,
260+
"problem_type": "BinaryClassification",
261+
"inference_attribute": "prediction",
262+
"probability_attribute": "probability",
263+
"ground_truth_attribute": "label"
264+
}
265+
}
126266
```
267+
268+
**Model Bias Baseline:**
269+
```json
270+
{
271+
"monitor_type": "model_bias",
272+
"endpoint_name": "my-endpoint",
273+
"training_data_uri": "s3://my-bucket/training-data/train.csv",
274+
"baseline_output_uri": "s3://my-bucket/baselines/model-bias/",
275+
"model_bias_params": {
276+
"instance_count": 1,
277+
"instance_type": "ml.m5.xlarge",
278+
"volume_size_gb": 30,
279+
"max_runtime_seconds": 1800,
280+
"label_header": "label",
281+
"headers": "feature1,feature2,feature3,label",
282+
"dataset_type": "text/csv",
283+
"label_values": "0,1",
284+
"facet_name": "feature1",
285+
"facet_values": "100,200",
286+
"probability_threshold": 0.8,
287+
"model_name": "my-model"
288+
}
289+
}
290+
```
291+
292+
**Model Explainability Baseline:**
293+
```json
294+
{
295+
"monitor_type": "model_explainability",
296+
"endpoint_name": "my-endpoint",
297+
"training_data_uri": "s3://my-bucket/training-data/train.csv",
298+
"baseline_output_uri": "s3://my-bucket/baselines/model-explainability/",
299+
"model_explainability_params": {
300+
"instance_count": 1,
301+
"instance_type": "ml.m5.xlarge",
302+
"volume_size_gb": 30,
303+
"max_runtime_seconds": 1800,
304+
"label_header": "label",
305+
"headers": "feature1,feature2,feature3,label",
306+
"dataset_type": "text/csv",
307+
"model_name": "my-model",
308+
"num_samples": 100,
309+
"agg_method": "mean_abs",
310+
"save_local_shap_values": false,
311+
"shap_baseline": [[0.0]]
312+
}
313+
}
314+
```
315+
316+
**Note**: All parameter fields within the `*_params` objects are optional and will use the defaults shown above if not provided.
62 KB
Loading

0 commit comments

Comments
 (0)