nvflare.app_opt.xgboost.histogram_based_v2.adaptor module

class XGBAdaptor[source]

Bases: ABC, FLComponent

XGBAdaptors are used to integrate FLARE with XGBoost Target (Server or Client) in run time.

For example, an XGB server could be run as a separate gRPC server process, or be run as part of the FLARE’s FL server job process. Similarly, an XGB client could be run as a separate gRPC client process, or be run as part of the FLARE’s FL client process.

Each type of XGB Target requires an appropriate adaptor to integrate it with FLARE’s XGB Controller or Executor.

The XGBAdaptor class defines commonly required methods for all adaptor implementations.

abstract configure(config: dict, fl_ctx: FLContext)[source]

Configures the target. If any error occurs, this method should raise an exception.

Parameters:
  • config – config data

  • fl_ctx – the FL context

Returns: None

initialize(fl_ctx: FLContext)[source]

Initializes the adaptor.

Parameters:

fl_ctx – the FL context

Returns: None

monitor_target(fl_ctx: FLContext, target_stopped_cb)[source]

Starts a monitor thread to check and respond to the health of the target.

The monitor thread periodically checks for the abort signal. If set, it triggers the stop() method to halt the target.

Additionally, the monitor checks at intervals whether the target has already stopped (by invoking the _is_stopped() method). If the target is detected as stopped, the monitor calls the specified target_stopped_cb callback.

Parameters:
  • fl_ctx (FLContext) – The Federated Learning context.

  • target_stopped_cb (callable) – The callback function to be executed when the target is stopped.

Returns:

None

Raises:

RuntimeError – If target_stopped_cb is not a callable function.

Note

This method starts the monitor in a separate daemon thread to run concurrently.

set_abort_signal(abort_signal: Signal)[source]

Sets the abort_signal.

The abort_signal is used by FLARE’s XGB Controller/Executor. to tell the adaptor that the job has been aborted.

Parameters:

abort_signal – the abort signal assigned by the caller.

Returns: None

set_runner(runner: XGBRunner)[source]

Sets the XGBRunner that will be used to run XGB processing logic. Note that the adaptor is only responsible for starting the runner.

Parameters:

runner – the runner to be set

Returns: None

abstract start(fl_ctx: FLContext)[source]

Starts the target. If any error occurs when starting the target, this method should raise an exception.

Parameters:

fl_ctx – the FL context.

Returns: None

abstract stop(fl_ctx: FLContext)[source]

Stops the target. If any error occurs when stopping the target, this method should raise an exception.

Parameters:

fl_ctx – the FL context.

Returns: None

class XGBClientAdaptor(per_msg_timeout: float, tx_timeout: float)[source]

Bases: XGBAdaptor, ABC

XGBClientAdaptor specifies commonly required methods for client adaptor implementations.

Constructor of XGBClientAdaptor

configure(config: dict, fl_ctx: FLContext)[source]

Called by XGB Executor to configure the target.

The rank, world size, and number of rounds are required config parameters.

Parameters:
  • config – config data

  • fl_ctx – FL context

Returns:

None

class XGBServerAdaptor[source]

Bases: XGBAdaptor, ABC

XGBServerAdaptor specifies commonly required methods for server adaptor implementations.

abstract all_gather(rank: int, seq: int, send_buf: bytes, fl_ctx: FLContext) bytes[source]

Called by the XGB Controller to perform Allgather operation, per XGBoost spec.

Parameters:
  • rank – rank of the calling client

  • seq – sequence number of the request

  • send_buf – operation input data

  • fl_ctx – FL context

Returns:

operation result

abstract all_reduce(rank: int, seq: int, data_type: int, reduce_op: int, send_buf: bytes, fl_ctx: FLContext) bytes[source]

Called by the XGB Controller to perform Allreduce operation, per XGBoost spec.

Parameters:
  • rank – rank of the calling client

  • seq – sequence number of the request

  • data_type – data type of the input

  • reduce_op – reduce operation to be performed

  • send_buf – input data

  • fl_ctx – FL context

Returns:

operation result

abstract broadcast(rank: int, seq: int, root: int, send_buf: bytes, fl_ctx: FLContext) bytes[source]

Called by the XGB Controller to perform Broadcast operation, per XGBoost spec.

Parameters:
  • rank – rank of the calling client

  • seq – sequence number of the request

  • root – root rank of the broadcast

  • send_buf – input data

  • fl_ctx – FL context

Returns:

operation result

configure(config: dict, fl_ctx: FLContext)[source]

Configures the target.

Parameters:
  • config (dict) – configuration to be used to configure the target.

  • fl_ctx – FL context

Returns:

None

Raises:

RuntimeError – if world_size is not configured.