start_client¶
- start_client(*, server_address: str, client_fn: Callable[[Context], Client] | None = None, client: Client | None = None, grpc_max_message_length: int = 536870912, root_certificates: bytes | str | None = None, insecure: bool | None = None, transport: str | None = None, authentication_keys: tuple[EllipticCurvePrivateKey, EllipticCurvePublicKey] | None = None, max_retries: int | None = None, max_wait_time: float | None = None) None [source]¶
启动一个 Flower 客户节点,连接到 Flower 服务器。
Warning
This function is deprecated since 1.13.0. Use
flower-supernode
command instead to start a SuperNode.- 参数:
server_address (str) -- 服务器的 IPv4 或 IPv6 地址:如果 Flower 服务器在同一台机器上运行,端口为 8080,则`server_address`应为`"[::]:8080"`。
client_fn (Optional[ClientFnExt]) -- 用于实例化客户端的可调用程序。(默认值:无)
client (Optional[flwr.client.Client]) -- 抽象基类 flwr.client.Client 的实现(默认值:无)
grpc_max_message_length (int (default: 536_870_912, this equals 512MB)) -- 可与 Flower 服务器交换的 gRPC 信息的最大长度:默认值对大多数模型都足够了。训练超大模型的用户可能需要增加该值。请注意,Flower 服务器需要以相同的值启动(请参阅 flwr.server.start_server),否则它将不知道增加的限制并阻止更大的消息。
root_certificates (Optional[Union[bytes, str]] (default: None)) -- 字节字符串或路径字符串形式的 PEM 编码根证书。如果提供,将使用这些证书与启用 SSL 的 Flower 服务器建立安全连接。
insecure (bool (default: True)) -- 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(实验性)
authentication_keys (Optional[Tuple[PrivateKey, PublicKey]] (default: None)) -- Tuple containing the elliptic curve private key and public key for authentication from the cryptography library. Source: https://cryptography.io/en/latest/hazmat/primitives/asymmetric/ec/ Used to establish an authenticated connection with the server.
max_retries (Optional[int] (default: None)) -- The maximum number of times the client will try to connect to the server before giving up in case of a connection error. If set to None, there is no limit to the number of tries.
max_wait_time (Optional[float] (default: None)) -- The maximum duration before the client stops trying to connect to the server in case of connection error. If set to None, there is no limit to the total time.
实例
使用不安全的服务器连接启动 gRPC 客户端:
>>> start_client( >>> server_address=localhost:8080, >>> client_fn=client_fn, >>> )
Starting an SSL-enabled gRPC client using system certificates:
>>> def client_fn(context: Context): >>> return FlowerClient().to_client() >>> >>> start_client( >>> server_address=localhost:8080, >>> client_fn=client_fn, >>> insecure=False, >>> )
Starting an SSL-enabled gRPC client using provided certificates:
>>> from pathlib import Path >>> >>> start_client( >>> server_address=localhost:8080, >>> client_fn=client_fn, >>> root_certificates=Path("/crts/root.pem").read_bytes(), >>> )