AWS sagemaker documentation change
Summary
Added SageMaker Python SDK v3 code examples for saving tensors with Debugger in three scenarios: built-in collections, modified collections, and custom collections.
Security assessment
The changes add new code samples demonstrating SDK usage patterns. There is no evidence of security vulnerability fixes, security configurations, or security-related documentation. The modifications are routine updates for SDK version support.
Diff
diff --git a/sagemaker/latest/dg/debugger-save-tensors.md b/sagemaker/latest/dg/debugger-save-tensors.md index 574d5e3bf..f3706b078 100644 --- a//sagemaker/latest/dg/debugger-save-tensors.md +++ b//sagemaker/latest/dg/debugger-save-tensors.md @@ -63,0 +64,60 @@ In the following example code, the `s3_output_path` parameter for `DebuggerHookC +SageMaker Python SDK v3 + + + + import boto3 + import sagemaker + from sagemaker.train import ModelTrainer + from sagemaker.core.debugger import DebuggerHookConfig, CollectionConfig + from sagemaker.core.helper.session_helper import Session, get_execution_role + + **# use Debugger CollectionConfig to call built-in collections** + **collection_configs** =[ + CollectionConfig(name="weights"), + CollectionConfig(name="gradients"), + CollectionConfig(name="losses"), + CollectionConfig(name="biases") + ] + + # configure Debugger hook + # set a target S3 bucket as you want + sagemaker_session=Session() + BUCKET_NAME=sagemaker_session.default_bucket() + LOCATION_IN_BUCKET='debugger-built-in-collections-hook' + + **hook_config** =DebuggerHookConfig( + s3_output_path='s3://{BUCKET_NAME}/{LOCATION_IN_BUCKET}'. + format(BUCKET_NAME=BUCKET_NAME, + LOCATION_IN_BUCKET=LOCATION_IN_BUCKET), + collection_configs=**collection_configs** + ) + + from sagemaker.core import image_uris + from sagemaker.train.configs import SourceCode, Compute + + training_image = image_uris.retrieve( + framework="tensorflow", + region=boto3.Session().region_name, + version="2.9.0", + py_version="py39", + instance_type="ml.p3.2xlarge", + image_scope="training" + ) + + # construct a SageMaker ModelTrainer + sagemaker_model_trainer=ModelTrainer( + training_image=training_image, + source_code=SourceCode(entry_script='directory/to/your_training_script.py'), + role=get_execution_role(), + base_job_name='debugger-demo-job', + compute=Compute(instance_type="ml.p3.2xlarge", instance_count=1), + + # debugger-specific hook argument below + debugger_hook_config=**hook_config** + ) + + sagemaker_model_trainer.train() + +SageMaker Python SDK v2 (Legacy) + + @@ -111,0 +172,58 @@ You can modify the Debugger built-in collections using the `CollectionConfig` AP +SageMaker Python SDK v3 + + + + import boto3 + import sagemaker + from sagemaker.train import ModelTrainer + from sagemaker.core.debugger import DebuggerHookConfig, CollectionConfig + from sagemaker.core.helper.session_helper import Session, get_execution_role + + # use Debugger CollectionConfig to call and modify built-in collections + **collection_configs** =[ + CollectionConfig( + name="losses", + parameters={"save_interval": "50"})] + + # configure Debugger hook + # set a target S3 bucket as you want + sagemaker_session=Session() + BUCKET_NAME=sagemaker_session.default_bucket() + LOCATION_IN_BUCKET='debugger-modified-collections-hook' + + **hook_config** =DebuggerHookConfig( + s3_output_path='s3://{BUCKET_NAME}/{LOCATION_IN_BUCKET}'. + format(BUCKET_NAME=BUCKET_NAME, + LOCATION_IN_BUCKET=LOCATION_IN_BUCKET), + collection_configs=**collection_configs** + ) + + from sagemaker.core import image_uris + from sagemaker.train.configs import SourceCode, Compute + + training_image = image_uris.retrieve( + framework="tensorflow", + region=boto3.Session().region_name, + version="2.9.0", + py_version="py39", + instance_type="ml.p3.2xlarge", + image_scope="training" + ) + + # construct a SageMaker ModelTrainer + sagemaker_model_trainer=ModelTrainer( + training_image=training_image, + source_code=SourceCode(entry_script='directory/to/your_training_script.py'), + role=get_execution_role(), + base_job_name='debugger-demo-job', + compute=Compute(instance_type="ml.p3.2xlarge", instance_count=1), + + # debugger-specific hook argument below + debugger_hook_config=**hook_config** + ) + + sagemaker_model_trainer.train() + +SageMaker Python SDK v2 (Legacy) + + @@ -157,0 +276,62 @@ You can also save a reduced number of tensors instead of the full set of tensors +SageMaker Python SDK v3 + + + + import boto3 + import sagemaker + from sagemaker.train import ModelTrainer + from sagemaker.core.debugger import DebuggerHookConfig, CollectionConfig + from sagemaker.core.helper.session_helper import Session, get_execution_role + + # use Debugger CollectionConfig to create a custom collection + **collection_configs** =[ + CollectionConfig( + name="custom_activations_collection", + parameters={ + "include_regex": "relu|tanh", # Required + "reductions": "mean,variance,max,abs_mean,abs_variance,abs_max" + }) + ] + + # configure Debugger hook + # set a target S3 bucket as you want + sagemaker_session=Session() + BUCKET_NAME=sagemaker_session.default_bucket() + LOCATION_IN_BUCKET='debugger-custom-collections-hook' + + **hook_config** =DebuggerHookConfig( + s3_output_path='s3://{BUCKET_NAME}/{LOCATION_IN_BUCKET}'. + format(BUCKET_NAME=BUCKET_NAME, + LOCATION_IN_BUCKET=LOCATION_IN_BUCKET), + collection_configs=**collection_configs** + ) + + from sagemaker.core import image_uris + from sagemaker.train.configs import SourceCode, Compute + + training_image = image_uris.retrieve( + framework="tensorflow", + region=boto3.Session().region_name, + version="2.9.0", + py_version="py39", + instance_type="ml.p3.2xlarge", + image_scope="training" + ) + + # construct a SageMaker ModelTrainer + sagemaker_model_trainer=ModelTrainer( + training_image=training_image, + source_code=SourceCode(entry_script='directory/to/your_training_script.py'), + role=get_execution_role(), + base_job_name='debugger-demo-job', + compute=Compute(instance_type="ml.p3.2xlarge", instance_count=1), + + # debugger-specific hook argument below + debugger_hook_config=**hook_config** + ) + + sagemaker_model_trainer.train() + +SageMaker Python SDK v2 (Legacy) + +