@@ -598,6 +598,16 @@ the `JumpStart UI in SageMaker Studio <https://docs.aws.amazon.com/sagemaker/lat
598
598
Example notebooks
599
599
=================
600
600
601
+ Explore example notebooks to get started with pretrained models using the SageMaker Python SDK.
602
+
603
+ Example notebooks for foundation models
604
+ ---------------------------------------
605
+ All JumpStart foundation models are available to use programmatically with the SageMaker Python SDK.
606
+ For a list of available example notebooks related to JumpStart foundation models, see
607
+ `JumpStart foundation models example notebooks <https://docs.aws.amazon.com/sagemaker/latest/dg/jumpstart-foundation-models.html#jumpstart-foundation-models-example-notebooks >`__.
608
+
609
+ Example notebooks for task-based models
610
+ ---------------------------------------
601
611
SageMaker built-in algorithms with pre-trained models support 15 different machine learning problem types.
602
612
Below is a list of all the supported problem types with a link to a Jupyter notebook that provides example usage.
603
613
@@ -629,9 +639,6 @@ Tabular
629
639
- `Tabular Regression (TabTransformer) <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/tabtransformer_tabular/Amazon_Tabular_Regression_TabTransformer.ipynb >`__
630
640
631
641
632
- The following topic give you information about JumpStart components,
633
- as well as how to use the SageMaker Python SDK for these workflows.
634
-
635
642
Prerequisites
636
643
=============
637
644
@@ -642,87 +649,6 @@ Prerequisites
642
649
Amazon S3. For more information about IAM role permissions,
643
650
see `Policies and permissions in IAM <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html>`__.
644
651
645
- Built-in Components
646
- ===================
647
-
648
- The following sections provide information about the main components of built-in algorithms
649
- including pretrained models, model scripts, and model images.
650
-
651
- Pre-trained models
652
- ------------------
653
-
654
- SageMaker maintains a model zoo of over 300 models from popular open source model hubs, such as
655
- TensorFlow Hub, Pytorch Hub, and HuggingFace. You can use the SageMaker Python SDK to fine-tune
656
- a model on your own dataset or deploy it directly to a SageMaker endpoint for inference.
657
-
658
- Model artifacts are stored as tarballs in an S3 bucket. Each model is versioned and contains a
659
- unique ID which can be used to retrieve the model URI. The following information describes the
660
- ``model_id `` and ``model_version `` needed to retrieve the URI.
661
-
662
- .. container ::
663
-
664
- - ``model_id ``: A unique identifier for the JumpStart model.
665
- - ``model_version ``: The version of the specifications for the
666
- model. To use the latest version, enter ``"*"``. This is a
667
- required parameter.
668
-
669
- To retrieve a model, first select a ``model ID `` and ``version `` from
670
- the :doc: `available models <./doc_utils/pretrainedmodels >`.
671
-
672
- .. code :: python
673
-
674
- model_id, model_version = " huggingface-spc-bert-base-cased" , " 1.0.0"
675
- scope = " training" # or "inference"
676
-
677
- Then use those values to retrieve the model as follows.
678
-
679
- .. code :: python
680
-
681
- from sagemaker import model_uris
682
-
683
- model_uri = model_uris.retrieve(
684
- model_id = model_id, model_version = model_version, model_scope = scope
685
- )
686
-
687
- Model scripts
688
- -------------
689
-
690
- To adapt pre-trained models for SageMaker, a custom script is needed to perform training
691
- or inference. SageMaker maintains a suite of scripts used for each of the models in the
692
- S3 bucket, which can be accessed using the SageMaker Python SDK Use the ``model_id`` and
693
- ``version `` of the corresponding model to retrieve the related script as follows.
694
-
695
- .. code :: python
696
-
697
- from sagemaker import script_uris
698
-
699
- script_uri = script_uris.retrieve(
700
- model_id = model_id, model_version = model_version, script_scope = scope
701
- )
702
-
703
- Model images
704
- -------------
705
-
706
- A Docker image is required to perform training or inference on all
707
- SageMaker models. SageMaker relies on Docker images from the
708
- following repos https://github.com/aws/deep-learning-containers,
709
- https://github.com/aws/sagemaker-xgboost-container,
710
- and https://github.com/aws/sagemaker-scikit-learn-container. Use
711
- the ``model_id`` and ``version `` of the corresponding model to
712
- retrieve the related image as follows.
713
-
714
- .. code :: python
715
-
716
- from sagemaker import image_uris
717
-
718
- image_uri = image_uris.retrieve(
719
- region = None ,
720
- framework = None ,
721
- image_scope = scope,
722
- model_id = model_id,
723
- model_version = model_version,
724
- instance_type = " ml.m5.xlarge" ,
725
- )
726
652
727
653
Deploy a Pre-Trained Model Directly to a SageMaker Endpoint
728
654
============================================================
@@ -731,7 +657,7 @@ You can deploy a built-in algorithm or pre-trained model to a SageMaker endpoint
731
657
732
658
First, find the model ID for the model of your choice in the :doc: `Built-in Algorithms with pre-trained Model Table<./doc_utils/pretrainedmodels> `.
733
659
734
- Low-code Deployment with the JumpStartModel class
660
+ Low-code deployment with the JumpStartModel class
735
661
-------------------------------------------------
736
662
737
663
Using the model ID, define your model as a JumpStart model. Use the ``deploy `` method to automatically deploy your model for inference.
@@ -858,13 +784,42 @@ tune the model for your use case with your custom dataset. The following assumes
858
784
familiarity with `SageMaker training jobs and their
859
785
architecture <https://docs.aws.amazon.com/sagemaker/latest/dg/how-it-works-training.html> `__.
860
786
861
- Low-code Fine -tuning with the JumpStartEstimator class
787
+ Low-code fine -tuning with the JumpStartEstimator class
862
788
------------------------------------------------------
863
789
790
+ You can fine-tune a built-in algorithm or pre-trained model in just a few lines of code using the SageMaker Python SDK.
791
+
792
+ First, find the model ID for the model of your choice in the :doc: `Built-in Algorithms with pre-trained Model Table<./doc_utils/pretrainedmodels> `.
793
+
794
+ Using the model ID, define your training job as a JumpStart estimator. Run ``estimator.fit() `` on your model, pointing to the training data to use for fine-tuning.
795
+ Then, use the ``deploy `` method to automatically deploy your model for inference. In this example, we use the SPC (sentence pair classification) BERT base model (cased) from HuggingFace.
796
+
797
+ .. code :: python
798
+
799
+ from sagemaker.jumpstart.estimator import JumpStartEstimator
800
+
801
+ model_id = " huggingface-spc-bert-base-cased"
802
+ estimator = JumpStartEstimator(model_id = model_id)
803
+ estimator.fit(
804
+ {
805
+ " training" : f " s3://s3_bucket_and_region_name/training_dataset_for_model_and_version
806
+ }
807
+ )
808
+ predictor = estimator.deploy()
809
+
810
+ You can then run inference with the deployed model using the `` predict`` method.
811
+
812
+ .. code:: python
813
+
814
+ sentence_1 = " hello"
815
+ sentence_2 = " world"
816
+ classification = predictor.predict([sentence_1, sentence_2])
817
+ print (classification)
818
+
864
819
You can optionally include specific model versions or instance types. For more information about the `` JumpStartEstimator`` class and its parameters,
865
820
see `JumpStartEstimator < https:// sagemaker.readthedocs.io/ en/ stable/ api/ inference/ model.html# sagemaker.jumpstart.estimator.JumpStartEstimator>`__.
866
821
867
- Fine-tune a Pre -trained Model on a Custom Dataset using the SageMaker Estimator class
822
+ Fine- tune a pre - trained model on a custom dataset using the SageMaker Estimator class
868
823
------------------------------------------------------------------------------------ -
869
824
870
825
To begin, select a `` model_id`` and `` version`` from the pre- trained
@@ -955,7 +910,7 @@ amount of time. The time that it takes varies depending on the
955
910
hyperparameters, dataset, and model you use and can range from 15
956
911
minutes to 12 hours.
957
912
958
- Deploy your Trained Model to a SageMaker Endpoint
913
+ Deploy your trained model to a SageMaker Endpoint
959
914
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
960
915
961
916
Now that you’ve created your training job, use your
@@ -1001,7 +956,7 @@ took your model to train.
1001
956
enable_network_isolation = True ,
1002
957
)
1003
958
1004
- Perform Inference on a SageMaker Endpoint
959
+ Perform inference on a SageMaker Endpoint
1005
960
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1006
961
1007
962
Finally, use the `` predictor`` instance to query your endpoint. For
@@ -1018,6 +973,88 @@ the
1018
973
1019
974
predictor.predict(json.dumps(data).encode(" utf-8" ), {" ContentType" : " application/list-text" })
1020
975
976
+ Built- in Components
977
+ ================== =
978
+
979
+ The following section provides information about the main components of built- in algorithms
980
+ including pretrained models, model scripts, and model images.
981
+
982
+ Pre- trained models
983
+ ------------------
984
+
985
+ SageMaker maintains a model zoo of over 600 models from popular open source model hubs, such as
986
+ TensorFlow Hub, Pytorch Hub, and HuggingFace. You can use the SageMaker Python SDK to fine- tune
987
+ a model on your own dataset or deploy it directly to a SageMaker endpoint for inference.
988
+
989
+ Model artifacts are stored as tarballs in an S3 bucket. Each model is versioned and contains a
990
+ unique ID which can be used to retrieve the model URI . The following information describes the
991
+ `` model_id`` and `` model_version`` needed to retrieve the URI .
992
+
993
+ .. container::
994
+
995
+ - `` model_id`` : A unique identifier for the JumpStart model.
996
+ - `` model_version`` : The version of the specifications for the
997
+ model. To use the latest version, enter `` " *" `` . This is a
998
+ required parameter.
999
+
1000
+ To retrieve a model, first select a `` model ID `` and `` version`` from
1001
+ the :doc:`available models < ./ doc_utils/ pretrainedmodels> ` .
1002
+
1003
+ .. code:: python
1004
+
1005
+ model_id, model_version = " huggingface-spc-bert-base-cased" , " 1.0.0"
1006
+ scope = " training" # or "inference"
1007
+
1008
+ Then use those values to retrieve the model as follows.
1009
+
1010
+ .. code:: python
1011
+
1012
+ from sagemaker import model_uris
1013
+
1014
+ model_uri = model_uris.retrieve(
1015
+ model_id = model_id, model_version = model_version, model_scope = scope
1016
+ )
1017
+
1018
+ Model scripts
1019
+ ------------ -
1020
+
1021
+ To adapt pre- trained models for SageMaker, a custom script is needed to perform training
1022
+ or inference. SageMaker maintains a suite of scripts used for each of the models in the
1023
+ S3 bucket, which can be accessed using the SageMaker Python SDK Use the `` model_id`` and
1024
+ `` version`` of the corresponding model to retrieve the related script as follows.
1025
+
1026
+ .. code:: python
1027
+
1028
+ from sagemaker import script_uris
1029
+
1030
+ script_uri = script_uris.retrieve(
1031
+ model_id = model_id, model_version = model_version, script_scope = scope
1032
+ )
1033
+
1034
+ Model images
1035
+ ------------ -
1036
+
1037
+ A Docker image is required to perform training or inference on all
1038
+ SageMaker models. SageMaker relies on Docker images from the
1039
+ following repos https:// github.com/ aws/ deep- learning- containers,
1040
+ https:// github.com/ aws/ sagemaker- xgboost- container,
1041
+ and https:// github.com/ aws/ sagemaker- scikit- learn- container. Use
1042
+ the `` model_id`` and `` version`` of the corresponding model to
1043
+ retrieve the related image as follows.
1044
+
1045
+ .. code:: python
1046
+
1047
+ from sagemaker import image_uris
1048
+
1049
+ image_uri = image_uris.retrieve(
1050
+ region = None ,
1051
+ framework = None ,
1052
+ image_scope = scope,
1053
+ model_id = model_id,
1054
+ model_version = model_version,
1055
+ instance_type = " ml.m5.xlarge" ,
1056
+ )
1057
+
1021
1058
Appendix
1022
1059
========
1023
1060
0 commit comments