-
Notifications
You must be signed in to change notification settings - Fork 0
Support backward compatibility #6
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
Support backward compatibility #6
Conversation
src/sagemaker_containers/encoders.py
Outdated
| return np.load(stream).astype(dtype) | ||
|
|
||
|
|
||
| def unicode_to_str(string_like): # type: (str or unicode) -> str |
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.
do we really need this? why not limit support to utf-8 only?
if we do need other charsets (and I think we don't):
- why 'unicode_to_str' for something that handles non-unicode charsets?
- this function is called after we check content is in 'UTF8_TYPES', so if this is needed, we have a mistake in worker.py
- why just latin1?
- guessing == mojibake. let's use charset from Content-Type header to get it right.
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.
Talked with @jesterhazy offline. We will remove it.
| resource_config = read_resource_config() | ||
| current_host = resource_config['current_host'] | ||
| hosts = resource_config['hosts'] | ||
| network_interface_name = resource_config.get('network_interface_name', 'ethwe') |
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.
is it safe to have a (non-None) default for this?
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.
This isn't actually added to resourceconfig yet, but the network interface name is needed for distributed training. As I see it, the choice is having a default here vs. having a default downstream and changing the value once this value changes.
src/sagemaker_containers/env.py
Outdated
| For example, `["algo-1", "algo-2", "algo-3"]` for a three-node cluster. | ||
| Returns: | ||
| list[str]: all the hosts in the training network. | ||
| (list[str]): all the hosts in the training network. |
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.
(<type>) is not google doc style for return values (even though it is for args)
src/sagemaker_containers/encoders.py
Outdated
| """ | ||
| stream = BytesIO(npy_array) | ||
| return np.load(stream) | ||
| return np.load(stream).astype(dtype) |
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.
I don't think we should do astype(dtype), at least not with np.float32 instead of none. The dtype is serialized with the data -- we should default to that.
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.
+1
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.
I agree. Thanks guys
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.
Removed
src/sagemaker_containers/encoders.py
Outdated
| try: | ||
| return string_like.decode('utf-8') | ||
| finally: | ||
| return string_like.decode('latin1') |
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.
This will always return string_like.decode('latin1'). I think this should be try: return utf-8, catch some exception, return latin1.
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.
true.
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.
removed
src/sagemaker_containers/encoders.py
Outdated
| """Convert an NPY array into numpy. | ||
| Args: | ||
| dtype (dtype, optional): Data type of the resulting array. |
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.
Should the docstrings for the args be reversed to match the function signature?
Same for other serializers.
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.
Good call. I will do it.
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.
done
src/sagemaker_containers/encoders.py
Outdated
| data = json.loads(string) | ||
| return np.array(data) | ||
| data = json.loads(unicode_to_str(string_like)) | ||
| return np.array(data).astype(dtype=dtype) |
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.
You can also pass in the dtype to np.array.
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.
^^ but it works slightly differently. i.e. constructor arg won't downcast, but astype will.
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.
So we will only allow, upcast? Is that the decision here?
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.
Leaving as-is is fine with me
test/unit/test_encoder.py
Outdated
| @patch('numpy.load', lambda x: 'loaded %s' % x) | ||
| @patch('numpy.load', lambda x: np.array([42])) | ||
| @patch('sagemaker_containers.encoders.BytesIO', lambda x: 'byte io %s' % x) | ||
| def test_npy_to_numpy(): |
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.
Could you test deserialization of other dtypes? The dtypes of the serialized numpy array and deserialized numpy array should match.
Support to requirements.txt file
* add container support code (#1) * Add missing test dependencies to setup.py (#2) * Add entry.py as script in setup.py so it can be invoked from our images (#3) * Add data_files to setup.py to copy nginx config correctly + fix install_requires (#4) * Move dependencies from extras_require to install_requires * Copy in change from internal repo: support pip install requirements.txt (#5) * Use package_data instead of data_files to package config files, refer to (#6) * Add missing conf files (accidentally left out of previous commit) (aws#8) * pip install requirements in training container (aws#11) * Use container exit code to exit Trainer process. (aws#9) * Add gunicorn and gevent as setup.py dependencies (aws#13) * Specify version ranges for install_requires dependencies * Add Apache license headers (aws#14) * Add changelog (aws#15) * Bump version to 1.0.0 (aws#16) * Fix year in license headers (aws#18) * Add README description (aws#20) * Update version to 1.0.1 (aws#21) * Read new TRAINING_JOB_NAME environment variable during training (aws#34) * Bump version to 1.0.2 and update Changelog (aws#37) * Move processing of requirements file out to the specific container. (aws#39) * Bump version to 1.0.3 and update Changelog (aws#42) * Change module name to string in __all__ (aws#50) * Hardcode special case for tuning job hyperparameter (aws#54) * Use strip() for more readability (aws#55) This change is a small improvement upon aws#54 * Bump version to 1.0.4 (aws#56)
Description of changes:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.