Repository: aws/sagemaker-python-sdk

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'


Discussion:
Hi @lihip, thanks for using SageMaker!

I haven't been able to reproduce this issue. Can you provide the rest of the code you used that led to this error (e.g. the training part too).
Same error for me.
sagemaker 1.36.0 was installed, but the error went away when I pip installed sagemaker==1.33.0.

Resolving patch:
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 @@ def create_model(
             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,


Test patch:
diff --git a/tests/unit/test_sklearn.py b/tests/unit/test_sklearn.py
--- a/tests/unit/test_sklearn.py
+++ b/tests/unit/test_sklearn.py
@@ -302,6 +302,26 @@ def test_sklearn(strftime, sagemaker_session, sklearn_version):
     assert isinstance(predictor, SKLearnPredictor)
 
 
+def test_transform_multiple_values_for_entry_point_issue(sagemaker_session, sklearn_version):
+    # https://github.com/aws/sagemaker-python-sdk/issues/974
+    sklearn = SKLearn(
+        entry_point=SCRIPT_PATH,
+        role=ROLE,
+        sagemaker_session=sagemaker_session,
+        train_instance_type=INSTANCE_TYPE,
+        py_version=PYTHON_VERSION,
+        framework_version=sklearn_version,
+    )
+
+    inputs = "s3://mybucket/train"
+
+    sklearn.fit(inputs=inputs)
+
+    transformer = sklearn.transformer(instance_count=1, instance_type="ml.m4.xlarge")
+    # if we got here, we didn't get a "multiple values" error
+    assert transformer is not None
+
+
 def test_fail_distributed_training(sagemaker_session, sklearn_version):
     with pytest.raises(AttributeError) as error:
         SKLearn(