You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/frameworks/xgboost/using_xgboost.rst
+51-1Lines changed: 51 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -390,6 +390,57 @@ The function should return a byte array of data serialized to ``content_type``.
390
390
The default implementation expects ``prediction`` to be a NumPy array and can serialize the result to JSON, CSV, or NPY.
391
391
It accepts response content types of "application/json", "text/csv", and "application/x-npy".
392
392
393
+
Bring your own model
394
+
--------------------
395
+
396
+
You can deploy an XGBoost model that you trained outside of SageMaker by using the Amazon SageMaker XGBoost container.
397
+
Typically, you save an XGBoost model by pickling the ``Booster`` object or calling ``booster.save_model``.
398
+
The XGBoost `built-in algorithm mode <https://docs.aws.amazon.com/sagemaker/latest/dg/xgboost.html#xgboost-modes>`_
399
+
supports both a pickled ``Booster`` object and a model produced by ``booster.save_model``.
400
+
For a sample notebook that shows to use the XGBoost built-in algorith mode to load a pre-existing XGBoost model,
401
+
see `Amazon SageMaker XGBoost Bring Your Own Model <https://github.com/awslabs/amazon-sagemaker-examples/blob/master/advanced_functionality/xgboost_bring_your_own_model/xgboost_bring_your_own_model.ipynb>`_.
402
+
403
+
You can also deploy an XGBoost model by using XGBoost as a framework.
404
+
By using XGBoost as a framework, you have more flexibility.
405
+
To deploy an XGBoost model by using XGBoost as a framework, you need to:
406
+
- Write an inference script.
407
+
- Create the XGBoostModel object.
408
+
409
+
Write an inference script
410
+
^^^^^^^^^^^^^^^^^^^^^^^^^
411
+
412
+
You must create an inference script that implements (at least) the ``model_fn`` function that calls the loaded model to get a prediction.
413
+
414
+
Optionally, you can also implement ``input_fn`` and ``output_fn`` to process input and output,
415
+
and ``predict_fn`` to customize how the model server gets predictions from the loaded model.
416
+
For information about how to write an inference script, see `SageMaker XGBoost Model Server <#sagemaker-xgboost-model-server>`_.
417
+
Pass the filename of the inference script as the ``entry_point`` parameter when you create the `XGBoostModel` object.
418
+
419
+
Create a XGBoostModel object
420
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
421
+
422
+
Now call the ``sagemaker.xgboost.model.XGBoostModel`` constructor to create a model object,
423
+
and then call its ``deploy()`` method to deploy your model for inference.
424
+
425
+
.. code:: python
426
+
427
+
from sagemaker import get_execution_role
428
+
role = get_execution_role()
429
+
430
+
xgboos_model = XGBoostModel(
431
+
model_data="s3://my-bucket/my-path/model.tar.gz",
432
+
role=role,
433
+
entry_point="inference.py",
434
+
framework_version="1.0-1"
435
+
)
436
+
437
+
predictor = xgboost_model.deploy(
438
+
instance_type='ml.c4.xlarge',
439
+
initial_instance_count=1
440
+
)
441
+
442
+
Now you can call the ``predict()`` method to get predictions from your deployed model.
443
+
393
444
Host Multiple Models with Multi-Model Endpoints
394
445
-----------------------------------------------
395
446
@@ -401,7 +452,6 @@ in the AWS documentation.
401
452
For a sample notebook that uses Amazon SageMaker to deploy multiple XGBoost models to an endpoint, see the
0 commit comments