小编foi*_*ois的帖子

在TensorFlow中关闭服务器

当我们想要使用分布式TensorFlow时,我们将使用创建一个参数服务器

tf.train.Server.join()
Run Code Online (Sandbox Code Playgroud)

但是,除了终止处理之外,我找不到任何关闭服务器的方法.join()的TensorFlow文档是

Blocks until the server has shut down.
This method currently blocks forever.
Run Code Online (Sandbox Code Playgroud)

这对我来说非常麻烦,因为我想创建许多服务器进行计算,并在一切结束时关闭它们.

有没有可能的解决方案.

谢谢

python machine-learning deep-learning grpc tensorflow

7
推荐指数
2
解决办法
4059
查看次数

在 Amazon EC2 上构建 gRPC 服务器

当我尝试在 Amazon EC2 实例上构建 gRPC 服务器/客户端时遇到问题。

我有一个实例 A(带有私有 ip:例如 1.2.3.4)。服务器代码就像

from concurrent import futures
import time
import math

import grpc

import helloworld_pb2

_ONE_DAY_IN_SECONDS = 60 * 60 * 24

class Greeter(helloworld_pb2.GreeterServicer):

  def SayHello(self, request, context):
    return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)


def serve():
  server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
  helloworld_pb2.add_GreeterServicer_to_server(Greeter(), server)
  server.add_insecure_port('1.2.3.4:50051')

  server.start()
  try:
    while True:
      time.sleep(_ONE_DAY_IN_SECONDS)
  except KeyboardInterrupt:
    server.stop(0)

if __name__ == '__main__':
  serve()
Run Code Online (Sandbox Code Playgroud)

另一方面,实例 B 有私有 ip 2.3.4.5,我想在它上面运行客户端脚本

from __future__ import print_function

import grpc

import helloworld_pb2


def run():
  channel = grpc.insecure_channel('1.2.3.4:50051')
  stub …
Run Code Online (Sandbox Code Playgroud)

communication cluster-computing amazon-ec2 server grpc

5
推荐指数
1
解决办法
1535
查看次数

将非常量整数传递给 C++ 中的模板参数

我想知道如何创建一个从命令行给出大小的矩阵。如果它是非模板矩阵类,则可以轻松完成。但是,如果矩阵类是模板类(如在 Eigen 中),我该如何创建一个从命令行给出大小的矩阵呢?

template<int _row, int _col>
class Matrix{
...
};

int main{
    // assign rows and cols dynamically
    int row;
    int col;
    std::cin >> row >> col;

    // Some procedures

    Matrix<row, col> m;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

编辑:

谢谢@hyde 和@marcinj。我认为 Eigen 的实现背后有一些神奇的机制。通过再次查看 Eigen 的代码,我认为他们int _Cols, int _Rows仅对小矩阵使用模板参数,并定义Dynamic为 -1 之类的一些常量并在运行时处理它。

c++ templates matrix

2
推荐指数
1
解决办法
1010
查看次数