We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
transformer() method for an SKLearn estimator is failing
Please fill out the form below.

### System Information
- **Framework (e.g. TensorFlow) / Algorithm (e.g. KMeans)**: SKLearn
- **Framework Version**: sagemaker 1.36.1
- **Python Version**: 3.6
- **CPU or GPU**: CPU
- **Python SDK Version**: sagemaker 1.36.1
- **Are you using a custom image**: yes, using entry point script

### Describe the problem
An SKLearn estimator that is based on a custom algorithm (using entry_point script) was fitted and created a training job. Then, when calling the transformer method of that estimator with instance_count and instance_type parameters, a TypeError is thrown.

### Minimal repro / logs
- **Exact command to reproduce**:
sklearn = SKLearn(
    entry_point=script_path,
    train_instance_type="ml.m5.large",
    role=role,
    output_path =output_location,
    code_location=code_location,
    hyperparameters={'min_child_weight': 2, 'max_depth':8})
transformer = sklearn.transformer(instance_count=1, instance_type='ml.m5.large')
Error:
TypeError: __init__() got multiple values for argument 'entry_point'

- **Stack trace:**
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-20-07fcf819e9f1> in <module>()
----> 1 transformer = sklearn.transformer(instance_count=1, instance_type='ml.m5.large')

~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/estimator.py in transformer(self, instance_count, instance_type, strategy, assemble_with, output_path, output_kms_key, accept, env, max_concurrent_transforms, max_payload, tags, role, model_server_workers, volume_kms_key, entry_point)
   1573         if self.latest_training_job is not None:
   1574             model = self.create_model(
-> 1575                 role=role, model_server_workers=model_server_workers, entry_point=entry_point
   1576             )
   1577 

~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/sklearn/estimator.py in create_model(self, model_server_workers, role, vpc_config_override, **kwargs)
    167             sagemaker_session=self.sagemaker_session,
    168             vpc_config=self.get_vpc_config(vpc_config_override),
--> 169             **kwargs
    170         )
    171 

TypeError: __init__() got multiple values for argument 'entry_point'

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/sagemaker/sklearn/estimator.py`
Content:
```
1 # Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"). You
4 # may not use this file except in compliance with the License. A copy of
5 # the License is located at
6 #
7 #     http://aws.amazon.com/apache2.0/
8 #
9 # or in the "license" file accompanying this file. This file is
10 # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11 # ANY KIND, either express or implied. See the License for the specific
12 # language governing permissions and limitations under the License.
13 """Placeholder docstring"""
14 from __future__ import absolute_import
15 
16 import logging
17 
18 from sagemaker.estimator import Framework
19 from sagemaker.fw_registry import default_framework_uri
20 from sagemaker.fw_utils import (
21     framework_name_from_image,
22     empty_framework_version_warning,
23     python_deprecation_warning,
24 )
25 from sagemaker.sklearn.defaults import SKLEARN_VERSION, SKLEARN_NAME
26 from sagemaker.sklearn.model import SKLearnModel
27 from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT
28 
29 logger = logging.getLogger("sagemaker")
30 
31 
32 class SKLearn(Framework):
33     """Handle end-to-end training and deployment of custom Scikit-learn code."""
34 
35     __framework_name__ = SKLEARN_NAME
36 
37     def __init__(
38         self,
39         entry_point,
40         framework_version=SKLEARN_VERSION,
41         source_dir=None,
42         hyperparameters=None,
43         py_version="py3",
44         image_name=None,
45         **kwargs
46     ):
47         """This ``Estimator`` executes an Scikit-learn script in a managed
48         Scikit-learn execution environment, within a SageMaker Training Job. The
49         managed Scikit-learn environment is an Amazon-built Docker container
50         that executes functions defined in the supplied ``entry_point`` Python
51         script.
52 
53         Training is started by calling
54         :meth:`~sagemaker.amazon.estimator.Framework.fit` on this Estimator.
55         After training is complete, calling
56         :meth:`~sagemaker.amazon.estimator.Framework.deploy` creates a hosted
57         SageMaker endpoint and returns an
58         :class:`~sagemaker.amazon.sklearn.model.SKLearnPredictor` instance that
59         can be used to perform inference against the hosted model.
60 
61         Technical documentation on preparing Scikit-learn scripts for
62         SageMaker training and using the Scikit-learn Estimator is available on
63         the project home-page: https://github.com/aws/sagemaker-python-sdk
64 
65         Args:
66             entry_point (str): Path (absolute or relative) to the Python source
67                 file which should be executed as the entry point to training.
68                 This should be compatible with either Python 2.7 or Python 3.5.
69             framework_version (str): Scikit-learn version you want to use for
70                 executing your model training code. List of supported versions
71                 https://github.com/aws/sagemaker-python-sdk#sklearn-sagemaker-estimators
72             source_dir (str): Path (absolute or relative) to a directory with
73                 any other training source code dependencies aside from tne entry
74                 point file (default: None). Structure within this directory are
75                 preserved when training on Amazon SageMaker.
76             hyperparameters (dict): Hyperparameters that will be used for
77                 training (default: None). The hyperparameters are made
78                 accessible as a dict[str, str] to the training code on
79                 SageMaker. For convenience, this accepts other types for keys
80                 and values, but ``str()`` will be called to convert them before
81                 training.
82             py_version (str): Python version you want to use for executing your
83                 model training code (default: 'py2'). One of 'py2' or 'py3'.
84             image_name (str): If specified, the estimator will use this image
85                 for training and hosting, instead of selecting the appropriate
86                 SageMaker official image based on framework_version and
87                 py_version. It can be an ECR url or dockerhub image and tag.
88                 Examples:
89                     123.dkr.ecr.us-west-2.amazonaws.com/my-custom-image:1.0
90                     custom-image:latest.
91             **kwargs: Additional kwargs passed to the
92                 :class:`~sagemaker.estimator.Framework` constructor.
93         """
94         # SciKit-Learn does not support distributed training or training on GPU instance types.
95         # Fail fast.
96         train_instance_type = kwargs.get("train_instance_type")
97         _validate_not_gpu_instance_type(train_instance_type)
98 
99         train_instance_count = kwargs.get("train_instance_count")
100         if train_instance_count:
101             if train_instance_count != 1:
102                 raise AttributeError(
103                     "Scikit-Learn does not support distributed training. "
104                     "Please remove the 'train_instance_count' argument or set "
105                     "'train_instance_count=1' when initializing SKLearn."
106                 )
107         super(SKLearn, self).__init__(
108             entry_point,
109             source_dir,
110             hyperparameters,
111             image_name=image_name,
112             **dict(kwargs, train_instance_count=1)
113         )
114 
115         if py_version == "py2":
116             logger.warning(python_deprecation_warning(self.__framework_name__))
117 
118         self.py_version = py_version
119 
120         if framework_version is None:
121             logger.warning(empty_framework_version_warning(SKLEARN_VERSION, SKLEARN_VERSION))
122         self.framework_version = framework_version or SKLEARN_VERSION
123 
124         if image_name is None:
125             image_tag = "{}-{}-{}".format(framework_version, "cpu", py_version)
126             self.image_name = default_framework_uri(
127                 SKLearn.__framework_name__, self.sagemaker_session.boto_region_name, image_tag
128             )
129 
130     def create_model(
131         self, model_server_workers=None, role=None, vpc_config_override=VPC_CONFIG_DEFAULT, **kwargs
132     ):
133         """Create a SageMaker ``SKLearnModel`` object that can be deployed to an
134         ``Endpoint``.
135 
136         Args:
137             model_server_workers (int): Optional. The number of worker processes
138                 used by the inference server. If None, server will use one
139                 worker per vCPU.
140             role (str): The ``ExecutionRoleArn`` IAM Role ARN for the ``Model``,
141                 which is also used during transform jobs. If not specified, the
142                 role from the Estimator will be used.
143             vpc_config_override (dict[str, list[str]]): Optional override for VpcConfig set on
144                 the model. Default: use subnets and security groups from this Estimator.
145                 * 'Subnets' (list[str]): List of subnet ids.
146                 * 'SecurityGroupIds' (list[str]): List of security group ids.
147             **kwargs: Passed to initialization of ``SKLearnModel``.
148 
149         Returns:
150             sagemaker.sklearn.model.SKLearnModel: A SageMaker ``SKLearnModel``
151             object. See :func:`~sagemaker.sklearn.model.SKLearnModel` for full details.
152         """
153         role = role or self.role
154         return SKLearnModel(
155             self.model_data,
156             role,
157             self.entry_point,
158             source_dir=self._model_source_dir(),
159             enable_cloudwatch_metrics=self.enable_cloudwatch_metrics,
160             name=self._current_job_name,
161             container_log_level=self.container_log_level,
162             code_location=self.code_location,
163             py_version=self.py_version,
164             framework_version=self.framework_version,
165             model_server_workers=model_server_workers,
166             image=self.image_name,
167             sagemaker_session=self.sagemaker_session,
168             vpc_config=self.get_vpc_config(vpc_config_override),
169             **kwargs
170         )
171 
172     @classmethod
173     def _prepare_init_params_from_job_description(cls, job_details, model_channel_name=None):
174         """Convert the job description to init params that can be handled by the
175         class constructor
176 
177         Args:
178             job_details: the returned job details from a describe_training_job
179                 API call.
180             model_channel_name:
181 
182         Returns:
183             dictionary: The transformed init_params
184         """
185         init_params = super(SKLearn, cls)._prepare_init_params_from_job_description(job_details)
186 
187         image_name = init_params.pop("image")
188         framework, py_version, _, _ = framework_name_from_image(image_name)
189         init_params["py_version"] = py_version
190 
191         if framework and framework != cls.__framework_name__:
192             training_job_name = init_params["base_job_name"]
193             raise ValueError(
194                 "Training job: {} didn't use image for requested framework".format(
195                     training_job_name
196                 )
197             )
198         if not framework:
199             # If we were unable to parse the framework name from the image it is not one of our
200             # officially supported images, in this case just add the image to the init params.
201             init_params["image_name"] = image_name
202         return init_params
203 
204 
205 def _validate_not_gpu_instance_type(training_instance_type):
206     """
207     Args:
208         training_instance_type:
209     """
210     gpu_instance_types = [
211         "ml.p2.xlarge",
212         "ml.p2.8xlarge",
213         "ml.p2.16xlarge",
214         "ml.p3.xlarge",
215         "ml.p3.8xlarge",
216         "ml.p3.16xlarge",
217     ]
218 
219     if training_instance_type in gpu_instance_types:
220         raise ValueError(
221             "GPU training in not supported for Scikit-Learn. "
222             "Please pick a different instance type from here: "
223             "https://aws.amazon.com/ec2/instance-types/"
224         )
225
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/sagemaker/sklearn/estimator.py b/src/sagemaker/sklearn/estimator.py
--- a/src/sagemaker/sklearn/estimator.py
+++ b/src/sagemaker/sklearn/estimator.py
@@ -151,6 +151,12 @@
             object. See :func:`~sagemaker.sklearn.model.SKLearnModel` for full details.
         """
         role = role or self.role
+
+        # remove unwanted entry_point kwarg
+        if "entry_point" in kwargs:
+            logger.debug("removing unused entry_point argument: %s", str(kwargs["entry_point"]))
+            kwargs = {k: v for k, v in kwargs.items() if k != "entry_point"}
+
         return SKLearnModel(
             self.model_data,
             role,

{"golden_diff": "diff --git a/src/sagemaker/sklearn/estimator.py b/src/sagemaker/sklearn/estimator.py\n--- a/src/sagemaker/sklearn/estimator.py\n+++ b/src/sagemaker/sklearn/estimator.py\n@@ -151,6 +151,12 @@\n             object. See :func:`~sagemaker.sklearn.model.SKLearnModel` for full details.\n         \"\"\"\n         role = role or self.role\n+\n+        # remove unwanted entry_point kwarg\n+        if \"entry_point\" in kwargs:\n+            logger.debug(\"removing unused entry_point argument: %s\", str(kwargs[\"entry_point\"]))\n+            kwargs = {k: v for k, v in kwargs.items() if k != \"entry_point\"}\n+\n         return SKLearnModel(\n             self.model_data,\n             role,\n", "issue": "transformer() method for an SKLearn estimator is failing\nPlease fill out the form below.\r\n\r\n### System Information\r\n- **Framework (e.g. TensorFlow) / Algorithm (e.g. KMeans)**: SKLearn\r\n- **Framework Version**: sagemaker 1.36.1\r\n- **Python Version**: 3.6\r\n- **CPU or GPU**: CPU\r\n- **Python SDK Version**: sagemaker 1.36.1\r\n- **Are you using a custom image**: yes, using entry point script\r\n\r\n### Describe the problem\r\nAn SKLearn estimator that is based on a custom algorithm (using entry_point script) was fitted and created a training job. Then, when calling the transformer method of that estimator with instance_count and instance_type parameters, a TypeError is thrown.\r\n\r\n### Minimal repro / logs\r\n- **Exact command to reproduce**:\r\nsklearn = SKLearn(\r\n    entry_point=script_path,\r\n    train_instance_type=\"ml.m5.large\",\r\n    role=role,\r\n    output_path =output_location,\r\n    code_location=code_location,\r\n    hyperparameters={'min_child_weight': 2, 'max_depth':8})\r\ntransformer = sklearn.transformer(instance_count=1, instance_type='ml.m5.large')\r\nError:\r\nTypeError: __init__() got multiple values for argument 'entry_point'\r\n\r\n- **Stack trace:**\r\n---------------------------------------------------------------------------\r\nTypeError                                 Traceback (most recent call last)\r\n<ipython-input-20-07fcf819e9f1> in <module>()\r\n----> 1 transformer = sklearn.transformer(instance_count=1, instance_type='ml.m5.large')\r\n\r\n~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/estimator.py in transformer(self, instance_count, instance_type, strategy, assemble_with, output_path, output_kms_key, accept, env, max_concurrent_transforms, max_payload, tags, role, model_server_workers, volume_kms_key, entry_point)\r\n   1573         if self.latest_training_job is not None:\r\n   1574             model = self.create_model(\r\n-> 1575                 role=role, model_server_workers=model_server_workers, entry_point=entry_point\r\n   1576             )\r\n   1577 \r\n\r\n~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/sklearn/estimator.py in create_model(self, model_server_workers, role, vpc_config_override, **kwargs)\r\n    167             sagemaker_session=self.sagemaker_session,\r\n    168             vpc_config=self.get_vpc_config(vpc_config_override),\r\n--> 169             **kwargs\r\n    170         )\r\n    171 \r\n\r\nTypeError: __init__() got multiple values for argument 'entry_point'\n", "before_files": [{"content": "# Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\"). You\n# may not use this file except in compliance with the License. A copy of\n# the License is located at\n#\n#     http://aws.amazon.com/apache2.0/\n#\n# or in the \"license\" file accompanying this file. This file is\n# distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n# ANY KIND, either express or implied. See the License for the specific\n# language governing permissions and limitations under the License.\n\"\"\"Placeholder docstring\"\"\"\nfrom __future__ import absolute_import\n\nimport logging\n\nfrom sagemaker.estimator import Framework\nfrom sagemaker.fw_registry import default_framework_uri\nfrom sagemaker.fw_utils import (\n    framework_name_from_image,\n    empty_framework_version_warning,\n    python_deprecation_warning,\n)\nfrom sagemaker.sklearn.defaults import SKLEARN_VERSION, SKLEARN_NAME\nfrom sagemaker.sklearn.model import SKLearnModel\nfrom sagemaker.vpc_utils import VPC_CONFIG_DEFAULT\n\nlogger = logging.getLogger(\"sagemaker\")\n\n\nclass SKLearn(Framework):\n    \"\"\"Handle end-to-end training and deployment of custom Scikit-learn code.\"\"\"\n\n    __framework_name__ = SKLEARN_NAME\n\n    def __init__(\n        self,\n        entry_point,\n        framework_version=SKLEARN_VERSION,\n        source_dir=None,\n        hyperparameters=None,\n        py_version=\"py3\",\n        image_name=None,\n        **kwargs\n    ):\n        \"\"\"This ``Estimator`` executes an Scikit-learn script in a managed\n        Scikit-learn execution environment, within a SageMaker Training Job. The\n        managed Scikit-learn environment is an Amazon-built Docker container\n        that executes functions defined in the supplied ``entry_point`` Python\n        script.\n\n        Training is started by calling\n        :meth:`~sagemaker.amazon.estimator.Framework.fit` on this Estimator.\n        After training is complete, calling\n        :meth:`~sagemaker.amazon.estimator.Framework.deploy` creates a hosted\n        SageMaker endpoint and returns an\n        :class:`~sagemaker.amazon.sklearn.model.SKLearnPredictor` instance that\n        can be used to perform inference against the hosted model.\n\n        Technical documentation on preparing Scikit-learn scripts for\n        SageMaker training and using the Scikit-learn Estimator is available on\n        the project home-page: https://github.com/aws/sagemaker-python-sdk\n\n        Args:\n            entry_point (str): Path (absolute or relative) to the Python source\n                file which should be executed as the entry point to training.\n                This should be compatible with either Python 2.7 or Python 3.5.\n            framework_version (str): Scikit-learn version you want to use for\n                executing your model training code. List of supported versions\n                https://github.com/aws/sagemaker-python-sdk#sklearn-sagemaker-estimators\n            source_dir (str): Path (absolute or relative) to a directory with\n                any other training source code dependencies aside from tne entry\n                point file (default: None). Structure within this directory are\n                preserved when training on Amazon SageMaker.\n            hyperparameters (dict): Hyperparameters that will be used for\n                training (default: None). The hyperparameters are made\n                accessible as a dict[str, str] to the training code on\n                SageMaker. For convenience, this accepts other types for keys\n                and values, but ``str()`` will be called to convert them before\n                training.\n            py_version (str): Python version you want to use for executing your\n                model training code (default: 'py2'). One of 'py2' or 'py3'.\n            image_name (str): If specified, the estimator will use this image\n                for training and hosting, instead of selecting the appropriate\n                SageMaker official image based on framework_version and\n                py_version. It can be an ECR url or dockerhub image and tag.\n                Examples:\n                    123.dkr.ecr.us-west-2.amazonaws.com/my-custom-image:1.0\n                    custom-image:latest.\n            **kwargs: Additional kwargs passed to the\n                :class:`~sagemaker.estimator.Framework` constructor.\n        \"\"\"\n        # SciKit-Learn does not support distributed training or training on GPU instance types.\n        # Fail fast.\n        train_instance_type = kwargs.get(\"train_instance_type\")\n        _validate_not_gpu_instance_type(train_instance_type)\n\n        train_instance_count = kwargs.get(\"train_instance_count\")\n        if train_instance_count:\n            if train_instance_count != 1:\n                raise AttributeError(\n                    \"Scikit-Learn does not support distributed training. \"\n                    \"Please remove the 'train_instance_count' argument or set \"\n                    \"'train_instance_count=1' when initializing SKLearn.\"\n                )\n        super(SKLearn, self).__init__(\n            entry_point,\n            source_dir,\n            hyperparameters,\n            image_name=image_name,\n            **dict(kwargs, train_instance_count=1)\n        )\n\n        if py_version == \"py2\":\n            logger.warning(python_deprecation_warning(self.__framework_name__))\n\n        self.py_version = py_version\n\n        if framework_version is None:\n            logger.warning(empty_framework_version_warning(SKLEARN_VERSION, SKLEARN_VERSION))\n        self.framework_version = framework_version or SKLEARN_VERSION\n\n        if image_name is None:\n            image_tag = \"{}-{}-{}\".format(framework_version, \"cpu\", py_version)\n            self.image_name = default_framework_uri(\n                SKLearn.__framework_name__, self.sagemaker_session.boto_region_name, image_tag\n            )\n\n    def create_model(\n        self, model_server_workers=None, role=None, vpc_config_override=VPC_CONFIG_DEFAULT, **kwargs\n    ):\n        \"\"\"Create a SageMaker ``SKLearnModel`` object that can be deployed to an\n        ``Endpoint``.\n\n        Args:\n            model_server_workers (int): Optional. The number of worker processes\n                used by the inference server. If None, server will use one\n                worker per vCPU.\n            role (str): The ``ExecutionRoleArn`` IAM Role ARN for the ``Model``,\n                which is also used during transform jobs. If not specified, the\n                role from the Estimator will be used.\n            vpc_config_override (dict[str, list[str]]): Optional override for VpcConfig set on\n                the model. Default: use subnets and security groups from this Estimator.\n                * 'Subnets' (list[str]): List of subnet ids.\n                * 'SecurityGroupIds' (list[str]): List of security group ids.\n            **kwargs: Passed to initialization of ``SKLearnModel``.\n\n        Returns:\n            sagemaker.sklearn.model.SKLearnModel: A SageMaker ``SKLearnModel``\n            object. See :func:`~sagemaker.sklearn.model.SKLearnModel` for full details.\n        \"\"\"\n        role = role or self.role\n        return SKLearnModel(\n            self.model_data,\n            role,\n            self.entry_point,\n            source_dir=self._model_source_dir(),\n            enable_cloudwatch_metrics=self.enable_cloudwatch_metrics,\n            name=self._current_job_name,\n            container_log_level=self.container_log_level,\n            code_location=self.code_location,\n            py_version=self.py_version,\n            framework_version=self.framework_version,\n            model_server_workers=model_server_workers,\n            image=self.image_name,\n            sagemaker_session=self.sagemaker_session,\n            vpc_config=self.get_vpc_config(vpc_config_override),\n            **kwargs\n        )\n\n    @classmethod\n    def _prepare_init_params_from_job_description(cls, job_details, model_channel_name=None):\n        \"\"\"Convert the job description to init params that can be handled by the\n        class constructor\n\n        Args:\n            job_details: the returned job details from a describe_training_job\n                API call.\n            model_channel_name:\n\n        Returns:\n            dictionary: The transformed init_params\n        \"\"\"\n        init_params = super(SKLearn, cls)._prepare_init_params_from_job_description(job_details)\n\n        image_name = init_params.pop(\"image\")\n        framework, py_version, _, _ = framework_name_from_image(image_name)\n        init_params[\"py_version\"] = py_version\n\n        if framework and framework != cls.__framework_name__:\n            training_job_name = init_params[\"base_job_name\"]\n            raise ValueError(\n                \"Training job: {} didn't use image for requested framework\".format(\n                    training_job_name\n                )\n            )\n        if not framework:\n            # If we were unable to parse the framework name from the image it is not one of our\n            # officially supported images, in this case just add the image to the init params.\n            init_params[\"image_name\"] = image_name\n        return init_params\n\n\ndef _validate_not_gpu_instance_type(training_instance_type):\n    \"\"\"\n    Args:\n        training_instance_type:\n    \"\"\"\n    gpu_instance_types = [\n        \"ml.p2.xlarge\",\n        \"ml.p2.8xlarge\",\n        \"ml.p2.16xlarge\",\n        \"ml.p3.xlarge\",\n        \"ml.p3.8xlarge\",\n        \"ml.p3.16xlarge\",\n    ]\n\n    if training_instance_type in gpu_instance_types:\n        raise ValueError(\n            \"GPU training in not supported for Scikit-Learn. \"\n            \"Please pick a different instance type from here: \"\n            \"https://aws.amazon.com/ec2/instance-types/\"\n        )\n", "path": "src/sagemaker/sklearn/estimator.py"}], "after_files": [{"content": "# Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\"). You\n# may not use this file except in compliance with the License. A copy of\n# the License is located at\n#\n#     http://aws.amazon.com/apache2.0/\n#\n# or in the \"license\" file accompanying this file. This file is\n# distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n# ANY KIND, either express or implied. See the License for the specific\n# language governing permissions and limitations under the License.\n\"\"\"Placeholder docstring\"\"\"\nfrom __future__ import absolute_import\n\nimport logging\n\nfrom sagemaker.estimator import Framework\nfrom sagemaker.fw_registry import default_framework_uri\nfrom sagemaker.fw_utils import (\n    framework_name_from_image,\n    empty_framework_version_warning,\n    python_deprecation_warning,\n)\nfrom sagemaker.sklearn.defaults import SKLEARN_VERSION, SKLEARN_NAME\nfrom sagemaker.sklearn.model import SKLearnModel\nfrom sagemaker.vpc_utils import VPC_CONFIG_DEFAULT\n\nlogger = logging.getLogger(\"sagemaker\")\n\n\nclass SKLearn(Framework):\n    \"\"\"Handle end-to-end training and deployment of custom Scikit-learn code.\"\"\"\n\n    __framework_name__ = SKLEARN_NAME\n\n    def __init__(\n        self,\n        entry_point,\n        framework_version=SKLEARN_VERSION,\n        source_dir=None,\n        hyperparameters=None,\n        py_version=\"py3\",\n        image_name=None,\n        **kwargs\n    ):\n        \"\"\"This ``Estimator`` executes an Scikit-learn script in a managed\n        Scikit-learn execution environment, within a SageMaker Training Job. The\n        managed Scikit-learn environment is an Amazon-built Docker container\n        that executes functions defined in the supplied ``entry_point`` Python\n        script.\n\n        Training is started by calling\n        :meth:`~sagemaker.amazon.estimator.Framework.fit` on this Estimator.\n        After training is complete, calling\n        :meth:`~sagemaker.amazon.estimator.Framework.deploy` creates a hosted\n        SageMaker endpoint and returns an\n        :class:`~sagemaker.amazon.sklearn.model.SKLearnPredictor` instance that\n        can be used to perform inference against the hosted model.\n\n        Technical documentation on preparing Scikit-learn scripts for\n        SageMaker training and using the Scikit-learn Estimator is available on\n        the project home-page: https://github.com/aws/sagemaker-python-sdk\n\n        Args:\n            entry_point (str): Path (absolute or relative) to the Python source\n                file which should be executed as the entry point to training.\n                This should be compatible with either Python 2.7 or Python 3.5.\n            framework_version (str): Scikit-learn version you want to use for\n                executing your model training code. List of supported versions\n                https://github.com/aws/sagemaker-python-sdk#sklearn-sagemaker-estimators\n            source_dir (str): Path (absolute or relative) to a directory with\n                any other training source code dependencies aside from tne entry\n                point file (default: None). Structure within this directory are\n                preserved when training on Amazon SageMaker.\n            hyperparameters (dict): Hyperparameters that will be used for\n                training (default: None). The hyperparameters are made\n                accessible as a dict[str, str] to the training code on\n                SageMaker. For convenience, this accepts other types for keys\n                and values, but ``str()`` will be called to convert them before\n                training.\n            py_version (str): Python version you want to use for executing your\n                model training code (default: 'py2'). One of 'py2' or 'py3'.\n            image_name (str): If specified, the estimator will use this image\n                for training and hosting, instead of selecting the appropriate\n                SageMaker official image based on framework_version and\n                py_version. It can be an ECR url or dockerhub image and tag.\n                Examples:\n                    123.dkr.ecr.us-west-2.amazonaws.com/my-custom-image:1.0\n                    custom-image:latest.\n            **kwargs: Additional kwargs passed to the\n                :class:`~sagemaker.estimator.Framework` constructor.\n        \"\"\"\n        # SciKit-Learn does not support distributed training or training on GPU instance types.\n        # Fail fast.\n        train_instance_type = kwargs.get(\"train_instance_type\")\n        _validate_not_gpu_instance_type(train_instance_type)\n\n        train_instance_count = kwargs.get(\"train_instance_count\")\n        if train_instance_count:\n            if train_instance_count != 1:\n                raise AttributeError(\n                    \"Scikit-Learn does not support distributed training. \"\n                    \"Please remove the 'train_instance_count' argument or set \"\n                    \"'train_instance_count=1' when initializing SKLearn.\"\n                )\n        super(SKLearn, self).__init__(\n            entry_point,\n            source_dir,\n            hyperparameters,\n            image_name=image_name,\n            **dict(kwargs, train_instance_count=1)\n        )\n\n        if py_version == \"py2\":\n            logger.warning(python_deprecation_warning(self.__framework_name__))\n\n        self.py_version = py_version\n\n        if framework_version is None:\n            logger.warning(empty_framework_version_warning(SKLEARN_VERSION, SKLEARN_VERSION))\n        self.framework_version = framework_version or SKLEARN_VERSION\n\n        if image_name is None:\n            image_tag = \"{}-{}-{}\".format(framework_version, \"cpu\", py_version)\n            self.image_name = default_framework_uri(\n                SKLearn.__framework_name__, self.sagemaker_session.boto_region_name, image_tag\n            )\n\n    def create_model(\n        self, model_server_workers=None, role=None, vpc_config_override=VPC_CONFIG_DEFAULT, **kwargs\n    ):\n        \"\"\"Create a SageMaker ``SKLearnModel`` object that can be deployed to an\n        ``Endpoint``.\n\n        Args:\n            model_server_workers (int): Optional. The number of worker processes\n                used by the inference server. If None, server will use one\n                worker per vCPU.\n            role (str): The ``ExecutionRoleArn`` IAM Role ARN for the ``Model``,\n                which is also used during transform jobs. If not specified, the\n                role from the Estimator will be used.\n            vpc_config_override (dict[str, list[str]]): Optional override for VpcConfig set on\n                the model. Default: use subnets and security groups from this Estimator.\n                * 'Subnets' (list[str]): List of subnet ids.\n                * 'SecurityGroupIds' (list[str]): List of security group ids.\n            **kwargs: Passed to initialization of ``SKLearnModel``.\n\n        Returns:\n            sagemaker.sklearn.model.SKLearnModel: A SageMaker ``SKLearnModel``\n            object. See :func:`~sagemaker.sklearn.model.SKLearnModel` for full details.\n        \"\"\"\n        role = role or self.role\n\n        # remove unwanted entry_point kwarg\n        if \"entry_point\" in kwargs:\n            logger.debug(\"removing unused entry_point argument: %s\", str(kwargs[\"entry_point\"]))\n            kwargs = {k: v for k, v in kwargs.items() if k != \"entry_point\"}\n\n        return SKLearnModel(\n            self.model_data,\n            role,\n            self.entry_point,\n            source_dir=self._model_source_dir(),\n            enable_cloudwatch_metrics=self.enable_cloudwatch_metrics,\n            name=self._current_job_name,\n            container_log_level=self.container_log_level,\n            code_location=self.code_location,\n            py_version=self.py_version,\n            framework_version=self.framework_version,\n            model_server_workers=model_server_workers,\n            image=self.image_name,\n            sagemaker_session=self.sagemaker_session,\n            vpc_config=self.get_vpc_config(vpc_config_override),\n            **kwargs\n        )\n\n    @classmethod\n    def _prepare_init_params_from_job_description(cls, job_details, model_channel_name=None):\n        \"\"\"Convert the job description to init params that can be handled by the\n        class constructor\n\n        Args:\n            job_details: the returned job details from a describe_training_job\n                API call.\n            model_channel_name:\n\n        Returns:\n            dictionary: The transformed init_params\n        \"\"\"\n        init_params = super(SKLearn, cls)._prepare_init_params_from_job_description(job_details)\n\n        image_name = init_params.pop(\"image\")\n        framework, py_version, _, _ = framework_name_from_image(image_name)\n        init_params[\"py_version\"] = py_version\n\n        if framework and framework != cls.__framework_name__:\n            training_job_name = init_params[\"base_job_name\"]\n            raise ValueError(\n                \"Training job: {} didn't use image for requested framework\".format(\n                    training_job_name\n                )\n            )\n        if not framework:\n            # If we were unable to parse the framework name from the image it is not one of our\n            # officially supported images, in this case just add the image to the init params.\n            init_params[\"image_name\"] = image_name\n        return init_params\n\n\ndef _validate_not_gpu_instance_type(training_instance_type):\n    \"\"\"\n    Args:\n        training_instance_type:\n    \"\"\"\n    gpu_instance_types = [\n        \"ml.p2.xlarge\",\n        \"ml.p2.8xlarge\",\n        \"ml.p2.16xlarge\",\n        \"ml.p3.xlarge\",\n        \"ml.p3.8xlarge\",\n        \"ml.p3.16xlarge\",\n    ]\n\n    if training_instance_type in gpu_instance_types:\n        raise ValueError(\n            \"GPU training in not supported for Scikit-Learn. \"\n            \"Please pick a different instance type from here: \"\n            \"https://aws.amazon.com/ec2/instance-types/\"\n        )\n", "path": "src/sagemaker/sklearn/estimator.py"}]}