Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/inference/deploy_finetuned.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,4 +7,4 @@ Deploy models that have been fine-tuned through the :doc:`Model Customization <.
:maxdepth:1

Deploy to SageMaker Endpoint <../model_customization/deploy_sagemaker_endpoint>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/bedrock-modelbuilder-deployment>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/deployment/bedrock-modelbuilder-deployment>
8 changes: 4 additions & 4 deletions docs/model_customization/evaluation.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,10 +12,10 @@ Launch evaluation jobs with the following options:
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/llm_as_judge_demo
../../v3-examples/model-customization-examples/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/custom_scorer_demo
../../v3-examples/model-customization-examples/benchmark_demo
../../v3-examples/model-customization-examples/evaluation/llm_as_judge_demo
../../v3-examples/model-customization-examples/evaluation/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/evaluation/custom_scorer_demo
../../v3-examples/model-customization-examples/evaluation/benchmark_demo
../../v3-examples/nova-examples/evaluation-benchmark-and-custom-scorer


Expand Down
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_hyperpod.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,4 +177,4 @@ Interactive Notebook
.. toctree::
:maxdepth:1

../../v3-examples/model-customization-examples/sft_finetuning_hyperpod
../../v3-examples/model-customization-examples/serverful/sft_finetuning_hyperpod
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_serverful.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -138,4 +138,4 @@ Interactive Notebook
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/sft_finetuning_serverful_smtj
../../v3-examples/model-customization-examples/serverful/sft_finetuning_serverful_smtj
1 change: 1 addition & 0 deletions docs/model_customization/index.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,3 +23,4 @@ Key Benefits
open_weight_model_customization
nova
evaluation
notifications_setup
8 changes: 4 additions & 4 deletions docs/model_customization/model_customization.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -196,9 +196,9 @@ Key Features
:maxdepth: 1
:caption: Customization Techniques

SFT Finetuning <../../v3-examples/model-customization-examples/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/rlvr_finetuning_example_notebook_v3_prod>
SFT Finetuning <../../v3-examples/model-customization-examples/serverless/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/serverless/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/serverless/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/serverless/rlvr_finetuning_example_notebook_v3_prod>
Fine-Tuning with Serverful Training Jobs <finetuning_serverful>
Fine-Tuning with HyperPod <finetuning_hyperpod>
250 changes: 250 additions & 0 deletions docs/model_customization/notifications_setup.rst
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
Setting Up Training Job Notifications
========================================

Get notified when your training jobs complete, fail, or stop via SNS email/SMS
alerts. This guide walks through creating the prerequisite SNS topic and
configuring your trainer to send notifications.

Architecture
-------------

.. code-block:: text

SageMaker Training Job ──► EventBridge Rule ──► SNS Topic ──► Email/SMS/Slack

The SDK creates an EventBridge rule that listens for training job status changes
and routes them to your SNS topic. You provide the topic; the SDK handles the
wiring.

Prerequisites
--------------

You need:

1. An SNS topic with a policy allowing EventBridge to publish to it
2. A subscription on that topic (email, SMS, Slack, etc.)
3. IAM permissions for EventBridge rule management (see below)

Step 1: Create an SNS Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → **Create topic**
2. Choose **Standard** type
3. Name it (e.g., ``my-training-alerts``)
4. Click **Create topic**
5. Note the **Topic ARN** (e.g., ``arn:aws:sns:us-east-1:123456789012:my-training-alerts``)

**AWS CLI**

.. code-block:: bash

aws sns create-topic --name my-training-alerts

Step 2: Allow EventBridge to Publish
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The topic needs a resource policy granting EventBridge publish access.

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → open your topic → **Access policy** tab → **Edit**
2. Add this statement to the policy's ``Statement`` array (replace the ARN and
account ID with your own SNS topic ARN and AWS account ID):

.. code-block:: json

{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"Condition": {
"StringEquals": {"AWS:SourceAccount": "123456789012"}
}
}

.. note::

Replace ``arn:aws:sns:us-east-1:123456789012:my-training-alerts`` with your
actual SNS topic ARN, and ``123456789012`` with your AWS account ID. These
must match so that only EventBridge in your account can publish to your topic.

**AWS CLI**

.. code-block:: bash

TOPIC_ARN="arn:aws:sns:us-east-1:123456789012:my-training-alerts"
ACCOUNT_ID="123456789012"

aws sns set-topic-attributes \
--topic-arn $TOPIC_ARN \
--attribute-name Policy \
--attribute-value '{
"Version": "2008-10-17",
"Statement": [{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "'$TOPIC_ARN'",
"Condition": {"StringEquals": {"AWS:SourceAccount": "'$ACCOUNT_ID'"}}
}]
}'

Step 3: Subscribe to the Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Email**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol email \
--notification-endpoint you@example.com

Check your inbox and confirm the subscription.

**SMS**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol sms \
--notification-endpoint +15551234567

Step 4: Use with the SDK
~~~~~~~~~~~~~~~~~~~~~~~~~~

Pass the topic ARN in the ``notifications`` config when constructing your trainer:

.. code-block:: python

from sagemaker.train import SFTTrainer
from sagemaker.train.common import TrainingType
from sagemaker.core.training.configs import TrainingJobCompute

trainer = SFTTrainer(
model="amazon.nova-2-lite-v1",
training_type=TrainingType.LORA,
training_dataset="s3://my-bucket/data/train.jsonl",
compute=TrainingJobCompute(instance_type="ml.p4d.24xlarge"),
notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
},
)

trainer.train()

Configuration Options
~~~~~~~~~~~~~~~~~~~~~~

The ``notifications`` dict supports:

.. list-table::
:header-rows: 1
:widths: 25 10 65

* - Key
- Required
- Description
* - ``sns_topic_arn``
- Yes
- ARN of your SNS topic
* - ``events``
- No
- List of statuses to notify on. Default: ``["Completed", "Failed", "Stopped"]``.
Valid values: ``Completed``, ``Failed``, ``Stopped``, ``InProgress``.
* - ``event_bus_arn``
- No
- Custom EventBridge bus ARN. Defaults to the account's default event bus.
* - ``job_name_prefix``
- No
- Only notify for jobs whose name starts with this prefix.

Example: notify only on failures for jobs matching a prefix:

.. code-block:: python

notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"events": ["Failed"],
"job_name_prefix": "prod-sft-",
}

Managing Notification Rules
-----------------------------

List active rules:

.. code-block:: python

rules = trainer.list_notification_rules()
for rule in rules:
print(f"{rule['name']} ({rule['state']})")

Delete a rule:

.. code-block:: python

trainer.delete_notification_rule(rule_arn="arn:aws:events:us-east-1:123456789012:rule/sm-pysdk-job-notif-abc123")

Required IAM Permissions
--------------------------

The caller (your IAM role or user) needs these permissions. Replace the SNS
resource ARN with your actual topic ARN:

.. code-block:: json

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"events:PutRule",
"events:PutTargets",
"events:ListRules",
"events:ListTargetsByRule",
"events:RemoveTargets",
"events:DeleteRule"
],
"Resource": "arn:aws:events:*:*:rule/sm-pysdk-job-notif-*"
},
{
"Effect": "Allow",
"Action": "sns:GetTopicAttributes",
"Resource": "arn:aws:sns:*:*:my-training-alerts"
}
]
}

.. note::

The ``sns:GetTopicAttributes`` resource must match the SNS topic you created
in Step 1. You can use a wildcard (``arn:aws:sns:*:*:*``) for broader access
or scope it to your specific topic ARN for least privilege.

Troubleshooting
-----------------

**PermissionError: Missing permissions to manage EventBridge rules**

Your IAM identity needs ``events:PutRule`` and ``events:PutTargets``. Ask your
admin to attach the policy above.

**ValueError: SNS topic not found**

Verify the topic ARN is correct and exists in the same region as your
SageMaker session. Ensure you have ``sns:GetTopicAttributes`` permission.

**Not receiving notifications**

1. Confirm the SNS subscription is in ``Confirmed`` state (check in the Console)
2. Verify the topic policy allows EventBridge to publish (Step 2 above)
3. Check that the ``events`` list includes the status you're waiting for
4 changes: 2 additions & 2 deletions docs/model_customization/nova.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,5 +13,5 @@ Adapt Amazon Nova foundation models to your specific use cases through fine-tuni
:caption: Nova Customization Guides

nova_data_mixing
CPT Training on HyperPod <../../v3-examples/model-customization-examples/cpt_data_mixing_hyperpod>
../../v3-examples/model-customization-examples/sm-studio-nova-training-job-sample-notebook
CPT Training on HyperPod <../../v3-examples/model-customization-examples/serverful/cpt_data_mixing_hyperpod>
Serverless End-to-End Example <../../v3-examples/model-customization-examples/serverless/serverless_e2e_example>
2 changes: 1 addition & 1 deletion docs/model_customization/nova_data_mixing.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -132,4 +132,4 @@ Interactive Notebook
---------------------

For a complete walkthrough, see the
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/nova_data_mixing>`.
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/serverless/nova_data_mixing>`.
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,5 +6,5 @@ This section walks you through the process to get started with open weight model
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/ai_registry_example
../../v3-examples/model-customization-examples/serverless/ai_registry_example
model_customization
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Doc update: reorganize examples folder by zhaoqizqwang · Pull Request #6155 · aws/sagemaker-python-sdk · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/inference/deploy_finetuned.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,4 +7,4 @@ Deploy models that have been fine-tuned through the :doc:`Model Customization <.
:maxdepth:1

Deploy to SageMaker Endpoint <../model_customization/deploy_sagemaker_endpoint>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/bedrock-modelbuilder-deployment>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/deployment/bedrock-modelbuilder-deployment>
8 changes: 4 additions & 4 deletions docs/model_customization/evaluation.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,10 +12,10 @@ Launch evaluation jobs with the following options:
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/llm_as_judge_demo
../../v3-examples/model-customization-examples/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/custom_scorer_demo
../../v3-examples/model-customization-examples/benchmark_demo
../../v3-examples/model-customization-examples/evaluation/llm_as_judge_demo
../../v3-examples/model-customization-examples/evaluation/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/evaluation/custom_scorer_demo
../../v3-examples/model-customization-examples/evaluation/benchmark_demo
../../v3-examples/nova-examples/evaluation-benchmark-and-custom-scorer


Expand Down
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_hyperpod.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,4 +177,4 @@ Interactive Notebook
.. toctree::
:maxdepth:1

../../v3-examples/model-customization-examples/sft_finetuning_hyperpod
../../v3-examples/model-customization-examples/serverful/sft_finetuning_hyperpod
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_serverful.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -138,4 +138,4 @@ Interactive Notebook
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/sft_finetuning_serverful_smtj
../../v3-examples/model-customization-examples/serverful/sft_finetuning_serverful_smtj
1 change: 1 addition & 0 deletions docs/model_customization/index.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,3 +23,4 @@ Key Benefits
open_weight_model_customization
nova
evaluation
notifications_setup
8 changes: 4 additions & 4 deletions docs/model_customization/model_customization.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -196,9 +196,9 @@ Key Features
:maxdepth: 1
:caption: Customization Techniques

SFT Finetuning <../../v3-examples/model-customization-examples/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/rlvr_finetuning_example_notebook_v3_prod>
SFT Finetuning <../../v3-examples/model-customization-examples/serverless/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/serverless/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/serverless/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/serverless/rlvr_finetuning_example_notebook_v3_prod>
Fine-Tuning with Serverful Training Jobs <finetuning_serverful>
Fine-Tuning with HyperPod <finetuning_hyperpod>
250 changes: 250 additions & 0 deletions docs/model_customization/notifications_setup.rst
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
Setting Up Training Job Notifications
========================================

Get notified when your training jobs complete, fail, or stop via SNS email/SMS
alerts. This guide walks through creating the prerequisite SNS topic and
configuring your trainer to send notifications.

Architecture
-------------

.. code-block:: text

SageMaker Training Job ──► EventBridge Rule ──► SNS Topic ──► Email/SMS/Slack

The SDK creates an EventBridge rule that listens for training job status changes
and routes them to your SNS topic. You provide the topic; the SDK handles the
wiring.

Prerequisites
--------------

You need:

1. An SNS topic with a policy allowing EventBridge to publish to it
2. A subscription on that topic (email, SMS, Slack, etc.)
3. IAM permissions for EventBridge rule management (see below)

Step 1: Create an SNS Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → **Create topic**
2. Choose **Standard** type
3. Name it (e.g., ``my-training-alerts``)
4. Click **Create topic**
5. Note the **Topic ARN** (e.g., ``arn:aws:sns:us-east-1:123456789012:my-training-alerts``)

**AWS CLI**

.. code-block:: bash

aws sns create-topic --name my-training-alerts

Step 2: Allow EventBridge to Publish
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The topic needs a resource policy granting EventBridge publish access.

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → open your topic → **Access policy** tab → **Edit**
2. Add this statement to the policy's ``Statement`` array (replace the ARN and
account ID with your own SNS topic ARN and AWS account ID):

.. code-block:: json

{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"Condition": {
"StringEquals": {"AWS:SourceAccount": "123456789012"}
}
}

.. note::

Replace ``arn:aws:sns:us-east-1:123456789012:my-training-alerts`` with your
actual SNS topic ARN, and ``123456789012`` with your AWS account ID. These
must match so that only EventBridge in your account can publish to your topic.

**AWS CLI**

.. code-block:: bash

TOPIC_ARN="arn:aws:sns:us-east-1:123456789012:my-training-alerts"
ACCOUNT_ID="123456789012"

aws sns set-topic-attributes \
--topic-arn $TOPIC_ARN \
--attribute-name Policy \
--attribute-value '{
"Version": "2008-10-17",
"Statement": [{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "'$TOPIC_ARN'",
"Condition": {"StringEquals": {"AWS:SourceAccount": "'$ACCOUNT_ID'"}}
}]
}'

Step 3: Subscribe to the Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Email**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol email \
--notification-endpoint you@example.com

Check your inbox and confirm the subscription.

**SMS**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol sms \
--notification-endpoint +15551234567

Step 4: Use with the SDK
~~~~~~~~~~~~~~~~~~~~~~~~~~

Pass the topic ARN in the ``notifications`` config when constructing your trainer:

.. code-block:: python

from sagemaker.train import SFTTrainer
from sagemaker.train.common import TrainingType
from sagemaker.core.training.configs import TrainingJobCompute

trainer = SFTTrainer(
model="amazon.nova-2-lite-v1",
training_type=TrainingType.LORA,
training_dataset="s3://my-bucket/data/train.jsonl",
compute=TrainingJobCompute(instance_type="ml.p4d.24xlarge"),
notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
},
)

trainer.train()

Configuration Options
~~~~~~~~~~~~~~~~~~~~~~

The ``notifications`` dict supports:

.. list-table::
:header-rows: 1
:widths: 25 10 65

* - Key
- Required
- Description
* - ``sns_topic_arn``
- Yes
- ARN of your SNS topic
* - ``events``
- No
- List of statuses to notify on. Default: ``["Completed", "Failed", "Stopped"]``.
Valid values: ``Completed``, ``Failed``, ``Stopped``, ``InProgress``.
* - ``event_bus_arn``
- No
- Custom EventBridge bus ARN. Defaults to the account's default event bus.
* - ``job_name_prefix``
- No
- Only notify for jobs whose name starts with this prefix.

Example: notify only on failures for jobs matching a prefix:

.. code-block:: python

notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"events": ["Failed"],
"job_name_prefix": "prod-sft-",
}

Managing Notification Rules
-----------------------------

List active rules:

.. code-block:: python

rules = trainer.list_notification_rules()
for rule in rules:
print(f"{rule['name']} ({rule['state']})")

Delete a rule:

.. code-block:: python

trainer.delete_notification_rule(rule_arn="arn:aws:events:us-east-1:123456789012:rule/sm-pysdk-job-notif-abc123")

Required IAM Permissions
--------------------------

The caller (your IAM role or user) needs these permissions. Replace the SNS
resource ARN with your actual topic ARN:

.. code-block:: json

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"events:PutRule",
"events:PutTargets",
"events:ListRules",
"events:ListTargetsByRule",
"events:RemoveTargets",
"events:DeleteRule"
],
"Resource": "arn:aws:events:*:*:rule/sm-pysdk-job-notif-*"
},
{
"Effect": "Allow",
"Action": "sns:GetTopicAttributes",
"Resource": "arn:aws:sns:*:*:my-training-alerts"
}
]
}

.. note::

The ``sns:GetTopicAttributes`` resource must match the SNS topic you created
in Step 1. You can use a wildcard (``arn:aws:sns:*:*:*``) for broader access
or scope it to your specific topic ARN for least privilege.

Troubleshooting
-----------------

**PermissionError: Missing permissions to manage EventBridge rules**

Your IAM identity needs ``events:PutRule`` and ``events:PutTargets``. Ask your
admin to attach the policy above.

**ValueError: SNS topic not found**

Verify the topic ARN is correct and exists in the same region as your
SageMaker session. Ensure you have ``sns:GetTopicAttributes`` permission.

**Not receiving notifications**

1. Confirm the SNS subscription is in ``Confirmed`` state (check in the Console)
2. Verify the topic policy allows EventBridge to publish (Step 2 above)
3. Check that the ``events`` list includes the status you're waiting for
4 changes: 2 additions & 2 deletions docs/model_customization/nova.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,5 +13,5 @@ Adapt Amazon Nova foundation models to your specific use cases through fine-tuni
:caption: Nova Customization Guides

nova_data_mixing
CPT Training on HyperPod <../../v3-examples/model-customization-examples/cpt_data_mixing_hyperpod>
../../v3-examples/model-customization-examples/sm-studio-nova-training-job-sample-notebook
CPT Training on HyperPod <../../v3-examples/model-customization-examples/serverful/cpt_data_mixing_hyperpod>
Serverless End-to-End Example <../../v3-examples/model-customization-examples/serverless/serverless_e2e_example>
2 changes: 1 addition & 1 deletion docs/model_customization/nova_data_mixing.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -132,4 +132,4 @@ Interactive Notebook
---------------------

For a complete walkthrough, see the
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/nova_data_mixing>`.
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/serverless/nova_data_mixing>`.
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,5 +6,5 @@ This section walks you through the process to get started with open weight model
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/ai_registry_example
../../v3-examples/model-customization-examples/serverless/ai_registry_example
model_customization
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Doc update: reorganize examples folder by zhaoqizqwang · Pull Request #6155 · aws/sagemaker-python-sdk · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/inference/deploy_finetuned.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,4 +7,4 @@ Deploy models that have been fine-tuned through the :doc:`Model Customization <.
:maxdepth:1

Deploy to SageMaker Endpoint <../model_customization/deploy_sagemaker_endpoint>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/bedrock-modelbuilder-deployment>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/deployment/bedrock-modelbuilder-deployment>
8 changes: 4 additions & 4 deletions docs/model_customization/evaluation.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,10 +12,10 @@ Launch evaluation jobs with the following options:
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/llm_as_judge_demo
../../v3-examples/model-customization-examples/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/custom_scorer_demo
../../v3-examples/model-customization-examples/benchmark_demo
../../v3-examples/model-customization-examples/evaluation/llm_as_judge_demo
../../v3-examples/model-customization-examples/evaluation/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/evaluation/custom_scorer_demo
../../v3-examples/model-customization-examples/evaluation/benchmark_demo
../../v3-examples/nova-examples/evaluation-benchmark-and-custom-scorer


Expand Down
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_hyperpod.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,4 +177,4 @@ Interactive Notebook
.. toctree::
:maxdepth:1

../../v3-examples/model-customization-examples/sft_finetuning_hyperpod
../../v3-examples/model-customization-examples/serverful/sft_finetuning_hyperpod
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_serverful.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -138,4 +138,4 @@ Interactive Notebook
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/sft_finetuning_serverful_smtj
../../v3-examples/model-customization-examples/serverful/sft_finetuning_serverful_smtj
1 change: 1 addition & 0 deletions docs/model_customization/index.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,3 +23,4 @@ Key Benefits
open_weight_model_customization
nova
evaluation
notifications_setup
8 changes: 4 additions & 4 deletions docs/model_customization/model_customization.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -196,9 +196,9 @@ Key Features
:maxdepth: 1
:caption: Customization Techniques

SFT Finetuning <../../v3-examples/model-customization-examples/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/rlvr_finetuning_example_notebook_v3_prod>
SFT Finetuning <../../v3-examples/model-customization-examples/serverless/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/serverless/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/serverless/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/serverless/rlvr_finetuning_example_notebook_v3_prod>
Fine-Tuning with Serverful Training Jobs <finetuning_serverful>
Fine-Tuning with HyperPod <finetuning_hyperpod>
250 changes: 250 additions & 0 deletions docs/model_customization/notifications_setup.rst
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
Setting Up Training Job Notifications
========================================

Get notified when your training jobs complete, fail, or stop via SNS email/SMS
alerts. This guide walks through creating the prerequisite SNS topic and
configuring your trainer to send notifications.

Architecture
-------------

.. code-block:: text

SageMaker Training Job ──► EventBridge Rule ──► SNS Topic ──► Email/SMS/Slack

The SDK creates an EventBridge rule that listens for training job status changes
and routes them to your SNS topic. You provide the topic; the SDK handles the
wiring.

Prerequisites
--------------

You need:

1. An SNS topic with a policy allowing EventBridge to publish to it
2. A subscription on that topic (email, SMS, Slack, etc.)
3. IAM permissions for EventBridge rule management (see below)

Step 1: Create an SNS Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → **Create topic**
2. Choose **Standard** type
3. Name it (e.g., ``my-training-alerts``)
4. Click **Create topic**
5. Note the **Topic ARN** (e.g., ``arn:aws:sns:us-east-1:123456789012:my-training-alerts``)

**AWS CLI**

.. code-block:: bash

aws sns create-topic --name my-training-alerts

Step 2: Allow EventBridge to Publish
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The topic needs a resource policy granting EventBridge publish access.

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → open your topic → **Access policy** tab → **Edit**
2. Add this statement to the policy's ``Statement`` array (replace the ARN and
account ID with your own SNS topic ARN and AWS account ID):

.. code-block:: json

{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"Condition": {
"StringEquals": {"AWS:SourceAccount": "123456789012"}
}
}

.. note::

Replace ``arn:aws:sns:us-east-1:123456789012:my-training-alerts`` with your
actual SNS topic ARN, and ``123456789012`` with your AWS account ID. These
must match so that only EventBridge in your account can publish to your topic.

**AWS CLI**

.. code-block:: bash

TOPIC_ARN="arn:aws:sns:us-east-1:123456789012:my-training-alerts"
ACCOUNT_ID="123456789012"

aws sns set-topic-attributes \
--topic-arn $TOPIC_ARN \
--attribute-name Policy \
--attribute-value '{
"Version": "2008-10-17",
"Statement": [{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "'$TOPIC_ARN'",
"Condition": {"StringEquals": {"AWS:SourceAccount": "'$ACCOUNT_ID'"}}
}]
}'

Step 3: Subscribe to the Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Email**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol email \
--notification-endpoint you@example.com

Check your inbox and confirm the subscription.

**SMS**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol sms \
--notification-endpoint +15551234567

Step 4: Use with the SDK
~~~~~~~~~~~~~~~~~~~~~~~~~~

Pass the topic ARN in the ``notifications`` config when constructing your trainer:

.. code-block:: python

from sagemaker.train import SFTTrainer
from sagemaker.train.common import TrainingType
from sagemaker.core.training.configs import TrainingJobCompute

trainer = SFTTrainer(
model="amazon.nova-2-lite-v1",
training_type=TrainingType.LORA,
training_dataset="s3://my-bucket/data/train.jsonl",
compute=TrainingJobCompute(instance_type="ml.p4d.24xlarge"),
notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
},
)

trainer.train()

Configuration Options
~~~~~~~~~~~~~~~~~~~~~~

The ``notifications`` dict supports:

.. list-table::
:header-rows: 1
:widths: 25 10 65

* - Key
- Required
- Description
* - ``sns_topic_arn``
- Yes
- ARN of your SNS topic
* - ``events``
- No
- List of statuses to notify on. Default: ``["Completed", "Failed", "Stopped"]``.
Valid values: ``Completed``, ``Failed``, ``Stopped``, ``InProgress``.
* - ``event_bus_arn``
- No
- Custom EventBridge bus ARN. Defaults to the account's default event bus.
* - ``job_name_prefix``
- No
- Only notify for jobs whose name starts with this prefix.

Example: notify only on failures for jobs matching a prefix:

.. code-block:: python

notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"events": ["Failed"],
"job_name_prefix": "prod-sft-",
}

Managing Notification Rules
-----------------------------

List active rules:

.. code-block:: python

rules = trainer.list_notification_rules()
for rule in rules:
print(f"{rule['name']} ({rule['state']})")

Delete a rule:

.. code-block:: python

trainer.delete_notification_rule(rule_arn="arn:aws:events:us-east-1:123456789012:rule/sm-pysdk-job-notif-abc123")

Required IAM Permissions
--------------------------

The caller (your IAM role or user) needs these permissions. Replace the SNS
resource ARN with your actual topic ARN:

.. code-block:: json

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"events:PutRule",
"events:PutTargets",
"events:ListRules",
"events:ListTargetsByRule",
"events:RemoveTargets",
"events:DeleteRule"
],
"Resource": "arn:aws:events:*:*:rule/sm-pysdk-job-notif-*"
},
{
"Effect": "Allow",
"Action": "sns:GetTopicAttributes",
"Resource": "arn:aws:sns:*:*:my-training-alerts"
}
]
}

.. note::

The ``sns:GetTopicAttributes`` resource must match the SNS topic you created
in Step 1. You can use a wildcard (``arn:aws:sns:*:*:*``) for broader access
or scope it to your specific topic ARN for least privilege.

Troubleshooting
-----------------

**PermissionError: Missing permissions to manage EventBridge rules**

Your IAM identity needs ``events:PutRule`` and ``events:PutTargets``. Ask your
admin to attach the policy above.

**ValueError: SNS topic not found**

Verify the topic ARN is correct and exists in the same region as your
SageMaker session. Ensure you have ``sns:GetTopicAttributes`` permission.

**Not receiving notifications**

1. Confirm the SNS subscription is in ``Confirmed`` state (check in the Console)
2. Verify the topic policy allows EventBridge to publish (Step 2 above)
3. Check that the ``events`` list includes the status you're waiting for
4 changes: 2 additions & 2 deletions docs/model_customization/nova.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,5 +13,5 @@ Adapt Amazon Nova foundation models to your specific use cases through fine-tuni
:caption: Nova Customization Guides

nova_data_mixing
CPT Training on HyperPod <../../v3-examples/model-customization-examples/cpt_data_mixing_hyperpod>
../../v3-examples/model-customization-examples/sm-studio-nova-training-job-sample-notebook
CPT Training on HyperPod <../../v3-examples/model-customization-examples/serverful/cpt_data_mixing_hyperpod>
Serverless End-to-End Example <../../v3-examples/model-customization-examples/serverless/serverless_e2e_example>
2 changes: 1 addition & 1 deletion docs/model_customization/nova_data_mixing.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -132,4 +132,4 @@ Interactive Notebook
---------------------

For a complete walkthrough, see the
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/nova_data_mixing>`.
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/serverless/nova_data_mixing>`.
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,5 +6,5 @@ This section walks you through the process to get started with open weight model
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/ai_registry_example
../../v3-examples/model-customization-examples/serverless/ai_registry_example
model_customization
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Doc update: reorganize examples folder by zhaoqizqwang · Pull Request #6155 · aws/sagemaker-python-sdk · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/inference/deploy_finetuned.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,4 +7,4 @@ Deploy models that have been fine-tuned through the :doc:`Model Customization <.
:maxdepth:1

Deploy to SageMaker Endpoint <../model_customization/deploy_sagemaker_endpoint>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/bedrock-modelbuilder-deployment>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/deployment/bedrock-modelbuilder-deployment>
8 changes: 4 additions & 4 deletions docs/model_customization/evaluation.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,10 +12,10 @@ Launch evaluation jobs with the following options:
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/llm_as_judge_demo
../../v3-examples/model-customization-examples/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/custom_scorer_demo
../../v3-examples/model-customization-examples/benchmark_demo
../../v3-examples/model-customization-examples/evaluation/llm_as_judge_demo
../../v3-examples/model-customization-examples/evaluation/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/evaluation/custom_scorer_demo
../../v3-examples/model-customization-examples/evaluation/benchmark_demo
../../v3-examples/nova-examples/evaluation-benchmark-and-custom-scorer


Expand Down
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_hyperpod.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,4 +177,4 @@ Interactive Notebook
.. toctree::
:maxdepth:1

../../v3-examples/model-customization-examples/sft_finetuning_hyperpod
../../v3-examples/model-customization-examples/serverful/sft_finetuning_hyperpod
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_serverful.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -138,4 +138,4 @@ Interactive Notebook
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/sft_finetuning_serverful_smtj
../../v3-examples/model-customization-examples/serverful/sft_finetuning_serverful_smtj
1 change: 1 addition & 0 deletions docs/model_customization/index.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,3 +23,4 @@ Key Benefits
open_weight_model_customization
nova
evaluation
notifications_setup
8 changes: 4 additions & 4 deletions docs/model_customization/model_customization.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -196,9 +196,9 @@ Key Features
:maxdepth: 1
:caption: Customization Techniques

SFT Finetuning <../../v3-examples/model-customization-examples/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/rlvr_finetuning_example_notebook_v3_prod>
SFT Finetuning <../../v3-examples/model-customization-examples/serverless/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/serverless/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/serverless/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/serverless/rlvr_finetuning_example_notebook_v3_prod>
Fine-Tuning with Serverful Training Jobs <finetuning_serverful>
Fine-Tuning with HyperPod <finetuning_hyperpod>
250 changes: 250 additions & 0 deletions docs/model_customization/notifications_setup.rst
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
Setting Up Training Job Notifications
========================================

Get notified when your training jobs complete, fail, or stop via SNS email/SMS
alerts. This guide walks through creating the prerequisite SNS topic and
configuring your trainer to send notifications.

Architecture
-------------

.. code-block:: text

SageMaker Training Job ──► EventBridge Rule ──► SNS Topic ──► Email/SMS/Slack

The SDK creates an EventBridge rule that listens for training job status changes
and routes them to your SNS topic. You provide the topic; the SDK handles the
wiring.

Prerequisites
--------------

You need:

1. An SNS topic with a policy allowing EventBridge to publish to it
2. A subscription on that topic (email, SMS, Slack, etc.)
3. IAM permissions for EventBridge rule management (see below)

Step 1: Create an SNS Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → **Create topic**
2. Choose **Standard** type
3. Name it (e.g., ``my-training-alerts``)
4. Click **Create topic**
5. Note the **Topic ARN** (e.g., ``arn:aws:sns:us-east-1:123456789012:my-training-alerts``)

**AWS CLI**

.. code-block:: bash

aws sns create-topic --name my-training-alerts

Step 2: Allow EventBridge to Publish
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The topic needs a resource policy granting EventBridge publish access.

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → open your topic → **Access policy** tab → **Edit**
2. Add this statement to the policy's ``Statement`` array (replace the ARN and
account ID with your own SNS topic ARN and AWS account ID):

.. code-block:: json

{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"Condition": {
"StringEquals": {"AWS:SourceAccount": "123456789012"}
}
}

.. note::

Replace ``arn:aws:sns:us-east-1:123456789012:my-training-alerts`` with your
actual SNS topic ARN, and ``123456789012`` with your AWS account ID. These
must match so that only EventBridge in your account can publish to your topic.

**AWS CLI**

.. code-block:: bash

TOPIC_ARN="arn:aws:sns:us-east-1:123456789012:my-training-alerts"
ACCOUNT_ID="123456789012"

aws sns set-topic-attributes \
--topic-arn $TOPIC_ARN \
--attribute-name Policy \
--attribute-value '{
"Version": "2008-10-17",
"Statement": [{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "'$TOPIC_ARN'",
"Condition": {"StringEquals": {"AWS:SourceAccount": "'$ACCOUNT_ID'"}}
}]
}'

Step 3: Subscribe to the Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Email**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol email \
--notification-endpoint you@example.com

Check your inbox and confirm the subscription.

**SMS**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol sms \
--notification-endpoint +15551234567

Step 4: Use with the SDK
~~~~~~~~~~~~~~~~~~~~~~~~~~

Pass the topic ARN in the ``notifications`` config when constructing your trainer:

.. code-block:: python

from sagemaker.train import SFTTrainer
from sagemaker.train.common import TrainingType
from sagemaker.core.training.configs import TrainingJobCompute

trainer = SFTTrainer(
model="amazon.nova-2-lite-v1",
training_type=TrainingType.LORA,
training_dataset="s3://my-bucket/data/train.jsonl",
compute=TrainingJobCompute(instance_type="ml.p4d.24xlarge"),
notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
},
)

trainer.train()

Configuration Options
~~~~~~~~~~~~~~~~~~~~~~

The ``notifications`` dict supports:

.. list-table::
:header-rows: 1
:widths: 25 10 65

* - Key
- Required
- Description
* - ``sns_topic_arn``
- Yes
- ARN of your SNS topic
* - ``events``
- No
- List of statuses to notify on. Default: ``["Completed", "Failed", "Stopped"]``.
Valid values: ``Completed``, ``Failed``, ``Stopped``, ``InProgress``.
* - ``event_bus_arn``
- No
- Custom EventBridge bus ARN. Defaults to the account's default event bus.
* - ``job_name_prefix``
- No
- Only notify for jobs whose name starts with this prefix.

Example: notify only on failures for jobs matching a prefix:

.. code-block:: python

notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"events": ["Failed"],
"job_name_prefix": "prod-sft-",
}

Managing Notification Rules
-----------------------------

List active rules:

.. code-block:: python

rules = trainer.list_notification_rules()
for rule in rules:
print(f"{rule['name']} ({rule['state']})")

Delete a rule:

.. code-block:: python

trainer.delete_notification_rule(rule_arn="arn:aws:events:us-east-1:123456789012:rule/sm-pysdk-job-notif-abc123")

Required IAM Permissions
--------------------------

The caller (your IAM role or user) needs these permissions. Replace the SNS
resource ARN with your actual topic ARN:

.. code-block:: json

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"events:PutRule",
"events:PutTargets",
"events:ListRules",
"events:ListTargetsByRule",
"events:RemoveTargets",
"events:DeleteRule"
],
"Resource": "arn:aws:events:*:*:rule/sm-pysdk-job-notif-*"
},
{
"Effect": "Allow",
"Action": "sns:GetTopicAttributes",
"Resource": "arn:aws:sns:*:*:my-training-alerts"
}
]
}

.. note::

The ``sns:GetTopicAttributes`` resource must match the SNS topic you created
in Step 1. You can use a wildcard (``arn:aws:sns:*:*:*``) for broader access
or scope it to your specific topic ARN for least privilege.

Troubleshooting
-----------------

**PermissionError: Missing permissions to manage EventBridge rules**

Your IAM identity needs ``events:PutRule`` and ``events:PutTargets``. Ask your
admin to attach the policy above.

**ValueError: SNS topic not found**

Verify the topic ARN is correct and exists in the same region as your
SageMaker session. Ensure you have ``sns:GetTopicAttributes`` permission.

**Not receiving notifications**

1. Confirm the SNS subscription is in ``Confirmed`` state (check in the Console)
2. Verify the topic policy allows EventBridge to publish (Step 2 above)
3. Check that the ``events`` list includes the status you're waiting for
4 changes: 2 additions & 2 deletions docs/model_customization/nova.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,5 +13,5 @@ Adapt Amazon Nova foundation models to your specific use cases through fine-tuni
:caption: Nova Customization Guides

nova_data_mixing
CPT Training on HyperPod <../../v3-examples/model-customization-examples/cpt_data_mixing_hyperpod>
../../v3-examples/model-customization-examples/sm-studio-nova-training-job-sample-notebook
CPT Training on HyperPod <../../v3-examples/model-customization-examples/serverful/cpt_data_mixing_hyperpod>
Serverless End-to-End Example <../../v3-examples/model-customization-examples/serverless/serverless_e2e_example>
2 changes: 1 addition & 1 deletion docs/model_customization/nova_data_mixing.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -132,4 +132,4 @@ Interactive Notebook
---------------------

For a complete walkthrough, see the
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/nova_data_mixing>`.
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/serverless/nova_data_mixing>`.
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,5 +6,5 @@ This section walks you through the process to get started with open weight model
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/ai_registry_example
../../v3-examples/model-customization-examples/serverless/ai_registry_example
model_customization
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Doc update: reorganize examples folder by zhaoqizqwang · Pull Request #6155 · aws/sagemaker-python-sdk · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/inference/deploy_finetuned.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,4 +7,4 @@ Deploy models that have been fine-tuned through the :doc:`Model Customization <.
:maxdepth:1

Deploy to SageMaker Endpoint <../model_customization/deploy_sagemaker_endpoint>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/bedrock-modelbuilder-deployment>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/deployment/bedrock-modelbuilder-deployment>
8 changes: 4 additions & 4 deletions docs/model_customization/evaluation.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,10 +12,10 @@ Launch evaluation jobs with the following options:
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/llm_as_judge_demo
../../v3-examples/model-customization-examples/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/custom_scorer_demo
../../v3-examples/model-customization-examples/benchmark_demo
../../v3-examples/model-customization-examples/evaluation/llm_as_judge_demo
../../v3-examples/model-customization-examples/evaluation/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/evaluation/custom_scorer_demo
../../v3-examples/model-customization-examples/evaluation/benchmark_demo
../../v3-examples/nova-examples/evaluation-benchmark-and-custom-scorer


Expand Down
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_hyperpod.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,4 +177,4 @@ Interactive Notebook
.. toctree::
:maxdepth:1

../../v3-examples/model-customization-examples/sft_finetuning_hyperpod
../../v3-examples/model-customization-examples/serverful/sft_finetuning_hyperpod
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_serverful.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -138,4 +138,4 @@ Interactive Notebook
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/sft_finetuning_serverful_smtj
../../v3-examples/model-customization-examples/serverful/sft_finetuning_serverful_smtj
1 change: 1 addition & 0 deletions docs/model_customization/index.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,3 +23,4 @@ Key Benefits
open_weight_model_customization
nova
evaluation
notifications_setup
8 changes: 4 additions & 4 deletions docs/model_customization/model_customization.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -196,9 +196,9 @@ Key Features
:maxdepth: 1
:caption: Customization Techniques

SFT Finetuning <../../v3-examples/model-customization-examples/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/rlvr_finetuning_example_notebook_v3_prod>
SFT Finetuning <../../v3-examples/model-customization-examples/serverless/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/serverless/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/serverless/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/serverless/rlvr_finetuning_example_notebook_v3_prod>
Fine-Tuning with Serverful Training Jobs <finetuning_serverful>
Fine-Tuning with HyperPod <finetuning_hyperpod>
250 changes: 250 additions & 0 deletions docs/model_customization/notifications_setup.rst
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
Setting Up Training Job Notifications
========================================

Get notified when your training jobs complete, fail, or stop via SNS email/SMS
alerts. This guide walks through creating the prerequisite SNS topic and
configuring your trainer to send notifications.

Architecture
-------------

.. code-block:: text

SageMaker Training Job ──► EventBridge Rule ──► SNS Topic ──► Email/SMS/Slack

The SDK creates an EventBridge rule that listens for training job status changes
and routes them to your SNS topic. You provide the topic; the SDK handles the
wiring.

Prerequisites
--------------

You need:

1. An SNS topic with a policy allowing EventBridge to publish to it
2. A subscription on that topic (email, SMS, Slack, etc.)
3. IAM permissions for EventBridge rule management (see below)

Step 1: Create an SNS Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → **Create topic**
2. Choose **Standard** type
3. Name it (e.g., ``my-training-alerts``)
4. Click **Create topic**
5. Note the **Topic ARN** (e.g., ``arn:aws:sns:us-east-1:123456789012:my-training-alerts``)

**AWS CLI**

.. code-block:: bash

aws sns create-topic --name my-training-alerts

Step 2: Allow EventBridge to Publish
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The topic needs a resource policy granting EventBridge publish access.

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → open your topic → **Access policy** tab → **Edit**
2. Add this statement to the policy's ``Statement`` array (replace the ARN and
account ID with your own SNS topic ARN and AWS account ID):

.. code-block:: json

{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"Condition": {
"StringEquals": {"AWS:SourceAccount": "123456789012"}
}
}

.. note::

Replace ``arn:aws:sns:us-east-1:123456789012:my-training-alerts`` with your
actual SNS topic ARN, and ``123456789012`` with your AWS account ID. These
must match so that only EventBridge in your account can publish to your topic.

**AWS CLI**

.. code-block:: bash

TOPIC_ARN="arn:aws:sns:us-east-1:123456789012:my-training-alerts"
ACCOUNT_ID="123456789012"

aws sns set-topic-attributes \
--topic-arn $TOPIC_ARN \
--attribute-name Policy \
--attribute-value '{
"Version": "2008-10-17",
"Statement": [{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "'$TOPIC_ARN'",
"Condition": {"StringEquals": {"AWS:SourceAccount": "'$ACCOUNT_ID'"}}
}]
}'

Step 3: Subscribe to the Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Email**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol email \
--notification-endpoint you@example.com

Check your inbox and confirm the subscription.

**SMS**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol sms \
--notification-endpoint +15551234567

Step 4: Use with the SDK
~~~~~~~~~~~~~~~~~~~~~~~~~~

Pass the topic ARN in the ``notifications`` config when constructing your trainer:

.. code-block:: python

from sagemaker.train import SFTTrainer
from sagemaker.train.common import TrainingType
from sagemaker.core.training.configs import TrainingJobCompute

trainer = SFTTrainer(
model="amazon.nova-2-lite-v1",
training_type=TrainingType.LORA,
training_dataset="s3://my-bucket/data/train.jsonl",
compute=TrainingJobCompute(instance_type="ml.p4d.24xlarge"),
notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
},
)

trainer.train()

Configuration Options
~~~~~~~~~~~~~~~~~~~~~~

The ``notifications`` dict supports:

.. list-table::
:header-rows: 1
:widths: 25 10 65

* - Key
- Required
- Description
* - ``sns_topic_arn``
- Yes
- ARN of your SNS topic
* - ``events``
- No
- List of statuses to notify on. Default: ``["Completed", "Failed", "Stopped"]``.
Valid values: ``Completed``, ``Failed``, ``Stopped``, ``InProgress``.
* - ``event_bus_arn``
- No
- Custom EventBridge bus ARN. Defaults to the account's default event bus.
* - ``job_name_prefix``
- No
- Only notify for jobs whose name starts with this prefix.

Example: notify only on failures for jobs matching a prefix:

.. code-block:: python

notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"events": ["Failed"],
"job_name_prefix": "prod-sft-",
}

Managing Notification Rules
-----------------------------

List active rules:

.. code-block:: python

rules = trainer.list_notification_rules()
for rule in rules:
print(f"{rule['name']} ({rule['state']})")

Delete a rule:

.. code-block:: python

trainer.delete_notification_rule(rule_arn="arn:aws:events:us-east-1:123456789012:rule/sm-pysdk-job-notif-abc123")

Required IAM Permissions
--------------------------

The caller (your IAM role or user) needs these permissions. Replace the SNS
resource ARN with your actual topic ARN:

.. code-block:: json

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"events:PutRule",
"events:PutTargets",
"events:ListRules",
"events:ListTargetsByRule",
"events:RemoveTargets",
"events:DeleteRule"
],
"Resource": "arn:aws:events:*:*:rule/sm-pysdk-job-notif-*"
},
{
"Effect": "Allow",
"Action": "sns:GetTopicAttributes",
"Resource": "arn:aws:sns:*:*:my-training-alerts"
}
]
}

.. note::

The ``sns:GetTopicAttributes`` resource must match the SNS topic you created
in Step 1. You can use a wildcard (``arn:aws:sns:*:*:*``) for broader access
or scope it to your specific topic ARN for least privilege.

Troubleshooting
-----------------

**PermissionError: Missing permissions to manage EventBridge rules**

Your IAM identity needs ``events:PutRule`` and ``events:PutTargets``. Ask your
admin to attach the policy above.

**ValueError: SNS topic not found**

Verify the topic ARN is correct and exists in the same region as your
SageMaker session. Ensure you have ``sns:GetTopicAttributes`` permission.

**Not receiving notifications**

1. Confirm the SNS subscription is in ``Confirmed`` state (check in the Console)
2. Verify the topic policy allows EventBridge to publish (Step 2 above)
3. Check that the ``events`` list includes the status you're waiting for
4 changes: 2 additions & 2 deletions docs/model_customization/nova.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,5 +13,5 @@ Adapt Amazon Nova foundation models to your specific use cases through fine-tuni
:caption: Nova Customization Guides

nova_data_mixing
CPT Training on HyperPod <../../v3-examples/model-customization-examples/cpt_data_mixing_hyperpod>
../../v3-examples/model-customization-examples/sm-studio-nova-training-job-sample-notebook
CPT Training on HyperPod <../../v3-examples/model-customization-examples/serverful/cpt_data_mixing_hyperpod>
Serverless End-to-End Example <../../v3-examples/model-customization-examples/serverless/serverless_e2e_example>
2 changes: 1 addition & 1 deletion docs/model_customization/nova_data_mixing.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -132,4 +132,4 @@ Interactive Notebook
---------------------

For a complete walkthrough, see the
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/nova_data_mixing>`.
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/serverless/nova_data_mixing>`.
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,5 +6,5 @@ This section walks you through the process to get started with open weight model
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/ai_registry_example
../../v3-examples/model-customization-examples/serverless/ai_registry_example
model_customization
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Doc update: reorganize examples folder by zhaoqizqwang · Pull Request #6155 · aws/sagemaker-python-sdk · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/inference/deploy_finetuned.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,4 +7,4 @@ Deploy models that have been fine-tuned through the :doc:`Model Customization <.
:maxdepth:1

Deploy to SageMaker Endpoint <../model_customization/deploy_sagemaker_endpoint>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/bedrock-modelbuilder-deployment>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/deployment/bedrock-modelbuilder-deployment>
8 changes: 4 additions & 4 deletions docs/model_customization/evaluation.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,10 +12,10 @@ Launch evaluation jobs with the following options:
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/llm_as_judge_demo
../../v3-examples/model-customization-examples/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/custom_scorer_demo
../../v3-examples/model-customization-examples/benchmark_demo
../../v3-examples/model-customization-examples/evaluation/llm_as_judge_demo
../../v3-examples/model-customization-examples/evaluation/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/evaluation/custom_scorer_demo
../../v3-examples/model-customization-examples/evaluation/benchmark_demo
../../v3-examples/nova-examples/evaluation-benchmark-and-custom-scorer


Expand Down
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_hyperpod.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,4 +177,4 @@ Interactive Notebook
.. toctree::
:maxdepth:1

../../v3-examples/model-customization-examples/sft_finetuning_hyperpod
../../v3-examples/model-customization-examples/serverful/sft_finetuning_hyperpod
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_serverful.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -138,4 +138,4 @@ Interactive Notebook
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/sft_finetuning_serverful_smtj
../../v3-examples/model-customization-examples/serverful/sft_finetuning_serverful_smtj
1 change: 1 addition & 0 deletions docs/model_customization/index.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,3 +23,4 @@ Key Benefits
open_weight_model_customization
nova
evaluation
notifications_setup
8 changes: 4 additions & 4 deletions docs/model_customization/model_customization.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -196,9 +196,9 @@ Key Features
:maxdepth: 1
:caption: Customization Techniques

SFT Finetuning <../../v3-examples/model-customization-examples/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/rlvr_finetuning_example_notebook_v3_prod>
SFT Finetuning <../../v3-examples/model-customization-examples/serverless/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/serverless/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/serverless/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/serverless/rlvr_finetuning_example_notebook_v3_prod>
Fine-Tuning with Serverful Training Jobs <finetuning_serverful>
Fine-Tuning with HyperPod <finetuning_hyperpod>
250 changes: 250 additions & 0 deletions docs/model_customization/notifications_setup.rst
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
Setting Up Training Job Notifications
========================================

Get notified when your training jobs complete, fail, or stop via SNS email/SMS
alerts. This guide walks through creating the prerequisite SNS topic and
configuring your trainer to send notifications.

Architecture
-------------

.. code-block:: text

SageMaker Training Job ──► EventBridge Rule ──► SNS Topic ──► Email/SMS/Slack

The SDK creates an EventBridge rule that listens for training job status changes
and routes them to your SNS topic. You provide the topic; the SDK handles the
wiring.

Prerequisites
--------------

You need:

1. An SNS topic with a policy allowing EventBridge to publish to it
2. A subscription on that topic (email, SMS, Slack, etc.)
3. IAM permissions for EventBridge rule management (see below)

Step 1: Create an SNS Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → **Create topic**
2. Choose **Standard** type
3. Name it (e.g., ``my-training-alerts``)
4. Click **Create topic**
5. Note the **Topic ARN** (e.g., ``arn:aws:sns:us-east-1:123456789012:my-training-alerts``)

**AWS CLI**

.. code-block:: bash

aws sns create-topic --name my-training-alerts

Step 2: Allow EventBridge to Publish
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The topic needs a resource policy granting EventBridge publish access.

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → open your topic → **Access policy** tab → **Edit**
2. Add this statement to the policy's ``Statement`` array (replace the ARN and
account ID with your own SNS topic ARN and AWS account ID):

.. code-block:: json

{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"Condition": {
"StringEquals": {"AWS:SourceAccount": "123456789012"}
}
}

.. note::

Replace ``arn:aws:sns:us-east-1:123456789012:my-training-alerts`` with your
actual SNS topic ARN, and ``123456789012`` with your AWS account ID. These
must match so that only EventBridge in your account can publish to your topic.

**AWS CLI**

.. code-block:: bash

TOPIC_ARN="arn:aws:sns:us-east-1:123456789012:my-training-alerts"
ACCOUNT_ID="123456789012"

aws sns set-topic-attributes \
--topic-arn $TOPIC_ARN \
--attribute-name Policy \
--attribute-value '{
"Version": "2008-10-17",
"Statement": [{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "'$TOPIC_ARN'",
"Condition": {"StringEquals": {"AWS:SourceAccount": "'$ACCOUNT_ID'"}}
}]
}'

Step 3: Subscribe to the Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Email**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol email \
--notification-endpoint you@example.com

Check your inbox and confirm the subscription.

**SMS**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol sms \
--notification-endpoint +15551234567

Step 4: Use with the SDK
~~~~~~~~~~~~~~~~~~~~~~~~~~

Pass the topic ARN in the ``notifications`` config when constructing your trainer:

.. code-block:: python

from sagemaker.train import SFTTrainer
from sagemaker.train.common import TrainingType
from sagemaker.core.training.configs import TrainingJobCompute

trainer = SFTTrainer(
model="amazon.nova-2-lite-v1",
training_type=TrainingType.LORA,
training_dataset="s3://my-bucket/data/train.jsonl",
compute=TrainingJobCompute(instance_type="ml.p4d.24xlarge"),
notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
},
)

trainer.train()

Configuration Options
~~~~~~~~~~~~~~~~~~~~~~

The ``notifications`` dict supports:

.. list-table::
:header-rows: 1
:widths: 25 10 65

* - Key
- Required
- Description
* - ``sns_topic_arn``
- Yes
- ARN of your SNS topic
* - ``events``
- No
- List of statuses to notify on. Default: ``["Completed", "Failed", "Stopped"]``.
Valid values: ``Completed``, ``Failed``, ``Stopped``, ``InProgress``.
* - ``event_bus_arn``
- No
- Custom EventBridge bus ARN. Defaults to the account's default event bus.
* - ``job_name_prefix``
- No
- Only notify for jobs whose name starts with this prefix.

Example: notify only on failures for jobs matching a prefix:

.. code-block:: python

notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"events": ["Failed"],
"job_name_prefix": "prod-sft-",
}

Managing Notification Rules
-----------------------------

List active rules:

.. code-block:: python

rules = trainer.list_notification_rules()
for rule in rules:
print(f"{rule['name']} ({rule['state']})")

Delete a rule:

.. code-block:: python

trainer.delete_notification_rule(rule_arn="arn:aws:events:us-east-1:123456789012:rule/sm-pysdk-job-notif-abc123")

Required IAM Permissions
--------------------------

The caller (your IAM role or user) needs these permissions. Replace the SNS
resource ARN with your actual topic ARN:

.. code-block:: json

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"events:PutRule",
"events:PutTargets",
"events:ListRules",
"events:ListTargetsByRule",
"events:RemoveTargets",
"events:DeleteRule"
],
"Resource": "arn:aws:events:*:*:rule/sm-pysdk-job-notif-*"
},
{
"Effect": "Allow",
"Action": "sns:GetTopicAttributes",
"Resource": "arn:aws:sns:*:*:my-training-alerts"
}
]
}

.. note::

The ``sns:GetTopicAttributes`` resource must match the SNS topic you created
in Step 1. You can use a wildcard (``arn:aws:sns:*:*:*``) for broader access
or scope it to your specific topic ARN for least privilege.

Troubleshooting
-----------------

**PermissionError: Missing permissions to manage EventBridge rules**

Your IAM identity needs ``events:PutRule`` and ``events:PutTargets``. Ask your
admin to attach the policy above.

**ValueError: SNS topic not found**

Verify the topic ARN is correct and exists in the same region as your
SageMaker session. Ensure you have ``sns:GetTopicAttributes`` permission.

**Not receiving notifications**

1. Confirm the SNS subscription is in ``Confirmed`` state (check in the Console)
2. Verify the topic policy allows EventBridge to publish (Step 2 above)
3. Check that the ``events`` list includes the status you're waiting for
4 changes: 2 additions & 2 deletions docs/model_customization/nova.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,5 +13,5 @@ Adapt Amazon Nova foundation models to your specific use cases through fine-tuni
:caption: Nova Customization Guides

nova_data_mixing
CPT Training on HyperPod <../../v3-examples/model-customization-examples/cpt_data_mixing_hyperpod>
../../v3-examples/model-customization-examples/sm-studio-nova-training-job-sample-notebook
CPT Training on HyperPod <../../v3-examples/model-customization-examples/serverful/cpt_data_mixing_hyperpod>
Serverless End-to-End Example <../../v3-examples/model-customization-examples/serverless/serverless_e2e_example>
2 changes: 1 addition & 1 deletion docs/model_customization/nova_data_mixing.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -132,4 +132,4 @@ Interactive Notebook
---------------------

For a complete walkthrough, see the
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/nova_data_mixing>`.
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/serverless/nova_data_mixing>`.
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,5 +6,5 @@ This section walks you through the process to get started with open weight model
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/ai_registry_example
../../v3-examples/model-customization-examples/serverless/ai_registry_example
model_customization
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Doc update: reorganize examples folder by zhaoqizqwang · Pull Request #6155 · aws/sagemaker-python-sdk · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/inference/deploy_finetuned.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,4 +7,4 @@ Deploy models that have been fine-tuned through the :doc:`Model Customization <.
:maxdepth:1

Deploy to SageMaker Endpoint <../model_customization/deploy_sagemaker_endpoint>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/bedrock-modelbuilder-deployment>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/deployment/bedrock-modelbuilder-deployment>
8 changes: 4 additions & 4 deletions docs/model_customization/evaluation.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,10 +12,10 @@ Launch evaluation jobs with the following options:
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/llm_as_judge_demo
../../v3-examples/model-customization-examples/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/custom_scorer_demo
../../v3-examples/model-customization-examples/benchmark_demo
../../v3-examples/model-customization-examples/evaluation/llm_as_judge_demo
../../v3-examples/model-customization-examples/evaluation/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/evaluation/custom_scorer_demo
../../v3-examples/model-customization-examples/evaluation/benchmark_demo
../../v3-examples/nova-examples/evaluation-benchmark-and-custom-scorer


Expand Down
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_hyperpod.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,4 +177,4 @@ Interactive Notebook
.. toctree::
:maxdepth:1

../../v3-examples/model-customization-examples/sft_finetuning_hyperpod
../../v3-examples/model-customization-examples/serverful/sft_finetuning_hyperpod
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_serverful.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -138,4 +138,4 @@ Interactive Notebook
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/sft_finetuning_serverful_smtj
../../v3-examples/model-customization-examples/serverful/sft_finetuning_serverful_smtj
1 change: 1 addition & 0 deletions docs/model_customization/index.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,3 +23,4 @@ Key Benefits
open_weight_model_customization
nova
evaluation
notifications_setup
8 changes: 4 additions & 4 deletions docs/model_customization/model_customization.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -196,9 +196,9 @@ Key Features
:maxdepth: 1
:caption: Customization Techniques

SFT Finetuning <../../v3-examples/model-customization-examples/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/rlvr_finetuning_example_notebook_v3_prod>
SFT Finetuning <../../v3-examples/model-customization-examples/serverless/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/serverless/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/serverless/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/serverless/rlvr_finetuning_example_notebook_v3_prod>
Fine-Tuning with Serverful Training Jobs <finetuning_serverful>
Fine-Tuning with HyperPod <finetuning_hyperpod>
250 changes: 250 additions & 0 deletions docs/model_customization/notifications_setup.rst
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
Setting Up Training Job Notifications
========================================

Get notified when your training jobs complete, fail, or stop via SNS email/SMS
alerts. This guide walks through creating the prerequisite SNS topic and
configuring your trainer to send notifications.

Architecture
-------------

.. code-block:: text

SageMaker Training Job ──► EventBridge Rule ──► SNS Topic ──► Email/SMS/Slack

The SDK creates an EventBridge rule that listens for training job status changes
and routes them to your SNS topic. You provide the topic; the SDK handles the
wiring.

Prerequisites
--------------

You need:

1. An SNS topic with a policy allowing EventBridge to publish to it
2. A subscription on that topic (email, SMS, Slack, etc.)
3. IAM permissions for EventBridge rule management (see below)

Step 1: Create an SNS Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → **Create topic**
2. Choose **Standard** type
3. Name it (e.g., ``my-training-alerts``)
4. Click **Create topic**
5. Note the **Topic ARN** (e.g., ``arn:aws:sns:us-east-1:123456789012:my-training-alerts``)

**AWS CLI**

.. code-block:: bash

aws sns create-topic --name my-training-alerts

Step 2: Allow EventBridge to Publish
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The topic needs a resource policy granting EventBridge publish access.

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → open your topic → **Access policy** tab → **Edit**
2. Add this statement to the policy's ``Statement`` array (replace the ARN and
account ID with your own SNS topic ARN and AWS account ID):

.. code-block:: json

{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"Condition": {
"StringEquals": {"AWS:SourceAccount": "123456789012"}
}
}

.. note::

Replace ``arn:aws:sns:us-east-1:123456789012:my-training-alerts`` with your
actual SNS topic ARN, and ``123456789012`` with your AWS account ID. These
must match so that only EventBridge in your account can publish to your topic.

**AWS CLI**

.. code-block:: bash

TOPIC_ARN="arn:aws:sns:us-east-1:123456789012:my-training-alerts"
ACCOUNT_ID="123456789012"

aws sns set-topic-attributes \
--topic-arn $TOPIC_ARN \
--attribute-name Policy \
--attribute-value '{
"Version": "2008-10-17",
"Statement": [{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "'$TOPIC_ARN'",
"Condition": {"StringEquals": {"AWS:SourceAccount": "'$ACCOUNT_ID'"}}
}]
}'

Step 3: Subscribe to the Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Email**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol email \
--notification-endpoint you@example.com

Check your inbox and confirm the subscription.

**SMS**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol sms \
--notification-endpoint +15551234567

Step 4: Use with the SDK
~~~~~~~~~~~~~~~~~~~~~~~~~~

Pass the topic ARN in the ``notifications`` config when constructing your trainer:

.. code-block:: python

from sagemaker.train import SFTTrainer
from sagemaker.train.common import TrainingType
from sagemaker.core.training.configs import TrainingJobCompute

trainer = SFTTrainer(
model="amazon.nova-2-lite-v1",
training_type=TrainingType.LORA,
training_dataset="s3://my-bucket/data/train.jsonl",
compute=TrainingJobCompute(instance_type="ml.p4d.24xlarge"),
notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
},
)

trainer.train()

Configuration Options
~~~~~~~~~~~~~~~~~~~~~~

The ``notifications`` dict supports:

.. list-table::
:header-rows: 1
:widths: 25 10 65

* - Key
- Required
- Description
* - ``sns_topic_arn``
- Yes
- ARN of your SNS topic
* - ``events``
- No
- List of statuses to notify on. Default: ``["Completed", "Failed", "Stopped"]``.
Valid values: ``Completed``, ``Failed``, ``Stopped``, ``InProgress``.
* - ``event_bus_arn``
- No
- Custom EventBridge bus ARN. Defaults to the account's default event bus.
* - ``job_name_prefix``
- No
- Only notify for jobs whose name starts with this prefix.

Example: notify only on failures for jobs matching a prefix:

.. code-block:: python

notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"events": ["Failed"],
"job_name_prefix": "prod-sft-",
}

Managing Notification Rules
-----------------------------

List active rules:

.. code-block:: python

rules = trainer.list_notification_rules()
for rule in rules:
print(f"{rule['name']} ({rule['state']})")

Delete a rule:

.. code-block:: python

trainer.delete_notification_rule(rule_arn="arn:aws:events:us-east-1:123456789012:rule/sm-pysdk-job-notif-abc123")

Required IAM Permissions
--------------------------

The caller (your IAM role or user) needs these permissions. Replace the SNS
resource ARN with your actual topic ARN:

.. code-block:: json

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"events:PutRule",
"events:PutTargets",
"events:ListRules",
"events:ListTargetsByRule",
"events:RemoveTargets",
"events:DeleteRule"
],
"Resource": "arn:aws:events:*:*:rule/sm-pysdk-job-notif-*"
},
{
"Effect": "Allow",
"Action": "sns:GetTopicAttributes",
"Resource": "arn:aws:sns:*:*:my-training-alerts"
}
]
}

.. note::

The ``sns:GetTopicAttributes`` resource must match the SNS topic you created
in Step 1. You can use a wildcard (``arn:aws:sns:*:*:*``) for broader access
or scope it to your specific topic ARN for least privilege.

Troubleshooting
-----------------

**PermissionError: Missing permissions to manage EventBridge rules**

Your IAM identity needs ``events:PutRule`` and ``events:PutTargets``. Ask your
admin to attach the policy above.

**ValueError: SNS topic not found**

Verify the topic ARN is correct and exists in the same region as your
SageMaker session. Ensure you have ``sns:GetTopicAttributes`` permission.

**Not receiving notifications**

1. Confirm the SNS subscription is in ``Confirmed`` state (check in the Console)
2. Verify the topic policy allows EventBridge to publish (Step 2 above)
3. Check that the ``events`` list includes the status you're waiting for
4 changes: 2 additions & 2 deletions docs/model_customization/nova.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,5 +13,5 @@ Adapt Amazon Nova foundation models to your specific use cases through fine-tuni
:caption: Nova Customization Guides

nova_data_mixing
CPT Training on HyperPod <../../v3-examples/model-customization-examples/cpt_data_mixing_hyperpod>
../../v3-examples/model-customization-examples/sm-studio-nova-training-job-sample-notebook
CPT Training on HyperPod <../../v3-examples/model-customization-examples/serverful/cpt_data_mixing_hyperpod>
Serverless End-to-End Example <../../v3-examples/model-customization-examples/serverless/serverless_e2e_example>
2 changes: 1 addition & 1 deletion docs/model_customization/nova_data_mixing.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -132,4 +132,4 @@ Interactive Notebook
---------------------

For a complete walkthrough, see the
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/nova_data_mixing>`.
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/serverless/nova_data_mixing>`.
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,5 +6,5 @@ This section walks you through the process to get started with open weight model
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/ai_registry_example
../../v3-examples/model-customization-examples/serverless/ai_registry_example
model_customization
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Doc update: reorganize examples folder by zhaoqizqwang · Pull Request #6155 · aws/sagemaker-python-sdk · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/inference/deploy_finetuned.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,4 +7,4 @@ Deploy models that have been fine-tuned through the :doc:`Model Customization <.
:maxdepth:1

Deploy to SageMaker Endpoint <../model_customization/deploy_sagemaker_endpoint>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/bedrock-modelbuilder-deployment>
Deploy to Amazon Bedrock <../../v3-examples/model-customization-examples/deployment/bedrock-modelbuilder-deployment>
8 changes: 4 additions & 4 deletions docs/model_customization/evaluation.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,10 +12,10 @@ Launch evaluation jobs with the following options:
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/llm_as_judge_demo
../../v3-examples/model-customization-examples/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/custom_scorer_demo
../../v3-examples/model-customization-examples/benchmark_demo
../../v3-examples/model-customization-examples/evaluation/llm_as_judge_demo
../../v3-examples/model-customization-examples/evaluation/inspect_ai_evaluation_demo
../../v3-examples/model-customization-examples/evaluation/custom_scorer_demo
../../v3-examples/model-customization-examples/evaluation/benchmark_demo
../../v3-examples/nova-examples/evaluation-benchmark-and-custom-scorer


Expand Down
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_hyperpod.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,4 +177,4 @@ Interactive Notebook
.. toctree::
:maxdepth:1

../../v3-examples/model-customization-examples/sft_finetuning_hyperpod
../../v3-examples/model-customization-examples/serverful/sft_finetuning_hyperpod
2 changes: 1 addition & 1 deletion docs/model_customization/finetuning_serverful.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -138,4 +138,4 @@ Interactive Notebook
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/sft_finetuning_serverful_smtj
../../v3-examples/model-customization-examples/serverful/sft_finetuning_serverful_smtj
1 change: 1 addition & 0 deletions docs/model_customization/index.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,3 +23,4 @@ Key Benefits
open_weight_model_customization
nova
evaluation
notifications_setup
8 changes: 4 additions & 4 deletions docs/model_customization/model_customization.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -196,9 +196,9 @@ Key Features
:maxdepth: 1
:caption: Customization Techniques

SFT Finetuning <../../v3-examples/model-customization-examples/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/rlvr_finetuning_example_notebook_v3_prod>
SFT Finetuning <../../v3-examples/model-customization-examples/serverless/sft_finetuning_example_notebook_pysdk_prod_v3>
DPOTrainer Finetuning <../../v3-examples/model-customization-examples/serverless/dpo_trainer_example_notebook_v3_prod>
RLAIF Finetuning <../../v3-examples/model-customization-examples/serverless/rlaif_finetuning_example_notebook_v3_prod>
RLVR Finetuning <../../v3-examples/model-customization-examples/serverless/rlvr_finetuning_example_notebook_v3_prod>
Fine-Tuning with Serverful Training Jobs <finetuning_serverful>
Fine-Tuning with HyperPod <finetuning_hyperpod>
250 changes: 250 additions & 0 deletions docs/model_customization/notifications_setup.rst
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
Setting Up Training Job Notifications
========================================

Get notified when your training jobs complete, fail, or stop via SNS email/SMS
alerts. This guide walks through creating the prerequisite SNS topic and
configuring your trainer to send notifications.

Architecture
-------------

.. code-block:: text

SageMaker Training Job ──► EventBridge Rule ──► SNS Topic ──► Email/SMS/Slack

The SDK creates an EventBridge rule that listens for training job status changes
and routes them to your SNS topic. You provide the topic; the SDK handles the
wiring.

Prerequisites
--------------

You need:

1. An SNS topic with a policy allowing EventBridge to publish to it
2. A subscription on that topic (email, SMS, Slack, etc.)
3. IAM permissions for EventBridge rule management (see below)

Step 1: Create an SNS Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → **Create topic**
2. Choose **Standard** type
3. Name it (e.g., ``my-training-alerts``)
4. Click **Create topic**
5. Note the **Topic ARN** (e.g., ``arn:aws:sns:us-east-1:123456789012:my-training-alerts``)

**AWS CLI**

.. code-block:: bash

aws sns create-topic --name my-training-alerts

Step 2: Allow EventBridge to Publish
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The topic needs a resource policy granting EventBridge publish access.

**AWS Console**

1. Go to **Amazon SNS** → **Topics** → open your topic → **Access policy** tab → **Edit**
2. Add this statement to the policy's ``Statement`` array (replace the ARN and
account ID with your own SNS topic ARN and AWS account ID):

.. code-block:: json

{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"Condition": {
"StringEquals": {"AWS:SourceAccount": "123456789012"}
}
}

.. note::

Replace ``arn:aws:sns:us-east-1:123456789012:my-training-alerts`` with your
actual SNS topic ARN, and ``123456789012`` with your AWS account ID. These
must match so that only EventBridge in your account can publish to your topic.

**AWS CLI**

.. code-block:: bash

TOPIC_ARN="arn:aws:sns:us-east-1:123456789012:my-training-alerts"
ACCOUNT_ID="123456789012"

aws sns set-topic-attributes \
--topic-arn $TOPIC_ARN \
--attribute-name Policy \
--attribute-value '{
"Version": "2008-10-17",
"Statement": [{
"Sid": "AllowEventBridgePublish",
"Effect": "Allow",
"Principal": {"Service": "events.amazonaws.com"},
"Action": "SNS:Publish",
"Resource": "'$TOPIC_ARN'",
"Condition": {"StringEquals": {"AWS:SourceAccount": "'$ACCOUNT_ID'"}}
}]
}'

Step 3: Subscribe to the Topic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Email**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol email \
--notification-endpoint you@example.com

Check your inbox and confirm the subscription.

**SMS**

.. code-block:: bash

aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-training-alerts \
--protocol sms \
--notification-endpoint +15551234567

Step 4: Use with the SDK
~~~~~~~~~~~~~~~~~~~~~~~~~~

Pass the topic ARN in the ``notifications`` config when constructing your trainer:

.. code-block:: python

from sagemaker.train import SFTTrainer
from sagemaker.train.common import TrainingType
from sagemaker.core.training.configs import TrainingJobCompute

trainer = SFTTrainer(
model="amazon.nova-2-lite-v1",
training_type=TrainingType.LORA,
training_dataset="s3://my-bucket/data/train.jsonl",
compute=TrainingJobCompute(instance_type="ml.p4d.24xlarge"),
notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
},
)

trainer.train()

Configuration Options
~~~~~~~~~~~~~~~~~~~~~~

The ``notifications`` dict supports:

.. list-table::
:header-rows: 1
:widths: 25 10 65

* - Key
- Required
- Description
* - ``sns_topic_arn``
- Yes
- ARN of your SNS topic
* - ``events``
- No
- List of statuses to notify on. Default: ``["Completed", "Failed", "Stopped"]``.
Valid values: ``Completed``, ``Failed``, ``Stopped``, ``InProgress``.
* - ``event_bus_arn``
- No
- Custom EventBridge bus ARN. Defaults to the account's default event bus.
* - ``job_name_prefix``
- No
- Only notify for jobs whose name starts with this prefix.

Example: notify only on failures for jobs matching a prefix:

.. code-block:: python

notifications={
"sns_topic_arn": "arn:aws:sns:us-east-1:123456789012:my-training-alerts",
"events": ["Failed"],
"job_name_prefix": "prod-sft-",
}

Managing Notification Rules
-----------------------------

List active rules:

.. code-block:: python

rules = trainer.list_notification_rules()
for rule in rules:
print(f"{rule['name']} ({rule['state']})")

Delete a rule:

.. code-block:: python

trainer.delete_notification_rule(rule_arn="arn:aws:events:us-east-1:123456789012:rule/sm-pysdk-job-notif-abc123")

Required IAM Permissions
--------------------------

The caller (your IAM role or user) needs these permissions. Replace the SNS
resource ARN with your actual topic ARN:

.. code-block:: json

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"events:PutRule",
"events:PutTargets",
"events:ListRules",
"events:ListTargetsByRule",
"events:RemoveTargets",
"events:DeleteRule"
],
"Resource": "arn:aws:events:*:*:rule/sm-pysdk-job-notif-*"
},
{
"Effect": "Allow",
"Action": "sns:GetTopicAttributes",
"Resource": "arn:aws:sns:*:*:my-training-alerts"
}
]
}

.. note::

The ``sns:GetTopicAttributes`` resource must match the SNS topic you created
in Step 1. You can use a wildcard (``arn:aws:sns:*:*:*``) for broader access
or scope it to your specific topic ARN for least privilege.

Troubleshooting
-----------------

**PermissionError: Missing permissions to manage EventBridge rules**

Your IAM identity needs ``events:PutRule`` and ``events:PutTargets``. Ask your
admin to attach the policy above.

**ValueError: SNS topic not found**

Verify the topic ARN is correct and exists in the same region as your
SageMaker session. Ensure you have ``sns:GetTopicAttributes`` permission.

**Not receiving notifications**

1. Confirm the SNS subscription is in ``Confirmed`` state (check in the Console)
2. Verify the topic policy allows EventBridge to publish (Step 2 above)
3. Check that the ``events`` list includes the status you're waiting for
4 changes: 2 additions & 2 deletions docs/model_customization/nova.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,5 +13,5 @@ Adapt Amazon Nova foundation models to your specific use cases through fine-tuni
:caption: Nova Customization Guides

nova_data_mixing
CPT Training on HyperPod <../../v3-examples/model-customization-examples/cpt_data_mixing_hyperpod>
../../v3-examples/model-customization-examples/sm-studio-nova-training-job-sample-notebook
CPT Training on HyperPod <../../v3-examples/model-customization-examples/serverful/cpt_data_mixing_hyperpod>
Serverless End-to-End Example <../../v3-examples/model-customization-examples/serverless/serverless_e2e_example>
2 changes: 1 addition & 1 deletion docs/model_customization/nova_data_mixing.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -132,4 +132,4 @@ Interactive Notebook
---------------------

For a complete walkthrough, see the
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/nova_data_mixing>`.
:doc:`Data Mixing notebook <../../v3-examples/model-customization-examples/serverless/nova_data_mixing>`.
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,5 +6,5 @@ This section walks you through the process to get started with open weight model
.. toctree::
:maxdepth: 1

../../v3-examples/model-customization-examples/ai_registry_example
../../v3-examples/model-customization-examples/serverless/ai_registry_example
model_customization
Loading