jax_privacy.experimental.compilation_utils.optimal_physical_batch_sizes

jax_privacy.experimental.compilation_utils.optimal_physical_batch_sizes#

jax_privacy.experimental.compilation_utils.optimal_physical_batch_sizes(batch_sizes, num_compilations)[source]#

Find a set of compiled batch sizes that minimizes wasted compute.

Given a list of batch sizes \(B_1, \dots, B_n\) and a compilation budget, \(C\), this function finds compiled batch sizes \(M_1, \dots, M_C\) that minimize the following objective:

\[L(M_1, \dots, M_C) = \sum_{i=1}^n \min_{j : M_j \geq B_i} (M_j - B_i)\]

The term \(M_j - B_i\) in this objective represents the wasted compute for evaluating gradients for a batch of size \(M_j\) when the true batch size is \(B_i\).

The time complexity of this function is \(O(C \cdot b^2)\) where \(b\) is the number of unique batch sizes in the list. It is currently not highly optimized.

Parameters:
  • batch_sizes (list[int]) – A list of non-negative integers \(B_1, \dots, B_n\).

  • num_compilations (int) – A non-negative integer representing the number of unique batch sizes to return (and compile downstream functions for).

Return type:

set[int]

Returns:

A set of integers.