During pipeline-parallel inference, splitting a batch into smaller micro-batches enables concurrent execution of pipeline stages, improving throughput at the cost of additional per-micro-batch synchronization overhead.
Implement a function microbatch_speedup(batch_time, num_microbatches, overhead_per_microbatch) that estimates the speedup achieved by micro-batching using the following model:
Without micro-batching, the total time to process one batch is batch_time seconds.
With M micro-batches, the per-micro-batch compute is batch_time / M, and there is a synchronization overhead of overhead_per_microbatch seconds incurred for each of the M micro-batches. So the total time is:
time_mb = batch_time / M + M * overhead_per_microbatch
Return the speedup ratio defined as batch_time / time_mb (a value > 1 means micro-batching is faster).