nvflare.app_opt.xgboost.histogram_based_v2.sec.processor_data_converter module

class ProcessorDataConverter[source]

Bases: DataConverter

decode_aggregation_context(buffer: bytes, fl_ctx: FLContext) AggregationContext[source]

Decode the buffer to extract aggregation context info

Parameters:
  • buffer – buffer to be decoded

  • fl_ctx – FLContext info

Returns: if the buffer contains aggregation context, return an AggregationContext object;

otherwise, return None

decode_gh_pairs(buffer: bytes, fl_ctx: FLContext) List[Tuple[int, int]][source]

Decode the buffer to extract (g, h) pairs.

Parameters:
  • buffer – the buffer to be decoded

  • fl_ctx – FLContext info

Returns: if the buffer contains (g, h) pairs, return a tuple of (g_numbers, h_numbers);

otherwise, return None

decode_histograms(buffer: bytes, fl_ctx: FLContext) List[float][source]

Decode the buffer to extract flattened histograms

Parameters:
  • buffer – buffer to be decoded

  • fl_ctx – FLContext info

Returns: if the buffer contains histograms, return the flattened histograms

otherwise, return None

encode_aggregation_result(aggr_results: Dict[int, List[FeatureAggregationResult]], fl_ctx: FLContext) bytes[source]

Encode an individual rank’s aggr result to a buffer based on XGB data structure

Parameters:
  • aggr_results – aggregation result for all features and all groups from all clients group_id => list of feature aggr results

  • fl_ctx – FLContext info

Returns: a buffer of bytes

encode_histograms_result(histograms: List[float], fl_ctx: FLContext) bytes[source]

Encode flattened histograms to be sent back to XGBoost

Parameters:
  • histograms – The flattened histograms for all features

  • fl_ctx – FLContext info

Returns: a buffer of bytes

static float_to_int(value: float) int[source]
static get_bin_size(cuts: [<class 'int'>], feature_id: int) int[source]
static int_to_float(value: int) float[source]
static slot_to_bin(cuts: [<class 'int'>], slot: int) Tuple[int, int][source]
static to_float_array(result: FeatureAggregationResult) List[float][source]