Split nLayers into contiguous [lo, hi) ranges of at most segSize layers each (the last range may be shorter). segSize is the memory knob: fewer layers per segment -> lower peak, ~fixed total recompute time.
nLayers
[lo, hi)
segSize
Split
nLayersinto contiguous[lo, hi)ranges of at mostsegSizelayers each (the last range may be shorter).segSizeis the memory knob: fewer layers per segment -> lower peak, ~fixed total recompute time.