prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  [PS-1] RPC service `pull_embedding_vector` implementation
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `elasticdl/python/ps/servicer.py`
  Content:
  ```
  1 import threading
  2 
  3 from google.protobuf import empty_pb2
  4 
  5 from elasticdl.proto import elasticdl_pb2, elasticdl_pb2_grpc
  6 from elasticdl.python.common.dtypes import dtype_numpy_to_tensor
  7 
  8 
  9 class PserverServicer(elasticdl_pb2_grpc.PserverServicer):
  10     """PS service implementation"""
  11 
  12     def __init__(
  13         self,
  14         parameters,
  15         grads_to_wait,
  16         optimizer,
  17         lr_staleness_modulation=False,
  18         use_async=False,
  19     ):
  20         self._parameters = parameters
  21         self._grads_to_wait = grads_to_wait
  22         self._optimizer = optimizer
  23         self._lr_staleness_modulation = lr_staleness_modulation
  24         self._use_async = use_async
  25         self._version = 0
  26         self._lock = threading.Lock()
  27 
  28     def pull_variable(self, request, _):
  29         """
  30         Response with all non-embedding parameters if initialized.
  31         """
  32         res = elasticdl_pb2.PullVariableResponse()
  33         if not self._parameters.init_status:
  34             res.model_init_status = False
  35             return res
  36 
  37         # Only sync-SGD needs lock
  38         # TODO: use a read-write lock to support multiple concurrent reads
  39         if not self._use_async:
  40             self._lock.acquire()
  41         res.model.version = self._parameters.version
  42         for name, var in self._parameters.non_embedding_params.items():
  43             tensor = res.model.param.add()
  44             tensor.name = name
  45             tensor.dim.extend(var.shape.as_list())
  46             var_values = var.numpy()
  47             tensor.content = var_values.tobytes()
  48             tensor.dtype = dtype_numpy_to_tensor(var_values.dtype)
  49         if not self._use_async:
  50             self._lock.release()
  51         res.model_init_status = True
  52         return res
  53 
  54     def pull_embedding_vector(self, request, _):
  55         # TODO: implement this RPC service
  56         return elasticdl_pb2.Tensor()
  57 
  58     def push_model(self, request, _):
  59         with self._lock:
  60             self._parameters.init_from_model_pb(request)
  61         return empty_pb2.Empty()
  62 
  63     def push_gradient(self, request, _):
  64         # TODO: implement this RPC service
  65         return elasticdl_pb2.PushGradientResponse()
  66
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/elasticdl/python/ps/servicer.py b/elasticdl/python/ps/servicer.py
  --- a/elasticdl/python/ps/servicer.py
  +++ b/elasticdl/python/ps/servicer.py
  @@ -4,6 +4,7 @@
   
   from elasticdl.proto import elasticdl_pb2, elasticdl_pb2_grpc
   from elasticdl.python.common.dtypes import dtype_numpy_to_tensor
  +from elasticdl.python.common.tensor import Tensor, serialize_tensor
   
   
   class PserverServicer(elasticdl_pb2_grpc.PserverServicer):
  @@ -52,8 +53,15 @@
           return res
   
       def pull_embedding_vector(self, request, _):
  -        # TODO: implement this RPC service
  -        return elasticdl_pb2.Tensor()
  +        ret = elasticdl_pb2.Tensor()
  +        if not request.ids:
  +            return ret
  +        embedding_vectors = self._parameters.get_embedding_param(
  +            request.name, request.ids
  +        )
  +        tensor = Tensor(values=embedding_vectors)
  +        serialize_tensor(tensor, ret)
  +        return ret
   
       def push_model(self, request, _):
           with self._lock:
  
verification_info: {"golden_diff": "diff --git a/elasticdl/python/ps/servicer.py b/elasticdl/python/ps/servicer.py\n--- a/elasticdl/python/ps/servicer.py\n+++ b/elasticdl/python/ps/servicer.py\n@@ -4,6 +4,7 @@\n \n from elasticdl.proto import elasticdl_pb2, elasticdl_pb2_grpc\n from elasticdl.python.common.dtypes import dtype_numpy_to_tensor\n+from elasticdl.python.common.tensor import Tensor, serialize_tensor\n \n \n class PserverServicer(elasticdl_pb2_grpc.PserverServicer):\n@@ -52,8 +53,15 @@\n         return res\n \n     def pull_embedding_vector(self, request, _):\n-        # TODO: implement this RPC service\n-        return elasticdl_pb2.Tensor()\n+        ret = elasticdl_pb2.Tensor()\n+        if not request.ids:\n+            return ret\n+        embedding_vectors = self._parameters.get_embedding_param(\n+            request.name, request.ids\n+        )\n+        tensor = Tensor(values=embedding_vectors)\n+        serialize_tensor(tensor, ret)\n+        return ret\n \n     def push_model(self, request, _):\n         with self._lock:\n", "issue": "[PS-1] RPC service `pull_embedding_vector` implementation\n\n", "before_files": [{"content": "import threading\n\nfrom google.protobuf import empty_pb2\n\nfrom elasticdl.proto import elasticdl_pb2, elasticdl_pb2_grpc\nfrom elasticdl.python.common.dtypes import dtype_numpy_to_tensor\n\n\nclass PserverServicer(elasticdl_pb2_grpc.PserverServicer):\n    \"\"\"PS service implementation\"\"\"\n\n    def __init__(\n        self,\n        parameters,\n        grads_to_wait,\n        optimizer,\n        lr_staleness_modulation=False,\n        use_async=False,\n    ):\n        self._parameters = parameters\n        self._grads_to_wait = grads_to_wait\n        self._optimizer = optimizer\n        self._lr_staleness_modulation = lr_staleness_modulation\n        self._use_async = use_async\n        self._version = 0\n        self._lock = threading.Lock()\n\n    def pull_variable(self, request, _):\n        \"\"\"\n        Response with all non-embedding parameters if initialized.\n        \"\"\"\n        res = elasticdl_pb2.PullVariableResponse()\n        if not self._parameters.init_status:\n            res.model_init_status = False\n            return res\n\n        # Only sync-SGD needs lock\n        # TODO: use a read-write lock to support multiple concurrent reads\n        if not self._use_async:\n            self._lock.acquire()\n        res.model.version = self._parameters.version\n        for name, var in self._parameters.non_embedding_params.items():\n            tensor = res.model.param.add()\n            tensor.name = name\n            tensor.dim.extend(var.shape.as_list())\n            var_values = var.numpy()\n            tensor.content = var_values.tobytes()\n            tensor.dtype = dtype_numpy_to_tensor(var_values.dtype)\n        if not self._use_async:\n            self._lock.release()\n        res.model_init_status = True\n        return res\n\n    def pull_embedding_vector(self, request, _):\n        # TODO: implement this RPC service\n        return elasticdl_pb2.Tensor()\n\n    def push_model(self, request, _):\n        with self._lock:\n            self._parameters.init_from_model_pb(request)\n        return empty_pb2.Empty()\n\n    def push_gradient(self, request, _):\n        # TODO: implement this RPC service\n        return elasticdl_pb2.PushGradientResponse()\n", "path": "elasticdl/python/ps/servicer.py"}], "after_files": [{"content": "import threading\n\nfrom google.protobuf import empty_pb2\n\nfrom elasticdl.proto import elasticdl_pb2, elasticdl_pb2_grpc\nfrom elasticdl.python.common.dtypes import dtype_numpy_to_tensor\nfrom elasticdl.python.common.tensor import Tensor, serialize_tensor\n\n\nclass PserverServicer(elasticdl_pb2_grpc.PserverServicer):\n    \"\"\"PS service implementation\"\"\"\n\n    def __init__(\n        self,\n        parameters,\n        grads_to_wait,\n        optimizer,\n        lr_staleness_modulation=False,\n        use_async=False,\n    ):\n        self._parameters = parameters\n        self._grads_to_wait = grads_to_wait\n        self._optimizer = optimizer\n        self._lr_staleness_modulation = lr_staleness_modulation\n        self._use_async = use_async\n        self._version = 0\n        self._lock = threading.Lock()\n\n    def pull_variable(self, request, _):\n        \"\"\"\n        Response with all non-embedding parameters if initialized.\n        \"\"\"\n        res = elasticdl_pb2.PullVariableResponse()\n        if not self._parameters.init_status:\n            res.model_init_status = False\n            return res\n\n        # Only sync-SGD needs lock\n        # TODO: use a read-write lock to support multiple concurrent reads\n        if not self._use_async:\n            self._lock.acquire()\n        res.model.version = self._parameters.version\n        for name, var in self._parameters.non_embedding_params.items():\n            tensor = res.model.param.add()\n            tensor.name = name\n            tensor.dim.extend(var.shape.as_list())\n            var_values = var.numpy()\n            tensor.content = var_values.tobytes()\n            tensor.dtype = dtype_numpy_to_tensor(var_values.dtype)\n        if not self._use_async:\n            self._lock.release()\n        res.model_init_status = True\n        return res\n\n    def pull_embedding_vector(self, request, _):\n        ret = elasticdl_pb2.Tensor()\n        if not request.ids:\n            return ret\n        embedding_vectors = self._parameters.get_embedding_param(\n            request.name, request.ids\n        )\n        tensor = Tensor(values=embedding_vectors)\n        serialize_tensor(tensor, ret)\n        return ret\n\n    def push_model(self, request, _):\n        with self._lock:\n            self._parameters.init_from_model_pb(request)\n        return empty_pb2.Empty()\n\n    def push_gradient(self, request, _):\n        # TODO: implement this RPC service\n        return elasticdl_pb2.PushGradientResponse()\n", "path": "elasticdl/python/ps/servicer.py"}]}