Skip to content

Commit 405117f

Browse files
martinRenouakrishna1995
authored andcommitted
Change: Allow extra_args to be passed to uploader
1 parent 1d6ba0e commit 405117f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/sagemaker/experiments/_helper.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,15 @@ def __init__(
5959
self.artifact_prefix = artifact_prefix
6060
self._s3_client = self.sagemaker_session.boto_session.client("s3")
6161

62-
def upload_artifact(self, file_path):
62+
def upload_artifact(self, file_path, extra_args=None):
6363
"""Upload an artifact file to S3.
6464
6565
Args:
6666
file_path (str): the file path of the artifact
67+
extra_args (dict): Optional extra arguments that may be passed to the upload operation.
68+
Similar to ExtraArgs parameter in S3 upload_file function. Please refer to the
69+
ExtraArgs parameter documentation here:
70+
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-uploading-files.html#the-extraargs-parameter
6771
6872
Returns:
6973
(str, str): The s3 URI of the uploaded file and the etag of the file.
@@ -91,7 +95,12 @@ def upload_artifact(self, file_path):
9195
artifact_s3_key = "{}/{}/{}".format(
9296
self.artifact_prefix, self.trial_component_name, artifact_name
9397
)
94-
self._s3_client.upload_file(file_path, self.artifact_bucket, artifact_s3_key)
98+
self._s3_client.upload_file(
99+
file_path,
100+
self.artifact_bucket,
101+
artifact_s3_key,
102+
ExtraArgs=extra_args,
103+
)
95104
etag = self._try_get_etag(artifact_s3_key)
96105
return "s3://{}/{}".format(self.artifact_bucket, artifact_s3_key), etag
97106

src/sagemaker/experiments/run.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,8 @@ def log_file(
503503
file_path: str,
504504
name: Optional[str] = None,
505505
media_type: Optional[str] = None,
506-
is_output: bool = True,
506+
is_output: Optional[bool] = True,
507+
extra_args: Optional[dict] = None,
507508
):
508509
"""Upload a file to s3 and store it as an input/output artifact in this run.
509510
@@ -516,11 +517,15 @@ def log_file(
516517
is_output (bool): Determines direction of association to the
517518
run. Defaults to True (output artifact).
518519
If set to False then represented as input association.
520+
extra_args (dict): Optional extra arguments that may be passed to the upload operation.
521+
Similar to ExtraArgs parameter in S3 upload_file function. Please refer to the
522+
ExtraArgs parameter documentation here:
523+
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-uploading-files.html#the-extraargs-parameter
519524
"""
520525
self._verify_trial_component_artifacts_length(is_output)
521526
media_type = media_type or guess_media_type(file_path)
522527
name = name or resolve_artifact_name(file_path)
523-
s3_uri, _ = self._artifact_uploader.upload_artifact(file_path)
528+
s3_uri, _ = self._artifact_uploader.upload_artifact(file_path, extra_args=extra_args)
524529
if is_output:
525530
self._trial_component.output_artifacts[name] = TrialComponentArtifact(
526531
value=s3_uri, media_type=media_type

0 commit comments

Comments
 (0)