We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
PipelineModel deploy method cannot find update_endpoint argument
Please fill out the form below.

### System Information
- **Framework (e.g. TensorFlow) / Algorithm (e.g. KMeans)**:
SKLearn with kNN
- **Framework Version**:
- **Python Version**:
Python 3
- **CPU or GPU**:
CPU
- **Python SDK Version**:
- **Are you using a custom image**:
No

### Describe the problem
I want to update an endpoint that already exists when deploying from a PipelineModel. The update_endpoint flag is supported on Estimators.deploy but not on PipelineModel.deploy

### Minimal repro / logs
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-116-1bc40bd315b2> in <module>()
     22                 instance_type='ml.t2.medium',
     23                 endpoint_name=endpoint_name,
---> 24                 update_endpoint=True)

TypeError: deploy() got an unexpected keyword argument 'update_endpoint'

- **Exact command to reproduce**:
model_name = 'inference-pipeline-' + timestamp_prefix
endpoint_name = 'sagemaker-ep'
sm_model = PipelineModel(
    name=model_name, 
    role=role, 
    models=[
        sklearn_preprocessor_model, 
        sklearn_estimator_model])

sm_model.deploy(initial_instance_count=1,
                instance_type='ml.t2.medium',
                endpoint_name=endpoint_name,
                update_endpoint=True)

--- 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/pipeline.py`
Content:
```
1 # Copyright 2017-2018 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 sagemaker
17 from sagemaker.session import Session
18 from sagemaker.utils import name_from_image
19 from sagemaker.transformer import Transformer
20 
21 
22 class PipelineModel(object):
23     """A pipeline of SageMaker
24     ``Model``s that can be deployed to an ``Endpoint``.
25     """
26 
27     def __init__(
28         self, models, role, predictor_cls=None, name=None, vpc_config=None, sagemaker_session=None
29     ):
30         """Initialize an SageMaker ``Model`` which can be used to build an
31         Inference Pipeline comprising of multiple model containers.
32 
33         Args:
34             models (list[sagemaker.Model]): For using multiple containers to
35                 build an inference pipeline, you can pass a list of ``sagemaker.Model`` objects
36                 in the order you want the inference to happen.
37             role (str): An AWS IAM role (either name or full ARN). The Amazon
38                 SageMaker training jobs and APIs that create Amazon SageMaker
39                 endpoints use this role to access training data and model
40                 artifacts. After the endpoint is created, the inference code
41                 might use the IAM role, if it needs to access an AWS resource.
42             predictor_cls (callable[string, sagemaker.session.Session]): A
43                 function to call to create a predictor (default: None). If not
44                 None, ``deploy`` will return the result of invoking this
45                 function on the created endpoint name.
46             name (str): The model name. If None, a default model name will be
47                 selected on each ``deploy``.
48             vpc_config (dict[str, list[str]]): The VpcConfig set on the model
49                 (default: None)
50                 * 'Subnets' (list[str]): List of subnet ids.
51                 * 'SecurityGroupIds' (list[str]): List of security group ids.
52             sagemaker_session (sagemaker.session.Session): A SageMaker Session
53                 object, used for SageMaker interactions (default: None). If not
54                 specified, one is created using the default AWS configuration
55                 chain.
56         """
57         self.models = models
58         self.role = role
59         self.predictor_cls = predictor_cls
60         self.name = name
61         self.vpc_config = vpc_config
62         self.sagemaker_session = sagemaker_session
63         self._model_name = None
64         self.endpoint_name = None
65 
66     def pipeline_container_def(self, instance_type):
67         """Return a dict created by ``sagemaker.pipeline_container_def()`` for
68         deploying this model to a specified instance type.
69 
70         Subclasses can override this to provide custom container definitions
71         for deployment to a specific instance type. Called by ``deploy()``.
72 
73         Args:
74             instance_type (str): The EC2 instance type to deploy this Model to.
75                 For example, 'ml.p2.xlarge'.
76 
77         Returns:
78             list[dict[str, str]]: A list of container definition objects usable
79             with the CreateModel API in the scenario of multiple containers
80             (Inference Pipeline).
81         """
82 
83         return sagemaker.pipeline_container_def(self.models, instance_type)
84 
85     def deploy(
86         self, initial_instance_count, instance_type, endpoint_name=None, tags=None, wait=True
87     ):
88         """Deploy this ``Model`` to an ``Endpoint`` and optionally return a
89         ``Predictor``.
90 
91         Create a SageMaker ``Model`` and ``EndpointConfig``, and deploy an
92         ``Endpoint`` from this ``Model``. If ``self.predictor_cls`` is not None,
93         this method returns a the result of invoking ``self.predictor_cls`` on
94         the created endpoint name.
95 
96         The name of the created model is accessible in the ``name`` field of
97         this ``Model`` after deploy returns
98 
99         The name of the created endpoint is accessible in the
100         ``endpoint_name`` field of this ``Model`` after deploy returns.
101 
102         Args:
103             initial_instance_count (int): The initial number of instances to run
104                 in the ``Endpoint`` created from this ``Model``.
105             instance_type (str): The EC2 instance type to deploy this Model to.
106                 For example, 'ml.p2.xlarge'.
107             endpoint_name (str): The name of the endpoint to create (default:
108                 None). If not specified, a unique endpoint name will be created.
109             tags (List[dict[str, str]]): The list of tags to attach to this
110                 specific endpoint.
111             wait (bool): Whether the call should wait until the deployment of
112                 model completes (default: True).
113 
114         Returns:
115             callable[string, sagemaker.session.Session] or None: Invocation of
116             ``self.predictor_cls`` on the created endpoint name, if ``self.predictor_cls``
117             is not None. Otherwise, return None.
118         """
119         if not self.sagemaker_session:
120             self.sagemaker_session = Session()
121 
122         containers = self.pipeline_container_def(instance_type)
123 
124         self.name = self.name or name_from_image(containers[0]["Image"])
125         self.sagemaker_session.create_model(
126             self.name, self.role, containers, vpc_config=self.vpc_config
127         )
128 
129         production_variant = sagemaker.production_variant(
130             self.name, instance_type, initial_instance_count
131         )
132         self.endpoint_name = endpoint_name or self.name
133         self.sagemaker_session.endpoint_from_production_variants(
134             self.endpoint_name, [production_variant], tags, wait=wait
135         )
136         if self.predictor_cls:
137             return self.predictor_cls(self.endpoint_name, self.sagemaker_session)
138         return None
139 
140     def _create_sagemaker_pipeline_model(self, instance_type):
141         """Create a SageMaker Model Entity
142 
143         Args:
144             instance_type (str): The EC2 instance type that this Model will be
145                 used for, this is only used to determine if the image needs GPU
146                 support or not.
147         """
148         if not self.sagemaker_session:
149             self.sagemaker_session = Session()
150 
151         containers = self.pipeline_container_def(instance_type)
152 
153         self.name = self.name or name_from_image(containers[0]["Image"])
154         self.sagemaker_session.create_model(
155             self.name, self.role, containers, vpc_config=self.vpc_config
156         )
157 
158     def transformer(
159         self,
160         instance_count,
161         instance_type,
162         strategy=None,
163         assemble_with=None,
164         output_path=None,
165         output_kms_key=None,
166         accept=None,
167         env=None,
168         max_concurrent_transforms=None,
169         max_payload=None,
170         tags=None,
171         volume_kms_key=None,
172     ):
173         """Return a ``Transformer`` that uses this Model.
174 
175         Args:
176             instance_count (int): Number of EC2 instances to use.
177             instance_type (str): Type of EC2 instance to use, for example,
178                 'ml.c4.xlarge'.
179             strategy (str): The strategy used to decide how to batch records in
180                 a single request (default: None). Valid values: 'MULTI_RECORD'
181                 and 'SINGLE_RECORD'.
182             assemble_with (str): How the output is assembled (default: None).
183                 Valid values: 'Line' or 'None'.
184             output_path (str): S3 location for saving the transform result. If
185                 not specified, results are stored to a default bucket.
186             output_kms_key (str): Optional. KMS key ID for encrypting the
187                 transform output (default: None).
188             accept (str): The content type accepted by the endpoint deployed
189                 during the transform job.
190             env (dict): Environment variables to be set for use during the
191                 transform job (default: None).
192             max_concurrent_transforms (int): The maximum number of HTTP requests
193                 to be made to each individual transform container at one time.
194             max_payload (int): Maximum size of the payload in a single HTTP
195                 request to the container in MB.
196             tags (list[dict]): List of tags for labeling a transform job. If
197                 none specified, then the tags used for the training job are used
198                 for the transform job.
199             volume_kms_key (str): Optional. KMS key ID for encrypting the volume
200                 attached to the ML compute instance (default: None).
201         """
202         self._create_sagemaker_pipeline_model(instance_type)
203 
204         return Transformer(
205             self.name,
206             instance_count,
207             instance_type,
208             strategy=strategy,
209             assemble_with=assemble_with,
210             output_path=output_path,
211             output_kms_key=output_kms_key,
212             accept=accept,
213             max_concurrent_transforms=max_concurrent_transforms,
214             max_payload=max_payload,
215             env=env,
216             tags=tags,
217             base_transform_job_name=self.name,
218             volume_kms_key=volume_kms_key,
219             sagemaker_session=self.sagemaker_session,
220         )
221 
222     def delete_model(self):
223         """Delete the SageMaker model backing this pipeline model. This does not
224         delete the list of SageMaker models used in multiple containers to build
225         the inference pipeline.
226         """
227 
228         if self.name is None:
229             raise ValueError("The SageMaker model must be created before attempting to delete.")
230 
231         self.sagemaker_session.delete_model(self.name)
232
```
--- 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/pipeline.py b/src/sagemaker/pipeline.py
--- a/src/sagemaker/pipeline.py
+++ b/src/sagemaker/pipeline.py
@@ -83,7 +83,13 @@
         return sagemaker.pipeline_container_def(self.models, instance_type)
 
     def deploy(
-        self, initial_instance_count, instance_type, endpoint_name=None, tags=None, wait=True
+        self,
+        initial_instance_count,
+        instance_type,
+        endpoint_name=None,
+        tags=None,
+        wait=True,
+        update_endpoint=False,
     ):
         """Deploy this ``Model`` to an ``Endpoint`` and optionally return a
         ``Predictor``.
@@ -110,6 +116,11 @@
                 specific endpoint.
             wait (bool): Whether the call should wait until the deployment of
                 model completes (default: True).
+            update_endpoint (bool): Flag to update the model in an existing
+                Amazon SageMaker endpoint. If True, this will deploy a new
+                EndpointConfig to an already existing endpoint and delete
+                resources corresponding to the previous EndpointConfig. If
+                False, a new endpoint will be created. Default: False
 
         Returns:
             callable[string, sagemaker.session.Session] or None: Invocation of
@@ -130,9 +141,21 @@
             self.name, instance_type, initial_instance_count
         )
         self.endpoint_name = endpoint_name or self.name
-        self.sagemaker_session.endpoint_from_production_variants(
-            self.endpoint_name, [production_variant], tags, wait=wait
-        )
+
+        if update_endpoint:
+            endpoint_config_name = self.sagemaker_session.create_endpoint_config(
+                name=self.name,
+                model_name=self.name,
+                initial_instance_count=initial_instance_count,
+                instance_type=instance_type,
+                tags=tags,
+            )
+            self.sagemaker_session.update_endpoint(self.endpoint_name, endpoint_config_name)
+        else:
+            self.sagemaker_session.endpoint_from_production_variants(
+                self.endpoint_name, [production_variant], tags, wait=wait
+            )
+
         if self.predictor_cls:
             return self.predictor_cls(self.endpoint_name, self.sagemaker_session)
         return None

{"golden_diff": "diff --git a/src/sagemaker/pipeline.py b/src/sagemaker/pipeline.py\n--- a/src/sagemaker/pipeline.py\n+++ b/src/sagemaker/pipeline.py\n@@ -83,7 +83,13 @@\n         return sagemaker.pipeline_container_def(self.models, instance_type)\n \n     def deploy(\n-        self, initial_instance_count, instance_type, endpoint_name=None, tags=None, wait=True\n+        self,\n+        initial_instance_count,\n+        instance_type,\n+        endpoint_name=None,\n+        tags=None,\n+        wait=True,\n+        update_endpoint=False,\n     ):\n         \"\"\"Deploy this ``Model`` to an ``Endpoint`` and optionally return a\n         ``Predictor``.\n@@ -110,6 +116,11 @@\n                 specific endpoint.\n             wait (bool): Whether the call should wait until the deployment of\n                 model completes (default: True).\n+            update_endpoint (bool): Flag to update the model in an existing\n+                Amazon SageMaker endpoint. If True, this will deploy a new\n+                EndpointConfig to an already existing endpoint and delete\n+                resources corresponding to the previous EndpointConfig. If\n+                False, a new endpoint will be created. Default: False\n \n         Returns:\n             callable[string, sagemaker.session.Session] or None: Invocation of\n@@ -130,9 +141,21 @@\n             self.name, instance_type, initial_instance_count\n         )\n         self.endpoint_name = endpoint_name or self.name\n-        self.sagemaker_session.endpoint_from_production_variants(\n-            self.endpoint_name, [production_variant], tags, wait=wait\n-        )\n+\n+        if update_endpoint:\n+            endpoint_config_name = self.sagemaker_session.create_endpoint_config(\n+                name=self.name,\n+                model_name=self.name,\n+                initial_instance_count=initial_instance_count,\n+                instance_type=instance_type,\n+                tags=tags,\n+            )\n+            self.sagemaker_session.update_endpoint(self.endpoint_name, endpoint_config_name)\n+        else:\n+            self.sagemaker_session.endpoint_from_production_variants(\n+                self.endpoint_name, [production_variant], tags, wait=wait\n+            )\n+\n         if self.predictor_cls:\n             return self.predictor_cls(self.endpoint_name, self.sagemaker_session)\n         return None\n", "issue": "PipelineModel deploy method cannot find update_endpoint argument\nPlease fill out the form below.\r\n\r\n### System Information\r\n- **Framework (e.g. TensorFlow) / Algorithm (e.g. KMeans)**:\r\nSKLearn with kNN\r\n- **Framework Version**:\r\n- **Python Version**:\r\nPython 3\r\n- **CPU or GPU**:\r\nCPU\r\n- **Python SDK Version**:\r\n- **Are you using a custom image**:\r\nNo\r\n\r\n### Describe the problem\r\nI want to update an endpoint that already exists when deploying from a PipelineModel. The update_endpoint flag is supported on Estimators.deploy but not on PipelineModel.deploy\r\n\r\n### Minimal repro / logs\r\n---------------------------------------------------------------------------\r\nTypeError                                 Traceback (most recent call last)\r\n<ipython-input-116-1bc40bd315b2> in <module>()\r\n     22                 instance_type='ml.t2.medium',\r\n     23                 endpoint_name=endpoint_name,\r\n---> 24                 update_endpoint=True)\r\n\r\nTypeError: deploy() got an unexpected keyword argument 'update_endpoint'\r\n\r\n- **Exact command to reproduce**:\r\nmodel_name = 'inference-pipeline-' + timestamp_prefix\r\nendpoint_name = 'sagemaker-ep'\r\nsm_model = PipelineModel(\r\n    name=model_name, \r\n    role=role, \r\n    models=[\r\n        sklearn_preprocessor_model, \r\n        sklearn_estimator_model])\r\n\r\nsm_model.deploy(initial_instance_count=1,\r\n                instance_type='ml.t2.medium',\r\n                endpoint_name=endpoint_name,\r\n                update_endpoint=True)\n", "before_files": [{"content": "# Copyright 2017-2018 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 sagemaker\nfrom sagemaker.session import Session\nfrom sagemaker.utils import name_from_image\nfrom sagemaker.transformer import Transformer\n\n\nclass PipelineModel(object):\n    \"\"\"A pipeline of SageMaker\n    ``Model``s that can be deployed to an ``Endpoint``.\n    \"\"\"\n\n    def __init__(\n        self, models, role, predictor_cls=None, name=None, vpc_config=None, sagemaker_session=None\n    ):\n        \"\"\"Initialize an SageMaker ``Model`` which can be used to build an\n        Inference Pipeline comprising of multiple model containers.\n\n        Args:\n            models (list[sagemaker.Model]): For using multiple containers to\n                build an inference pipeline, you can pass a list of ``sagemaker.Model`` objects\n                in the order you want the inference to happen.\n            role (str): An AWS IAM role (either name or full ARN). The Amazon\n                SageMaker training jobs and APIs that create Amazon SageMaker\n                endpoints use this role to access training data and model\n                artifacts. After the endpoint is created, the inference code\n                might use the IAM role, if it needs to access an AWS resource.\n            predictor_cls (callable[string, sagemaker.session.Session]): A\n                function to call to create a predictor (default: None). If not\n                None, ``deploy`` will return the result of invoking this\n                function on the created endpoint name.\n            name (str): The model name. If None, a default model name will be\n                selected on each ``deploy``.\n            vpc_config (dict[str, list[str]]): The VpcConfig set on the model\n                (default: None)\n                * 'Subnets' (list[str]): List of subnet ids.\n                * 'SecurityGroupIds' (list[str]): List of security group ids.\n            sagemaker_session (sagemaker.session.Session): A SageMaker Session\n                object, used for SageMaker interactions (default: None). If not\n                specified, one is created using the default AWS configuration\n                chain.\n        \"\"\"\n        self.models = models\n        self.role = role\n        self.predictor_cls = predictor_cls\n        self.name = name\n        self.vpc_config = vpc_config\n        self.sagemaker_session = sagemaker_session\n        self._model_name = None\n        self.endpoint_name = None\n\n    def pipeline_container_def(self, instance_type):\n        \"\"\"Return a dict created by ``sagemaker.pipeline_container_def()`` for\n        deploying this model to a specified instance type.\n\n        Subclasses can override this to provide custom container definitions\n        for deployment to a specific instance type. Called by ``deploy()``.\n\n        Args:\n            instance_type (str): The EC2 instance type to deploy this Model to.\n                For example, 'ml.p2.xlarge'.\n\n        Returns:\n            list[dict[str, str]]: A list of container definition objects usable\n            with the CreateModel API in the scenario of multiple containers\n            (Inference Pipeline).\n        \"\"\"\n\n        return sagemaker.pipeline_container_def(self.models, instance_type)\n\n    def deploy(\n        self, initial_instance_count, instance_type, endpoint_name=None, tags=None, wait=True\n    ):\n        \"\"\"Deploy this ``Model`` to an ``Endpoint`` and optionally return a\n        ``Predictor``.\n\n        Create a SageMaker ``Model`` and ``EndpointConfig``, and deploy an\n        ``Endpoint`` from this ``Model``. If ``self.predictor_cls`` is not None,\n        this method returns a the result of invoking ``self.predictor_cls`` on\n        the created endpoint name.\n\n        The name of the created model is accessible in the ``name`` field of\n        this ``Model`` after deploy returns\n\n        The name of the created endpoint is accessible in the\n        ``endpoint_name`` field of this ``Model`` after deploy returns.\n\n        Args:\n            initial_instance_count (int): The initial number of instances to run\n                in the ``Endpoint`` created from this ``Model``.\n            instance_type (str): The EC2 instance type to deploy this Model to.\n                For example, 'ml.p2.xlarge'.\n            endpoint_name (str): The name of the endpoint to create (default:\n                None). If not specified, a unique endpoint name will be created.\n            tags (List[dict[str, str]]): The list of tags to attach to this\n                specific endpoint.\n            wait (bool): Whether the call should wait until the deployment of\n                model completes (default: True).\n\n        Returns:\n            callable[string, sagemaker.session.Session] or None: Invocation of\n            ``self.predictor_cls`` on the created endpoint name, if ``self.predictor_cls``\n            is not None. Otherwise, return None.\n        \"\"\"\n        if not self.sagemaker_session:\n            self.sagemaker_session = Session()\n\n        containers = self.pipeline_container_def(instance_type)\n\n        self.name = self.name or name_from_image(containers[0][\"Image\"])\n        self.sagemaker_session.create_model(\n            self.name, self.role, containers, vpc_config=self.vpc_config\n        )\n\n        production_variant = sagemaker.production_variant(\n            self.name, instance_type, initial_instance_count\n        )\n        self.endpoint_name = endpoint_name or self.name\n        self.sagemaker_session.endpoint_from_production_variants(\n            self.endpoint_name, [production_variant], tags, wait=wait\n        )\n        if self.predictor_cls:\n            return self.predictor_cls(self.endpoint_name, self.sagemaker_session)\n        return None\n\n    def _create_sagemaker_pipeline_model(self, instance_type):\n        \"\"\"Create a SageMaker Model Entity\n\n        Args:\n            instance_type (str): The EC2 instance type that this Model will be\n                used for, this is only used to determine if the image needs GPU\n                support or not.\n        \"\"\"\n        if not self.sagemaker_session:\n            self.sagemaker_session = Session()\n\n        containers = self.pipeline_container_def(instance_type)\n\n        self.name = self.name or name_from_image(containers[0][\"Image\"])\n        self.sagemaker_session.create_model(\n            self.name, self.role, containers, vpc_config=self.vpc_config\n        )\n\n    def transformer(\n        self,\n        instance_count,\n        instance_type,\n        strategy=None,\n        assemble_with=None,\n        output_path=None,\n        output_kms_key=None,\n        accept=None,\n        env=None,\n        max_concurrent_transforms=None,\n        max_payload=None,\n        tags=None,\n        volume_kms_key=None,\n    ):\n        \"\"\"Return a ``Transformer`` that uses this Model.\n\n        Args:\n            instance_count (int): Number of EC2 instances to use.\n            instance_type (str): Type of EC2 instance to use, for example,\n                'ml.c4.xlarge'.\n            strategy (str): The strategy used to decide how to batch records in\n                a single request (default: None). Valid values: 'MULTI_RECORD'\n                and 'SINGLE_RECORD'.\n            assemble_with (str): How the output is assembled (default: None).\n                Valid values: 'Line' or 'None'.\n            output_path (str): S3 location for saving the transform result. If\n                not specified, results are stored to a default bucket.\n            output_kms_key (str): Optional. KMS key ID for encrypting the\n                transform output (default: None).\n            accept (str): The content type accepted by the endpoint deployed\n                during the transform job.\n            env (dict): Environment variables to be set for use during the\n                transform job (default: None).\n            max_concurrent_transforms (int): The maximum number of HTTP requests\n                to be made to each individual transform container at one time.\n            max_payload (int): Maximum size of the payload in a single HTTP\n                request to the container in MB.\n            tags (list[dict]): List of tags for labeling a transform job. If\n                none specified, then the tags used for the training job are used\n                for the transform job.\n            volume_kms_key (str): Optional. KMS key ID for encrypting the volume\n                attached to the ML compute instance (default: None).\n        \"\"\"\n        self._create_sagemaker_pipeline_model(instance_type)\n\n        return Transformer(\n            self.name,\n            instance_count,\n            instance_type,\n            strategy=strategy,\n            assemble_with=assemble_with,\n            output_path=output_path,\n            output_kms_key=output_kms_key,\n            accept=accept,\n            max_concurrent_transforms=max_concurrent_transforms,\n            max_payload=max_payload,\n            env=env,\n            tags=tags,\n            base_transform_job_name=self.name,\n            volume_kms_key=volume_kms_key,\n            sagemaker_session=self.sagemaker_session,\n        )\n\n    def delete_model(self):\n        \"\"\"Delete the SageMaker model backing this pipeline model. This does not\n        delete the list of SageMaker models used in multiple containers to build\n        the inference pipeline.\n        \"\"\"\n\n        if self.name is None:\n            raise ValueError(\"The SageMaker model must be created before attempting to delete.\")\n\n        self.sagemaker_session.delete_model(self.name)\n", "path": "src/sagemaker/pipeline.py"}], "after_files": [{"content": "# Copyright 2017-2018 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 sagemaker\nfrom sagemaker.session import Session\nfrom sagemaker.utils import name_from_image\nfrom sagemaker.transformer import Transformer\n\n\nclass PipelineModel(object):\n    \"\"\"A pipeline of SageMaker\n    ``Model``s that can be deployed to an ``Endpoint``.\n    \"\"\"\n\n    def __init__(\n        self, models, role, predictor_cls=None, name=None, vpc_config=None, sagemaker_session=None\n    ):\n        \"\"\"Initialize an SageMaker ``Model`` which can be used to build an\n        Inference Pipeline comprising of multiple model containers.\n\n        Args:\n            models (list[sagemaker.Model]): For using multiple containers to\n                build an inference pipeline, you can pass a list of ``sagemaker.Model`` objects\n                in the order you want the inference to happen.\n            role (str): An AWS IAM role (either name or full ARN). The Amazon\n                SageMaker training jobs and APIs that create Amazon SageMaker\n                endpoints use this role to access training data and model\n                artifacts. After the endpoint is created, the inference code\n                might use the IAM role, if it needs to access an AWS resource.\n            predictor_cls (callable[string, sagemaker.session.Session]): A\n                function to call to create a predictor (default: None). If not\n                None, ``deploy`` will return the result of invoking this\n                function on the created endpoint name.\n            name (str): The model name. If None, a default model name will be\n                selected on each ``deploy``.\n            vpc_config (dict[str, list[str]]): The VpcConfig set on the model\n                (default: None)\n                * 'Subnets' (list[str]): List of subnet ids.\n                * 'SecurityGroupIds' (list[str]): List of security group ids.\n            sagemaker_session (sagemaker.session.Session): A SageMaker Session\n                object, used for SageMaker interactions (default: None). If not\n                specified, one is created using the default AWS configuration\n                chain.\n        \"\"\"\n        self.models = models\n        self.role = role\n        self.predictor_cls = predictor_cls\n        self.name = name\n        self.vpc_config = vpc_config\n        self.sagemaker_session = sagemaker_session\n        self._model_name = None\n        self.endpoint_name = None\n\n    def pipeline_container_def(self, instance_type):\n        \"\"\"Return a dict created by ``sagemaker.pipeline_container_def()`` for\n        deploying this model to a specified instance type.\n\n        Subclasses can override this to provide custom container definitions\n        for deployment to a specific instance type. Called by ``deploy()``.\n\n        Args:\n            instance_type (str): The EC2 instance type to deploy this Model to.\n                For example, 'ml.p2.xlarge'.\n\n        Returns:\n            list[dict[str, str]]: A list of container definition objects usable\n            with the CreateModel API in the scenario of multiple containers\n            (Inference Pipeline).\n        \"\"\"\n\n        return sagemaker.pipeline_container_def(self.models, instance_type)\n\n    def deploy(\n        self,\n        initial_instance_count,\n        instance_type,\n        endpoint_name=None,\n        tags=None,\n        wait=True,\n        update_endpoint=False,\n    ):\n        \"\"\"Deploy this ``Model`` to an ``Endpoint`` and optionally return a\n        ``Predictor``.\n\n        Create a SageMaker ``Model`` and ``EndpointConfig``, and deploy an\n        ``Endpoint`` from this ``Model``. If ``self.predictor_cls`` is not None,\n        this method returns a the result of invoking ``self.predictor_cls`` on\n        the created endpoint name.\n\n        The name of the created model is accessible in the ``name`` field of\n        this ``Model`` after deploy returns\n\n        The name of the created endpoint is accessible in the\n        ``endpoint_name`` field of this ``Model`` after deploy returns.\n\n        Args:\n            initial_instance_count (int): The initial number of instances to run\n                in the ``Endpoint`` created from this ``Model``.\n            instance_type (str): The EC2 instance type to deploy this Model to.\n                For example, 'ml.p2.xlarge'.\n            endpoint_name (str): The name of the endpoint to create (default:\n                None). If not specified, a unique endpoint name will be created.\n            tags (List[dict[str, str]]): The list of tags to attach to this\n                specific endpoint.\n            wait (bool): Whether the call should wait until the deployment of\n                model completes (default: True).\n            update_endpoint (bool): Flag to update the model in an existing\n                Amazon SageMaker endpoint. If True, this will deploy a new\n                EndpointConfig to an already existing endpoint and delete\n                resources corresponding to the previous EndpointConfig. If\n                False, a new endpoint will be created. Default: False\n\n        Returns:\n            callable[string, sagemaker.session.Session] or None: Invocation of\n            ``self.predictor_cls`` on the created endpoint name, if ``self.predictor_cls``\n            is not None. Otherwise, return None.\n        \"\"\"\n        if not self.sagemaker_session:\n            self.sagemaker_session = Session()\n\n        containers = self.pipeline_container_def(instance_type)\n\n        self.name = self.name or name_from_image(containers[0][\"Image\"])\n        self.sagemaker_session.create_model(\n            self.name, self.role, containers, vpc_config=self.vpc_config\n        )\n\n        production_variant = sagemaker.production_variant(\n            self.name, instance_type, initial_instance_count\n        )\n        self.endpoint_name = endpoint_name or self.name\n\n        if update_endpoint:\n            endpoint_config_name = self.sagemaker_session.create_endpoint_config(\n                name=self.name,\n                model_name=self.name,\n                initial_instance_count=initial_instance_count,\n                instance_type=instance_type,\n                tags=tags,\n            )\n            self.sagemaker_session.update_endpoint(self.endpoint_name, endpoint_config_name)\n        else:\n            self.sagemaker_session.endpoint_from_production_variants(\n                self.endpoint_name, [production_variant], tags, wait=wait\n            )\n\n        if self.predictor_cls:\n            return self.predictor_cls(self.endpoint_name, self.sagemaker_session)\n        return None\n\n    def _create_sagemaker_pipeline_model(self, instance_type):\n        \"\"\"Create a SageMaker Model Entity\n\n        Args:\n            instance_type (str): The EC2 instance type that this Model will be\n                used for, this is only used to determine if the image needs GPU\n                support or not.\n        \"\"\"\n        if not self.sagemaker_session:\n            self.sagemaker_session = Session()\n\n        containers = self.pipeline_container_def(instance_type)\n\n        self.name = self.name or name_from_image(containers[0][\"Image\"])\n        self.sagemaker_session.create_model(\n            self.name, self.role, containers, vpc_config=self.vpc_config\n        )\n\n    def transformer(\n        self,\n        instance_count,\n        instance_type,\n        strategy=None,\n        assemble_with=None,\n        output_path=None,\n        output_kms_key=None,\n        accept=None,\n        env=None,\n        max_concurrent_transforms=None,\n        max_payload=None,\n        tags=None,\n        volume_kms_key=None,\n    ):\n        \"\"\"Return a ``Transformer`` that uses this Model.\n\n        Args:\n            instance_count (int): Number of EC2 instances to use.\n            instance_type (str): Type of EC2 instance to use, for example,\n                'ml.c4.xlarge'.\n            strategy (str): The strategy used to decide how to batch records in\n                a single request (default: None). Valid values: 'MULTI_RECORD'\n                and 'SINGLE_RECORD'.\n            assemble_with (str): How the output is assembled (default: None).\n                Valid values: 'Line' or 'None'.\n            output_path (str): S3 location for saving the transform result. If\n                not specified, results are stored to a default bucket.\n            output_kms_key (str): Optional. KMS key ID for encrypting the\n                transform output (default: None).\n            accept (str): The content type accepted by the endpoint deployed\n                during the transform job.\n            env (dict): Environment variables to be set for use during the\n                transform job (default: None).\n            max_concurrent_transforms (int): The maximum number of HTTP requests\n                to be made to each individual transform container at one time.\n            max_payload (int): Maximum size of the payload in a single HTTP\n                request to the container in MB.\n            tags (list[dict]): List of tags for labeling a transform job. If\n                none specified, then the tags used for the training job are used\n                for the transform job.\n            volume_kms_key (str): Optional. KMS key ID for encrypting the volume\n                attached to the ML compute instance (default: None).\n        \"\"\"\n        self._create_sagemaker_pipeline_model(instance_type)\n\n        return Transformer(\n            self.name,\n            instance_count,\n            instance_type,\n            strategy=strategy,\n            assemble_with=assemble_with,\n            output_path=output_path,\n            output_kms_key=output_kms_key,\n            accept=accept,\n            max_concurrent_transforms=max_concurrent_transforms,\n            max_payload=max_payload,\n            env=env,\n            tags=tags,\n            base_transform_job_name=self.name,\n            volume_kms_key=volume_kms_key,\n            sagemaker_session=self.sagemaker_session,\n        )\n\n    def delete_model(self):\n        \"\"\"Delete the SageMaker model backing this pipeline model. This does not\n        delete the list of SageMaker models used in multiple containers to build\n        the inference pipeline.\n        \"\"\"\n\n        if self.name is None:\n            raise ValueError(\"The SageMaker model must be created before attempting to delete.\")\n\n        self.sagemaker_session.delete_model(self.name)\n", "path": "src/sagemaker/pipeline.py"}]}