Skip to content

Commit cbde0d6

Browse files
authored
Merge branch 'master' into rl_estimator_patch
2 parents ebe8eb3 + 11df130 commit cbde0d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+953
-107
lines changed

.github/ISSUE_TEMPLATE/feature_request.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
name: Feature request
3-
about: Suggest an improvement for this library
3+
about: Suggest new functionality for this library
44
title: ''
55
labels: ''
66
assignees: ''
77

88
---
99

10-
**Is your feature request related to a problem? Please describe.**
11-
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
10+
**Describe the feature you'd like**
11+
A clear and concise description of the functionality you want.
1212

13-
**Describe the solution you'd like**
14-
A clear and concise description of what you want to happen.
13+
**How would this feature be used? Please describe.**
14+
A clear and concise description of the use case for this feature. Please provide an example, if possible.
1515

1616
**Describe alternatives you've considered**
1717
A clear and concise description of any alternative solutions or features you've considered.

CHANGELOG.md

+65
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,70 @@
11
# Changelog
22

3+
## v1.69.0 (2020-07-09)
4+
5+
### Features
6+
7+
* Add ModelClientConfig Fields for Batch Transform
8+
9+
### Documentation Changes
10+
11+
* add KFP Processing component
12+
13+
## v1.68.0 (2020-07-07)
14+
15+
### Features
16+
17+
* add spot instance support for AlgorithmEstimator
18+
19+
### Documentation Changes
20+
21+
* add xgboost documentation for inference
22+
23+
## v1.67.1.post0 (2020-07-01)
24+
25+
### Documentation Changes
26+
27+
* add Step Functions SDK info
28+
29+
## v1.67.1 (2020-06-30)
30+
31+
### Bug Fixes and Other Changes
32+
33+
* add deprecation warnings for estimator.delete_endpoint() and tuner.delete_endpoint()
34+
35+
## v1.67.0 (2020-06-29)
36+
37+
### Features
38+
39+
* Apache Airflow integration for SageMaker Processing Jobs
40+
41+
### Bug Fixes and Other Changes
42+
43+
* fix punctuation in warning message
44+
45+
### Testing and Release Infrastructure
46+
47+
* address warnings about pytest custom marks, error message checking, and yaml loading
48+
* mark long-running cron tests
49+
* fix tox test dependencies and bump coverage threshold to 86%
50+
51+
## v1.66.0 (2020-06-25)
52+
53+
### Features
54+
55+
* add 3.8 as supported python version
56+
57+
### Testing and Release Infrastructure
58+
59+
* upgrade airflow to latest stable version
60+
* update feature request issue template
61+
62+
## v1.65.1.post1 (2020-06-24)
63+
64+
### Testing and Release Infrastructure
65+
66+
* add py38 to buildspecs
67+
368
## v1.65.1.post0 (2020-06-22)
469

570
### Documentation Changes

README.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ SageMaker Python SDK is tested on:
9696
- Python 2.7
9797
- Python 3.6
9898
- Python 3.7
99+
- Python 3.8
99100

100101
AWS Permissions
101102
~~~~~~~~~~~~~~~
@@ -123,8 +124,8 @@ You can install the libraries needed to run the tests by running :code:`pip inst
123124

124125

125126
We run unit tests with tox, which is a program that lets you run unit tests for multiple Python versions, and also make sure the
126-
code fits our style guidelines. We run tox with Python 2.7, 3.6 and 3.7, so to run unit tests
127-
with the same configuration we do, you'll need to have interpreters for Python 2.7, Python 3.6 and Python 3.7 installed.
127+
code fits our style guidelines. We run tox with Python 2.7, 3.6, 3.7, and 3.8, so to run unit tests
128+
with the same configuration we do, you'll need to have interpreters for Python 2.7, Python 3.6, Python 3.7, and Python 3.8 installed.
128129

129130
To run the unit tests with tox, run:
130131

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.65.2.dev0
1+
1.69.1.dev0

doc/frameworks/mxnet/using_mxnet.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,14 @@ If there are other packages you want to use with your script, you can include a
321321
Both ``requirements.txt`` and your training script should be put in the same folder.
322322
You must specify this folder in ``source_dir`` argument when creating an MXNet estimator.
323323

324-
The function of installing packages using ``requirements.txt`` is supported for all MXNet versions during training.
324+
The function of installing packages using ``requirements.txt`` is supported for MXNet versions 1.3.0 and higher during training.
325+
325326
When serving an MXNet model, support for this function varies with MXNet versions.
326327
For MXNet 1.6.0 or newer, ``requirements.txt`` must be under folder ``code``.
327328
The SageMaker MXNet Estimator automatically saves ``code`` in ``model.tar.gz`` after training (assuming you set up your script and ``requirements.txt`` correctly as stipulated in the previous paragraph).
328329
In the case of bringing your own trained model for deployment, you must save ``requirements.txt`` under folder ``code`` in ``model.tar.gz`` yourself or specify it through ``dependencies``.
329-
For MXNet 1.4.1, ``requirements.txt`` is not supported for inference.
330-
For MXNet 0.12.1-1.3.0, ``requirements.txt`` must be in ``source_dir``.
330+
For MXNet 0.12.1-1.2.1, 1.4.0-1.4.1, ``requirements.txt`` is not supported for inference.
331+
For MXNet 1.3.0, ``requirements.txt`` must be in ``source_dir``.
331332

332333
A ``requirements.txt`` file is a text file that contains a list of items that are installed by using ``pip install``.
333334
You can also specify the version of an item to install.

doc/frameworks/xgboost/using_xgboost.rst

+216-13
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ and a dictionary of the hyperparameters to pass to the training script.
161161
role=role,
162162
train_instance_count=1,
163163
train_instance_type="ml.m5.2xlarge",
164-
framework_version="0.90-1",
164+
framework_version="1.0-1",
165165
)
166166
167167
@@ -179,24 +179,227 @@ After you create an estimator, call the ``fit`` method to run the training job.
179179
Deploy Open Source XGBoost Models
180180
=================================
181181

182-
After the training job finishes, call the ``deploy`` method of the estimator to create a predictor that you can use to get inferences from your trained model.
182+
After you fit an XGBoost Estimator, you can host the newly created model in SageMaker.
183+
184+
After you call ``fit``, you can call ``deploy`` on an ``XGBoost`` estimator to create a SageMaker endpoint.
185+
The endpoint runs a SageMaker-provided XGBoost model server and hosts the model produced by your training script,
186+
which was run when you called ``fit``. This was the model you saved to ``model_dir``.
187+
188+
``deploy`` returns a ``Predictor`` object, which you can use to do inference on the Endpoint hosting your XGBoost model.
189+
Each ``Predictor`` provides a ``predict`` method which can do inference with numpy arrays, Python lists, or strings.
190+
After inference arrays or lists are serialized and sent to the XGBoost model server, ``predict`` returns the result of
191+
inference against your model.
183192

184193
.. code::
185194
186-
predictor = xgb_script_mode_estimator.deploy(initial_instance_count=1, instance_type="ml.m5.xlarge")
187-
test_data = xgboost.DMatrix('/path/to/data')
188-
predictor.predict(test_data)
195+
predictor = estimator.deploy(
196+
initial_instance_count=1,
197+
instance_type="ml.m5.xlarge"
198+
)
199+
predictor.serializer = str
200+
predictor.content_type = "text/libsvm"
189201
190-
Customize inference
191-
-------------------
202+
with open("abalone") as f:
203+
payload = f.read()
204+
205+
predictor.predict(payload)
206+
207+
SageMaker XGBoost Model Server
208+
-----------------------------------
209+
210+
You can configure two components of the SageMaker XGBoost model server: Model loading and model serving.
211+
Model loading is the process of deserializing your saved model back into an XGBoost model.
212+
Model serving is the process of translating endpoint requests to inference calls on the loaded model.
213+
214+
You configure the XGBoost model server by defining functions in the Python source file you passed to the XGBoost constructor.
215+
216+
Load a Model
217+
^^^^^^^^^^^^
218+
219+
Before a model can be served, it must be loaded. The SageMaker XGBoost model server loads your model by invoking a
220+
``model_fn`` function that you must provide in your script. The ``model_fn`` should have the following signature:
221+
222+
.. code:: python
223+
224+
def model_fn(model_dir)
225+
226+
SageMaker will inject the directory where your model files and sub-directories, saved by ``save``, have been mounted.
227+
Your model function should return a ``xgboost.Booster`` object that can be used for model serving.
228+
229+
The following code-snippet shows an example ``model_fn`` implementation.
230+
It loads and returns a pickled XGBoost model from a ``xgboost-model`` file in the SageMaker model directory ``model_dir``.
231+
232+
.. code:: python
233+
234+
import pickle as pkl
235+
236+
def model_fn(model_dir):
237+
with open(os.path.join(model_dir, "xgboost-model"), "rb") as f:
238+
booster = pkl.load(f)
239+
return booster
240+
241+
Serve a Model
242+
^^^^^^^^^^^^^
243+
244+
After the SageMaker model server has loaded your model by calling ``model_fn``, SageMaker will serve your model.
245+
The SageMaker Scikit-learn model server breaks request handling into three steps:
246+
247+
- input processing,
248+
- prediction, and
249+
- output processing.
250+
251+
In a similar way to model loading, you can customize the inference behavior by defining functions in your inference
252+
script, which can be either in the same file as your training script or in a separate file,
253+
254+
Each step involves invoking a python function, with information about the request and the return-value from the previous
255+
function in the chain.
256+
Inside the SageMaker XGBoost model server, the process looks like:
257+
258+
.. code:: python
259+
260+
# Deserialize the Invoke request body into an object we can perform prediction on
261+
input_object = input_fn(request_body, request_content_type)
262+
263+
# Perform prediction on the deserialized object, with the loaded model
264+
prediction = predict_fn(input_object, model)
265+
266+
# Serialize the prediction result into the desired response content type
267+
output = output_fn(prediction, response_content_type)
268+
269+
The above code-sample shows the three function definitions:
270+
271+
- ``input_fn``: Takes request data and deserializes the data into an object for prediction.
272+
- ``predict_fn``: Takes the deserialized request object and performs inference against the loaded model.
273+
- ``output_fn``: Takes the result of prediction and serializes this according to the response content type.
274+
275+
These functions are optional.
276+
The SageMaker XGBoost model server provides default implementations of these functions.
277+
You can provide your own implementations for these functions in your hosting script.
278+
If you omit any definition then the SageMaker XGBoost model server will use its default implementation for that
279+
function.
280+
281+
In the following sections we describe the default implementations of ``input_fn``, ``predict_fn``, and ``output_fn``.
282+
We describe the input arguments and expected return types of each, so you can define your own implementations.
283+
284+
Process Input
285+
"""""""""""""
286+
287+
When a request is made against an endpoint running a SageMaker XGBoost model server, the model server receives two
288+
pieces of information:
289+
290+
- The request Content-Type, for example "application/x-npy" or "text/libsvm"
291+
- The request data body, a byte array
292+
293+
The SageMaker XGBoost model server will invoke an ``input_fn`` function in your inference script, passing in this
294+
information. If you define an ``input_fn`` function definition, it should return an object that can be passed
295+
to ``predict_fn`` and have the following signature:
296+
297+
.. code:: python
298+
299+
def input_fn(request_body, request_content_type)
300+
301+
where ``request_body`` is a byte buffer and ``request_content_type`` is a Python string.
302+
303+
The SageMaker XGBoost model server provides a default implementation of ``input_fn``.
304+
This function deserializes CSV, LIBSVM, or protobuf recordIO into a ``xgboost.DMatrix``.
305+
306+
Default csv deserialization requires ``request_body`` contain one or more lines of CSV numerical data.
307+
The data is first loaded into a two-dimensional array, where each line break defines the boundaries of the first
308+
dimension, and then it is converted to an `xgboost.Dmatrix`. It assumes that CSV input does not have the
309+
label column.
310+
311+
Default LIBSVM deserialization requires ``request_body`` to follow the `LIBSVM <https://www.csie.ntu.edu.tw/~cjlin/libsvm/>`_ format.
312+
313+
The example below shows a custom ``input_fn`` for preparing pickled NumPy arrays.
314+
315+
.. code:: python
316+
317+
from io import BytesIO
318+
import numpy as np
319+
import xgboost as xgb
320+
321+
def input_fn(request_body, request_content_type):
322+
"""An input_fn that loads a numpy array"""
323+
if request_content_type == "application/npy":
324+
array = np.load(BytesIO(request_body))
325+
return xgb.DMatrix(array)
326+
else:
327+
# Handle other content-types here or raise an Exception
328+
# if the content type is not supported.
329+
pass
330+
331+
Get Predictions
332+
"""""""""""""""
333+
334+
After the inference request has been deserialized by ``input_fn``, the SageMaker XGBoost model server invokes
335+
``predict_fn`` on the return value of ``input_fn``.
336+
337+
As with ``input_fn``, you can define your own ``predict_fn`` or use the SageMaker XGBoost model server default.
338+
339+
The ``predict_fn`` function has the following signature:
340+
341+
.. code:: python
342+
343+
def predict_fn(input_object, model)
344+
345+
Where ``input_object`` is the object returned from ``input_fn`` and ``model`` is the model loaded by ``model_fn``.
346+
347+
The default implementation of ``predict_fn`` invokes the loaded model's ``predict`` function on ``input_object``,
348+
and returns the resulting value. The return-type should be a NumPy array to be compatible with the default
349+
``output_fn``.
350+
351+
The example below shows an overriden ``predict_fn`` that returns a two-dimensional NumPy array where
352+
the first columns are predictions and the remaining columns are the feature contributions
353+
(`SHAP values <https://github.com/slundberg/shap>`_) for that prediction.
354+
When ``pred_contribs`` is ``True`` in ``xgboost.Booster.predict()``, the output will be a matrix of size
355+
(nsample, nfeats + 1) with each record indicating the feature contributions for that prediction.
356+
Note the final column is the bias term.
357+
358+
.. code:: python
359+
360+
import numpy as np
361+
362+
def predict_fn(input_data, model):
363+
prediction = model.predict(input_data)
364+
feature_contribs = model.predict(input_data, pred_contribs=True)
365+
output = np.hstack((prediction[:, np.newaxis], feature_contribs))
366+
return output
367+
368+
If you implement your own prediction function, you should take care to ensure that:
369+
370+
- The first argument is expected to be the return value from input_fn.
371+
- The second argument is the loaded model.
372+
- The return value should be of the correct type to be passed as the first argument to ``output_fn``.
373+
If you use the default ``output_fn``, this should be a NumPy array.
374+
375+
Process Output
376+
""""""""""""""
377+
378+
After invoking ``predict_fn``, the model server invokes ``output_fn``, passing in the return value from
379+
``predict_fn`` and the requested response content-type.
380+
381+
The ``output_fn`` has the following signature:
382+
383+
.. code:: python
384+
385+
def output_fn(prediction, content_type)
386+
387+
``prediction`` is the result of invoking ``predict_fn`` and ``content_type`` is the requested response content-type.
388+
The function should return a byte array of data serialized to ``content_type``.
389+
390+
The default implementation expects ``prediction`` to be a NumPy array and can serialize the result to JSON, CSV, or NPY.
391+
It accepts response content types of "application/json", "text/csv", and "application/x-npy".
192392

193-
In your inference script, which can be either in the same file as your training script or in a separate file,
194-
you can customize the inference behavior by implementing the following functions:
195-
* ``input_fn`` - how input data is handled
196-
* ``predict_fn`` - how the model is invoked
197-
* ``output_fn`` - How the response data is handled
393+
Host Multiple Models with Multi-Model Endpoints
394+
-----------------------------------------------
198395

199-
These functions are optional. If you want to use the default implementations, do not implement them in your training script.
396+
To create an endpoint that can host multiple models, use multi-model endpoints.
397+
Multi-model endpoints are supported in SageMaker XGBoost versions ``0.90-2``, ``1.0-1``, and later.
398+
For information about using multiple XGBoost models with multi-model endpoints, see
399+
`Host Multiple Models with Multi-Model Endpoints <https://docs.aws.amazon.com/sagemaker/latest/dg/multi-model-endpoints.html>`_
400+
in the AWS documentation.
401+
For a sample notebook that uses Amazon SageMaker to deploy multiple XGBoost models to an endpoint, see the
402+
`Multi-Model Endpoint XGBoost Sample Notebook <https://github.com/awslabs/amazon-sagemaker-examples/blob/master/advanced_functionality/multi_model_xgboost_home_value/xgboost_multi_model_endpoint_home_value.ipynb>`_.
200403

201404

202405
*************************

doc/workflows/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ The SageMaker Python SDK supports managed training and inference for a variety o
99

1010
airflow/index
1111
kubernetes/index
12+
step_functions/index

doc/workflows/kubernetes/amazon_sagemaker_components_for_kubeflow_pipelines.rst

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Pipelines workflow. For more information, see \ `SageMaker
8989
hyperparameter optimization Kubeflow Pipeline
9090
component <https://github.com/kubeflow/pipelines/tree/master/components/aws/sagemaker/hyperparameter_tuning>`__.
9191

92+
**Processing**
93+
94+
The Processing component enables you to submit processing jobs to Amazon SageMaker directly from a Kubeflow Pipelines workflow. For more information, see \ `SageMaker Processing Kubeflow Pipeline component <https://github.com/kubeflow/pipelines/tree/master/components/aws/sagemaker/process>`__.
95+
9296
Inference components
9397
^^^^^^^^^^^^^^^^^^^^
9498

0 commit comments

Comments
 (0)