We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[PS-1] RPC service `pull_variable` 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 
7 
8 class PserverServicer(elasticdl_pb2_grpc.PserverServicer):
9     """PS service implementation"""
10 
11     def __init__(
12         self,
13         parameters,
14         grads_to_wait,
15         optimizer,
16         lr_staleness_modulation=False,
17         use_async=False,
18     ):
19         self._parameters = parameters
20         self._grads_to_wait = grads_to_wait
21         self._optimizer = optimizer
22         self._lr_staleness_modulation = lr_staleness_modulation
23         self._use_async = use_async
24         self._version = 0
25         self._lock = threading.Lock()
26 
27     def pull_variable(self, request, _):
28         # TODO: implement this RPC service
29         return elasticdl_pb2.PullVariableResponse()
30 
31     def pull_embedding_vector(self, request, _):
32         # TODO: implement this RPC service
33         return elasticdl_pb2.Tensor()
34 
35     def push_model(self, request, _):
36         with self._lock:
37             self._parameters.init_from_model_pb(request)
38         return empty_pb2.Empty()
39 
40     def push_gradient(self, request, _):
41         # TODO: implement this RPC service
42         return elasticdl_pb2.PushGradientResponse()
43
```
--- 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/elasticdl/python/ps/servicer.py b/elasticdl/python/ps/servicer.py
--- a/elasticdl/python/ps/servicer.py
+++ b/elasticdl/python/ps/servicer.py
@@ -3,6 +3,7 @@
 from google.protobuf import empty_pb2
 
 from elasticdl.proto import elasticdl_pb2, elasticdl_pb2_grpc
+from elasticdl.python.common.dtypes import dtype_numpy_to_tensor
 
 
 class PserverServicer(elasticdl_pb2_grpc.PserverServicer):
@@ -25,8 +26,30 @@
         self._lock = threading.Lock()
 
     def pull_variable(self, request, _):
-        # TODO: implement this RPC service
-        return elasticdl_pb2.PullVariableResponse()
+        """
+        Response with all non-embedding parameters if initialized.
+        """
+        res = elasticdl_pb2.PullVariableResponse()
+        if not self._parameters.init_status:
+            res.model_init_status = False
+            return res
+
+        # Only sync-SGD needs lock
+        # TODO: use a read-write lock to support multiple concurrent reads
+        if not self._use_async:
+            self._lock.acquire()
+        res.model.version = self._parameters.version
+        for name, var in self._parameters.non_embedding_params.items():
+            tensor = res.model.param.add()
+            tensor.name = name
+            tensor.dim.extend(var.shape.as_list())
+            var_values = var.numpy()
+            tensor.content = var_values.tobytes()
+            tensor.dtype = dtype_numpy_to_tensor(var_values.dtype)
+        if not self._use_async:
+            self._lock.release()
+        res.model_init_status = True
+        return res
 
     def pull_embedding_vector(self, request, _):
         # TODO: implement this RPC service

{"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@@ -3,6 +3,7 @@\n from google.protobuf import empty_pb2\n \n from elasticdl.proto import elasticdl_pb2, elasticdl_pb2_grpc\n+from elasticdl.python.common.dtypes import dtype_numpy_to_tensor\n \n \n class PserverServicer(elasticdl_pb2_grpc.PserverServicer):\n@@ -25,8 +26,30 @@\n         self._lock = threading.Lock()\n \n     def pull_variable(self, request, _):\n-        # TODO: implement this RPC service\n-        return elasticdl_pb2.PullVariableResponse()\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", "issue": "[PS-1] RPC service `pull_variable` 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\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        # TODO: implement this RPC service\n        return elasticdl_pb2.PullVariableResponse()\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\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"}]}