start_numpy_client

start_numpy_client(*, server_address: str, client: NumPyClient, grpc_max_message_length: int = 536870912, root_certificates: bytes | None = None, insecure: bool | None = None, transport: str | None = None) None[source]

启动 Flower NumPyClient,连接到 gRPC 服务器。

Warning

This function is deprecated since 1.7.0. Use flwr.client.start_client instead and first convert your NumPyClient to type flwr.client.Client by executing its to_client() method.

参数:
  • server_address (str) -- 服务器的 IPv4 或 IPv6 地址:如果 Flower 服务器在同一台机器上运行,端口为 8080,则`server_address`应为`"[::]:8080"`

  • client (flwr.client.NumPyClient) -- 抽象基类 flwr.client.NumPyClient 的实现。

  • grpc_max_message_length (int (default: 536_870_912, this equals 512MB)) -- 可与 Flower 服务器交换的 gRPC 信息的最大长度:默认值对大多数模型都足够了。训练超大模型的用户可能需要增加该值。请注意,Flower 服务器需要以相同的值启动(请参阅 flwr.server.start_server),否则它将不知道增加的限制并阻止更大的消息。

  • root_certificates (bytes (default: None)) -- 字节字符串或路径字符串形式的 PEM 编码根证书。如果提供,将使用这些证书与启用 SSL 的 Flower 服务器建立安全连接。

  • insecure (Optional[bool] (default: None)) -- Starts an insecure gRPC connection when True. Enables HTTPS connection when False, using system certificates if root_certificates is None.

  • transport (Optional[str] (default: None)) -- 配置传输层:允许的值包括 - 'grpc-bidi': gRPC,双向流 - 'grpc-rere': gRPC,请求-响应(实验性) - 'rest': HTTP(实验性)

实例

使用不安全的服务器连接启动 gRPC 客户端:

>>> start_numpy_client(
>>>     server_address=localhost:8080,
>>>     client=FlowerClient(),
>>> )

Starting an SSL-enabled gRPC client using system certificates:

>>> start_numpy_client(
>>>     server_address=localhost:8080,
>>>     client=FlowerClient(),
>>>     insecure=False,
>>> )

Starting an SSL-enabled gRPC client using provided certificates:

>>> from pathlib import Path
>>>
>>> start_numpy_client(
>>>     server_address=localhost:8080,
>>>     client=FlowerClient(),
>>>     root_certificates=Path("/crts/root.pem").read_bytes(),
>>> )