-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feature: support training inputs from EFS and FSx #991
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
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1efd696
feature: add FileSystemInput class and unit tests
caxiaohu 5b60c0c
Feature: Add FileSystemRecordSet class and a unit test
caxiaohu 1d769ff
change: fix 1p algorithm HPO with two channel data sets issue
caxiaohu 60bd406
feature: add documentation for efs and fsx
caxiaohu 52fda98
Feature: add utility functions for file system input setup and integr…
caxiaohu b6d65e9
Feature: add kmeans with efs and fsx data sources
caxiaohu d9ae029
Merge branch 'master' into file-system-support
laurenyu ed95870
fix doc spacing
laurenyu c59cca3
fix license headers
laurenyu ad18484
Merge branch 'master' into file-system-support
laurenyu 82c9694
Address pylint errors and update boto3 version
laurenyu 2fc6177
fix vpc util functions
laurenyu 7bf0794
fix vpc util functions
laurenyu 6603093
remove "test_" from util file name so that it doesn't interfere with …
laurenyu 176d3b5
fix efs path
laurenyu 3eef050
try not creating a different VPC
laurenyu 5da97b5
fix error handling
laurenyu d4503c2
fix error handling
laurenyu 62c1a97
undo vpc name experiment
laurenyu 8b42f13
address PR comments and OSError for reading stdin
laurenyu 89a8f90
fix kmeans efs path
laurenyu 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is | ||
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
"""Amazon SageMaker channel configurations for S3 data sources and file system data sources""" | ||
from __future__ import absolute_import, print_function | ||
|
||
FILE_SYSTEM_TYPES = ["FSxLustre", "EFS"] | ||
FILE_SYSTEM_ACCESS_MODES = ["ro", "rw"] | ||
|
||
|
||
class s3_input(object): | ||
"""Amazon SageMaker channel configurations for S3 data sources. | ||
|
||
Attributes: | ||
config (dict[str, dict]): A SageMaker ``DataSource`` referencing | ||
a SageMaker ``S3DataSource``. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
s3_data, | ||
distribution="FullyReplicated", | ||
compression=None, | ||
content_type=None, | ||
record_wrapping=None, | ||
s3_data_type="S3Prefix", | ||
input_mode=None, | ||
attribute_names=None, | ||
shuffle_config=None, | ||
): | ||
"""Create a definition for input data used by an SageMaker training job. | ||
See AWS documentation on the ``CreateTrainingJob`` API for more details on the parameters. | ||
|
||
Args: | ||
s3_data (str): Defines the location of s3 data to train on. | ||
distribution (str): Valid values: 'FullyReplicated', 'ShardedByS3Key' | ||
(default: 'FullyReplicated'). | ||
compression (str): Valid values: 'Gzip', None (default: None). This is used only in | ||
Pipe input mode. | ||
content_type (str): MIME type of the input data (default: None). | ||
record_wrapping (str): Valid values: 'RecordIO' (default: None). | ||
s3_data_type (str): Valid values: 'S3Prefix', 'ManifestFile', 'AugmentedManifestFile'. | ||
If 'S3Prefix', ``s3_data`` defines a prefix of s3 objects to train on. | ||
All objects with s3 keys beginning with ``s3_data`` will be used to train. | ||
If 'ManifestFile' or 'AugmentedManifestFile', then ``s3_data`` defines a | ||
single S3 manifest file or augmented manifest file (respectively), | ||
listing the S3 data to train on. Both the ManifestFile and | ||
AugmentedManifestFile formats are described in the SageMaker API documentation: | ||
https://docs.aws.amazon.com/sagemaker/latest/dg/API_S3DataSource.html | ||
input_mode (str): Optional override for this channel's input mode (default: None). | ||
By default, channels will use the input mode defined on | ||
``sagemaker.estimator.EstimatorBase.input_mode``, but they will ignore | ||
that setting if this parameter is set. | ||
|
||
* None - Amazon SageMaker will use the input mode specified in the ``Estimator`` | ||
* 'File' - Amazon SageMaker copies the training dataset from the S3 location to | ||
a local directory. | ||
* 'Pipe' - Amazon SageMaker streams data directly from S3 to the container via | ||
a Unix-named pipe. | ||
|
||
attribute_names (list[str]): A list of one or more attribute names to use that are | ||
found in a specified AugmentedManifestFile. | ||
shuffle_config (ShuffleConfig): If specified this configuration enables shuffling on | ||
this channel. See the SageMaker API documentation for more info: | ||
https://docs.aws.amazon.com/sagemaker/latest/dg/API_ShuffleConfig.html | ||
""" | ||
|
||
self.config = { | ||
"DataSource": { | ||
"S3DataSource": { | ||
"S3DataDistributionType": distribution, | ||
"S3DataType": s3_data_type, | ||
"S3Uri": s3_data, | ||
} | ||
} | ||
} | ||
|
||
if compression is not None: | ||
self.config["CompressionType"] = compression | ||
if content_type is not None: | ||
self.config["ContentType"] = content_type | ||
if record_wrapping is not None: | ||
self.config["RecordWrapperType"] = record_wrapping | ||
if input_mode is not None: | ||
self.config["InputMode"] = input_mode | ||
if attribute_names is not None: | ||
self.config["DataSource"]["S3DataSource"]["AttributeNames"] = attribute_names | ||
if shuffle_config is not None: | ||
self.config["ShuffleConfig"] = {"Seed": shuffle_config.seed} | ||
|
||
|
||
class FileSystemInput(object): | ||
"""Amazon SageMaker channel configurations for file system data sources. | ||
|
||
Attributes: | ||
config (dict[str, dict]): A Sagemaker File System ``DataSource``. | ||
""" | ||
|
||
def __init__( | ||
self, file_system_id, file_system_type, directory_path, file_system_access_mode="ro" | ||
): | ||
"""Create a new file system input used by an SageMaker training job. | ||
|
||
Args: | ||
file_system_id (str): An Amazon file system ID starting with 'fs-'. | ||
file_system_type (str): The type of file system used for the input. | ||
Valid values: 'EFS', 'FSxLustre'. | ||
directory_path (str): Relative path to the root directory (mount point) in | ||
the file system. | ||
Reference: https://docs.aws.amazon.com/efs/latest/ug/mounting-fs.html and | ||
https://docs.aws.amazon.com/fsx/latest/LustreGuide/mount-fs-auto-mount-onreboot.html | ||
file_system_access_mode (str): Permissions for read and write. | ||
Valid values: 'ro' or 'rw'. Defaults to 'ro'. | ||
""" | ||
|
||
if file_system_type not in FILE_SYSTEM_TYPES: | ||
raise ValueError( | ||
"Unrecognized file system type: %s. Valid values: %s." | ||
% (file_system_type, ", ".join(FILE_SYSTEM_TYPES)) | ||
) | ||
|
||
if file_system_access_mode not in FILE_SYSTEM_ACCESS_MODES: | ||
raise ValueError( | ||
"Unrecognized file system access mode: %s. Valid values: %s." | ||
% (file_system_access_mode, ", ".join(FILE_SYSTEM_ACCESS_MODES)) | ||
) | ||
|
||
self.config = { | ||
"DataSource": { | ||
"FileSystemDataSource": { | ||
"FileSystemId": file_system_id, | ||
"FileSystemType": file_system_type, | ||
"DirectoryPath": directory_path, | ||
"FileSystemAccessMode": file_system_access_mode, | ||
} | ||
} | ||
} |
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.
[Minor] Can these be written as one-liners with "or"?
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.
not exactly sure what you're suggesting here. are you thinking
self.config["CompressionType"] = compression or None
?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.
That's what I was thinking. Am I missing something that would make that incorrect?
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.
boto3 may complain about parameters being set to
None
. The error will be something like "incorrect parameter type <NoneType>, should be one of: <str>"