Uh oh!
There was an error while loading. Please reload this page.
- 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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f518d9063757027ed136ebb7028dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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: | ||
Uh oh!
There was an error while loading. Please reload this page.
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