TECHNOLOGY

PyTorch DevLog: allocation order and expandable segments

In this article
THE QUICK TAKE

Expandable segments can remove a segment-boundary obstacle; live blocks, pool routing and backend semantics still constrain reuse.

Edward Yang’s PyTorch DevLog uses deliberately small allocation sequences to explain why equal tensor demand can leave different amounts of reserved GPU memory. The value is a causal example that can guide diagnosis. It is not a production benchmark showing a fixed memory saving for every serving workload.

Follow the allocation sequence

The DevLog illustrates a pool without expandable segments: 8 allocations of 16 MiB reserve 128 MiB. After they are freed, requesting 4 allocations of 32 MiB can raise the pool’s reservation to 256 MiB. The old free pieces live in separate segments and cannot combine to satisfy the larger requests.

Reversing the order allows the larger segments to split for the smaller requests, retaining 128 MiB in that example. The tensor-volume totals are equal, but their allocation histories differ. These figures describe the shown laboratory pool and sequence, not an assertion that all global out-of-memory handling always preserves every cached segment.

Understand what expansion changes

With expandable segments, the example maps 140 MiB of physical memory for 128 MiB of requested allocations. Once all those tensors are freed, adjacent blocks can merge, allowing the later larger requests to reuse the mapped region. Reserving virtual address space and committing physical memory are distinct operations; a large virtual reservation does not itself consume that much physical VRAM.

The extra mapped capacity is reusable space, not evidence that tensor sizes were misreported. Conversely, the example does not promise exact requested-byte physical consumption. Page granularity still matters.

Keep the counterexamples

Expansion does not merge free pieces across an intervening live allocation. The DevLog also describes separate small and large allocation pools: free space in one cannot automatically satisfy requests routed to the other. These boundaries explain why a change can help one allocation pattern without solving every fragmentation problem.

The PyTorch CUDA documentation labels expandable segments experimental and describes its intended benefit for changing allocation sizes. It distinguishes tensor-allocated bytes from allocator-reserved bytes and states that emptying the cache does not free memory occupied by live tensors. Native-allocator statistics and controls also need to be interpreted for the selected backend.

Turn the example into a diagnosis

Preserve the framework version, backend, pool and stream context, then inspect the failing request alongside block states. The snapshot guide explains why reserved-minus-allocated alone cannot distinguish live demand, pending frees and unusable inactive pieces.

For a variable-batch serving workload, compare an equivalent fixed-shape control and preserve allocation order. If expansion improves capacity, report the actual workload’s measured peak and output checks rather than borrowing the DevLog’s illustrative ratio. A change in pool structure is evidence about that experiment, not proof that the model itself shrank.

Keep the allocator setting in the environment record, together with the representative trace. The example is most useful when it narrows a mechanism: segment boundaries can prevent reuse even after tensors are freed, while live allocations and pool separation remain independent constraints.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles