prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  [PS-1] RPC service `pull_variable` implementation
  
  
  </issue>
  <code>
  [start of elasticdl/python/ps/servicer.py]
  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 of elasticdl/python/ps/servicer.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
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
  @@ -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
  
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@@ -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"}]}