fix: allow Constraints.set_monitoring to disable monitoring for non-string features - #6312
mohamedzeidan2021 wants to merge 1 commit into
Conversation
|
Claude finished @mohamedzeidan2021's task in 38s —— View job Review: PR #6312 —
|
…tring features set_monitoring() unconditionally read feature["string_constraints"], which raised KeyError for non-string (e.g. Integral/Fractional) features and nested the override one level too deep even for string features. Per the Model Monitor constraints.json schema, monitoring_config_overrides belongs at the feature level. Write it there directly so it works for any feature type. Fixes aws#2745
9a83909 to
22ad275
Compare
jam-jee
left a comment
There was a problem hiding this comment.
Summary: Fix looks right and the tests cover the exact repro from #2745 (Integral feature with only num_constraints) plus the feature-level placement of monitoring_config_overrides. One CI failure is caused by this PR and needs a one-line fix before merge.
Blocking
sagemaker-core/tests/unit/model_monitor/test_monitoring_files.py:13-14 — codestyle-doc-tests (sagemaker-core) fails in black-check on this new file (both run attempts, latest 18:36Z). master pins black==26.3.1 (requirements/tox/black_requirements.txt), which requires a blank line between the module docstring and the first import:
"""Unit tests for the Constraints.set_monitoring feature-level override."""
from __future__ import absolute_importThe PR body says "black clean"; your local black is probably older than 26.x. Unrelated PR #6342 passes the same check today, so this is the only thing standing between this PR and a green codestyle job.
Nits (non-blocking)
test_monitoring_api_mapduplicatestest_set_monitoring_enable_maps_to_enabledand the disable test; one can go.- Pre-existing, out of scope:
set_monitoringsilently no-ops whenfeature_namematches nothing. AValueErrorwould be friendlier; happy to see that as a follow-up.
CI attribution: integ-tests (sagemaker-mlops) (feature-group quota 200 at 221 used; processing/transform jobs failing in the same 21:20-21:35Z window on #6313/#6314, passing on #6315 20 min later), integ-tests (sagemaker-serve) (InsufficientInstanceCapacity then expired token at 3h), and integ-tests-us-east-1 (Nova deployment quota 10/10) are all failing on unrelated PRs and are not caused by this change.
The v2 twin #6325 is unaffected (master-v2 pins black 24.3.0) and is already approved.
|
Claude finished @mohamedzeidan2021's task in 36s —— View job Review: PR #6312 —
|
Issue
Fixes #2745
sagemaker.model_monitor.Constraints.set_monitoring(enable_monitoring, feature_name=...)only worked for string-type features. For a non-string feature (e.g. binary/Integral likeChurn) it raisedKeyError: 'string_constraints', and even for string features it nested the override one level too deep — insidestring_constraintsrather than at the feature level, contrary to the Model Monitorconstraints.jsonschema.Fix
Per the constraints.json schema,
monitoring_config_overridesis a feature-level key (a sibling ofname,inferred_type, and the type-specificnum_constraints/string_constraintsblocks). The method now reads/writesmonitoring_config_overridesdirectly on the feature dict, so it works for any feature type and places the override where the schema (and the docs) say it belongs. The top-level (feature_name=None) path is unchanged.Before:
After:
Testing
Added
sagemaker-core/tests/unit/model_monitor/test_monitoring_files.py(7 tests): non-string feature (the reported case), string feature, enable/disable mapping, preservation of existing overrides, and the top-level no-feature_namepath. All pass; verified they fail without the fix. Existingtests/unit/model_monitorsuite green (51 passed, 1 skipped).blackandflake8clean.Backwards compatibility
No public signature/return/exception change. No other readers of
monitoring_config_overrides/string_constraintsand no other callers ofset_monitoringexist in the codebase. Output for string features moves the override from insidestring_constraintsto the feature level — this corrects the reported bug and matches the documented schema.