SMDebug RulesConfig
SMDebug RulesConfig is a Python library that provides a mapping of built-in rules with default configurations for Amazon SageMaker Debugger. It helps users specify these rules and common collection configurations without needing to handle low-level details, working in conjunction with the Amazon SageMaker Python SDK. The current version is 1.0.1, released in December 2020. While the package itself has not seen recent updates, its functionality remains an integral part of the SageMaker Debugger ecosystem.
Warnings
- breaking Major version 1.0.0 introduced the ability to specify profiler rules, and 1.0.1 added action classes for rules (e.g., `StopTraining`, `Email`). While older rule definitions might still work, new features and potentially updated underlying behavior for rule processing necessitate awareness of these version changes when upgrading or using new capabilities.
- gotcha This library (smdebug-rulesconfig) is tightly integrated with the Amazon SageMaker Python SDK and the `smdebug` client library. To utilize the latest Debugger features and ensure compatibility, it is crucial to keep both `sagemaker` and `smdebug` packages updated in your environment, not just `smdebug-rulesconfig`.
- gotcha The SageMaker DebuggerHookConfig is initialized by default for framework estimators (e.g., TensorFlow, PyTorch) to minimize code changes for debugging. If you do not intend to use Debugger, you must explicitly disable the hook.
- gotcha The `smdebug-rulesconfig` library focuses on *configuring* rules. The actual execution and analysis of these rules occur within the broader Amazon SageMaker Debugger service, often leveraging the `smdebug` client library for data retrieval and custom rule logic. Confusing these roles can lead to unexpected behavior if not properly integrated into a SageMaker training job.
Install
-
pip install smdebug-rulesconfig
Imports
- rule_configs
from sagemaker.debugger import Rule, CollectionConfig, rule_configs
Quickstart
from sagemaker.debugger import Rule, CollectionConfig, rule_configs
from sagemaker.estimator import Estimator # Placeholder for a SageMaker Estimator
import os
# In a real scenario, replace this with your actual SageMaker Estimator setup
# and ensure AWS credentials are configured (e.g., via environment variables or AWS CLI)
# For example: estimator = TensorFlow(role=os.environ.get('SAGEMAKER_ROLE', 'arn:aws:iam::123456789012:role/SageMakerRole'), ...)
# We use a placeholder here for quickstart reproducibility.
# Example: Vanilla built-in rule without customization
# This would typically be passed to a SageMaker Estimator's 'rules' parameter.
rule_vanishing_gradient = Rule.sagemaker(rule_configs.vanishing_gradient())
print(f"Vanishing Gradient Rule: {rule_vanishing_gradient.name}")
# Example: Built-in rule with customization
# This demonstrates how to customize a rule's parameters and collections.
rule_customized_weight_update = Rule.sagemaker(
base_config=rule_configs.weight_update_ratio(),
name="my_custom_wup_rule", # Optional
# container_local_path="/local/path", # Optional, if running locally or specific container path
# s3_output_path="s3://your-s3-bucket/debug-output/", # Optional, overrides default
rule_parameters={
"threshold": "0.001" # Example parameter customization
},
collections_to_save=[
CollectionConfig(
name="weights", # Required. Debugger will collect tensors for this collection.
parameters={
"save_interval": "100" # Example collection parameter
}
)
]
)
print(f"Customized Weight Update Ratio Rule: {rule_customized_weight_update.name}")
print(f" Rule parameters: {rule_customized_weight_update.rule_parameters}")
print(f" Collections to save: {[c.name for c in rule_customized_weight_update.collections_to_save]}")