-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(train): add dry_run=True to train() #6027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mujtaba1747
merged 4 commits into
aws:master-nova-follow-ups
from
amazeAmazing:feature/dry-run-validation
Jul 20, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f518d90
feat(train): add dry_run=True to train()
amazeAmazing 6375702
feat(evaluate): add dry_run=True to evaluate()
amazeAmazing 7ed136e
fix(dry_run): support DataSet objects, deduplicate ARN validation, ex…
amazeAmazing bb7028d
fix(dry_run): support all AWS partitions in DataSet ARN validation
amazeAmazing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,117 @@ def load_file_content( | |
| raise FileLoadError(f"Failed to read file {file_path}: {e}") | ||
|
|
||
|
|
||
| def validate_data_path_exists( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will have to check this but some trainers may also support a Dataset object. In that case the arn is stored as dataset.arn. |
||
| data_path: Union[str, "DataSet"], | ||
| sagemaker_session, | ||
| label: str = "data", | ||
| ) -> None: | ||
| """Validate that a data path (S3 URI, dataset ARN, or DataSet object) exists and is accessible. | ||
|
|
||
| Called inline during dry_run to catch bad paths before job submission. | ||
|
|
||
| Args: | ||
| data_path: S3 URI, SageMaker hub-content DataSet ARN, or DataSet object to validate. | ||
| sagemaker_session: SageMaker session (provides boto_session). | ||
| label: Human-readable label for error messages. | ||
|
|
||
| Raises: | ||
| ValueError: If the path does not exist or is inaccessible. | ||
| """ | ||
| # Handle DataSet objects — extract the ARN for validation | ||
| if isinstance(data_path, DataSet): | ||
| data_path = data_path.arn | ||
|
|
||
| # Handle SageMaker hub-content DataSet ARNs | ||
| if re.match(r"^arn:aws(?:-[a-z]+)*:sagemaker:.+/DataSet/", data_path): | ||
| _validate_dataset_arn_exists(data_path, sagemaker_session, label=label) | ||
| return | ||
|
|
||
| # Handle S3 URIs | ||
| parts = _parse_s3_uri(data_path) | ||
| if parts is None: | ||
| raise ValueError( | ||
| f"Invalid {label} path format: {data_path}. " | ||
| f"Expected an S3 URI (s3://bucket/key) or a DataSet ARN." | ||
| ) | ||
|
|
||
| bucket, key = parts | ||
| s3 = sagemaker_session.boto_session.client("s3") | ||
|
|
||
| try: | ||
| resp = s3.list_objects_v2(Bucket=bucket, Prefix=key, MaxKeys=1) | ||
| if resp.get("KeyCount", 0) == 0: | ||
| raise ValueError( | ||
| f"S3 {label} path does not exist: {data_path}" | ||
| ) | ||
| except ClientError as e: | ||
| code = e.response["Error"]["Code"] | ||
| if code == "403" or "AccessDenied" in str(e): | ||
| # Caller may not have access but the execution role might — | ||
| # log a warning and allow the job to proceed. | ||
| logger.warning( | ||
| "Cannot verify S3 %s path %s from caller identity " | ||
| "(AccessDenied). The execution role may still have access.", | ||
| label, data_path, | ||
| ) | ||
| else: | ||
| raise ValueError(f"Error accessing S3 {label} path {data_path}: {e}") | ||
|
|
||
|
|
||
| def _validate_dataset_arn_exists( | ||
| dataset_arn: str, | ||
| sagemaker_session, | ||
| label: str = "data", | ||
| ) -> None: | ||
| """Validate that a SageMaker hub-content DataSet ARN exists. | ||
|
|
||
| Args: | ||
| dataset_arn: ARN like arn:aws:sagemaker:<region>:<account>:hub-content/<hub>/DataSet/<name>/<version> | ||
| sagemaker_session: SageMaker session (provides boto_session). | ||
| label: Human-readable label for error messages. | ||
|
|
||
| Raises: | ||
| ValueError: If the dataset ARN cannot be described. | ||
| """ | ||
|
|
||
| pattern = ( | ||
| r"^arn:aws(?:-[a-z]+)*:sagemaker:([^:]+):(\d+):hub-content/" | ||
| r"([^/]+)/DataSet/([^/]+)/([\d\.]+)$" | ||
| ) | ||
| match = re.match(pattern, dataset_arn) | ||
| if not match: | ||
| raise ValueError( | ||
| f"Invalid {label} DataSet ARN format: {dataset_arn}" | ||
| ) | ||
|
|
||
| region, _, hub_name, content_name, content_version = match.groups() | ||
| sm_client = sagemaker_session.sagemaker_client | ||
|
|
||
| try: | ||
| sm_client.describe_hub_content( | ||
| HubName=hub_name, | ||
| HubContentType="DataSet", | ||
| HubContentName=content_name, | ||
| HubContentVersion=content_version, | ||
| ) | ||
| except ClientError as e: | ||
| code = e.response["Error"]["Code"] | ||
| if code == "ResourceNotFound" or "does not exist" in str(e).lower(): | ||
| raise ValueError( | ||
| f"{label.capitalize()} DataSet does not exist: {dataset_arn}" | ||
| ) | ||
| elif code == "AccessDeniedException" or "AccessDenied" in str(e): | ||
| logger.warning( | ||
| "Cannot verify %s DataSet %s from caller identity " | ||
| "(AccessDenied). The execution role may still have access.", | ||
| label, dataset_arn, | ||
| ) | ||
| else: | ||
| raise ValueError( | ||
| f"Error validating {label} DataSet {dataset_arn}: {e}" | ||
| ) | ||
|
|
||
|
|
||
| def _has_multimodal_content(record: dict) -> bool: | ||
| """Check if a single record contains multimodal content.""" | ||
| if "messages" not in record: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why didn't we add dry_run feature to Model trainer class. Customers can submit training jobs using model_trainer directly as well? I'm ok with not adding it if there's a good reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the callout - will make the change! That was a miss on my part