When NVMe reads a safetensors checkpoint straight into GPU memory, each tensor lands at the same position within a 4 KiB page that it has in the file. That costs nothing for an engine that copies weights into its own parameters, and can make a fused kernel twice as slow for a loader that computes on the loaded weights in place.
This page is about the DMA-BUF copier in the fastsafetensors 2026-10-28-iouring-dma-buf branch: it registers GPU memory with io_uring as a DMA-BUF, so the NVMe controller writes the weights into it with no host copy (background). The copier's default is to move nothing. Code that uses the loaded tensors in place should ask for 4096-byte alignment or, better, load files whose tensor data already starts on a 4096-byte boundary.
Short version: vLLM's --load-format fastsafetensors and other engines that copy weights into their own parameters should leave the default alone. A mixture-of-experts (MoE) loader that runs its fused kernel on the loaded buffer should pack its files with the data section at a multiple of 4096 bytes and call set_align(4096), so that an unpacked file is moved instead of silently running slower.
A safetensors file is an 8-byte length, a JSON header and then the tensor data. The data section starts at byte 8 + header length, which is often not a round number: in the files measured here it starts at byte 280. The safetensors library pads the header to a multiple of 8 bytes, so the data is at least 8-byte aligned.
O_DIRECT reads, and NVMe DMA into GPU memory, need each read's file offset and destination address to agree modulo 4 KiB. The copier therefore reads the page-aligned range that covers the tensors and places file byte x at a device address congruent to x modulo 4096. Every tensor then sits at its file position within a page: a data section that starts at byte 280 of the file starts at byte 280 of a GPU page. That is the same placement an mmap of the file gives on the host.
The other fastsafetensors copiers place data differently. The nogds copier reads into host memory and copies the data section to the start of its own GPU allocation. The gds copier moves misaligned data to the device pointer alignment, 16 bytes with PyTorch. Neither is page-aligned unless the file is.
All measurements are on one AMD Radeon Pro W7900 (48 GB, gfx1100, ROCm 6.4, PyTorch 2.9) reading from one PCIe NVMe drive, on a kernel with io_uring DMA-BUF registration. Each load is compared byte for byte with a reference reader.
The test loads one 384 MiB expert layer of the EMO mixture-of-experts model and runs a fused MoE Triton kernel at 1,024 tokens directly on the loaded weights, then on a fresh copy of the same weights. Two files hold the same layer: one written by the safetensors library (data at byte 280), one packed with its header padded so the data starts at byte 4096.
| File | Copier setting | Bytes moved | Kernel, loaded | Kernel, fresh copy |
|---|---|---|---|---|
| Data at byte 280 | 1 (the default) | 0 | 4.79 ms | 2.35 ms |
| Data at byte 280 | 16 | 384 MiB | 3.16 ms | 2.35 ms |
| Data at byte 280 | 4096 | 384 MiB | 2.25–2.35 ms | 2.33–2.34 ms |
| Data at byte 4096 (packed) | any | 0 | 2.34–2.35 ms | 2.34 ms |
Medians of the kernel benchmark, five loads per setting, November 23 run; the November 6 run gave 4.81, 3.11, 2.26 and 2.25–2.26 ms for the same rows. Every loaded tensor and every kernel output was bitwise equal to the reference. The 4096 range covers both the explicit setting and the EMO pool loader, which asks for 4096 itself.
The kernel runs at fresh-copy speed only when the data is on a page. A 16-byte move removes about two thirds of the slowdown. On a separate copy probe, 16-byte-aligned data at offsets 64 to 256 within a page ran 8% to 32% slower than page-aligned data. The move itself is a device-to-device copy of about 6 ms per GB, and on a 384 MiB layer it was lost in load-time noise (72 to 84 ms per load across settings).
The second test loads the whole 25.3 GiB BF16 EMO checkpoint (11 shards, four of them with data at 8 modulo 16) the way vLLM's fastsafetensors loader does: ParallelLoader, then a copy of every tensor into preallocated parameters, from a cold page cache. Each cell is the median of three loads, in two separate runs.
| Copier setting | nogds | dmabuf | dmabuf − nogds |
|---|---|---|---|
| 1, the default (November 23) | 3.994 / 4.023 s | 3.926 / 3.964 s | −67 / −60 ms |
| 16 (November 23) | 3.980 / 4.011 s | 4.017 / 4.004 s | +37 / −7 ms |
| 1 (November 6) | 4.013 / 4.076 s | 3.942 / 3.966 s | −71 / −110 ms |
| 16 (November 6) | 3.990 / 4.044 s | 3.995 / 4.049 s | +5 / +5 ms |
| 4096 (November 6) | 4.004 / 4.012 s | 4.171 / 4.134 s | +167 / +122 ms |
Zero mismatched tensors in every cell. The copy into parameters lands in fresh PyTorch allocations, so the source alignment does not reach the engine's kernels; the move only adds work.
Without a move the DMA-BUF copier is 60 to 110 ms faster than nogds on this checkpoint. A 16-byte move cancels that lead and a 4096-byte move turns it into a loss. Earlier "DMA-BUF beats nogds" results were measured without any move, so they hold for the default.
The setting follows from what the caller does with the tensors, not from whether the model is a mixture of experts.
| Caller | Setting | Why |
|---|---|---|
vLLM --load-format fastsafetensors with FASTSAFETENSORS_USE_DMABUF=1 | Default (no move) | Its weight loaders copy each tensor into vLLM's own parameters. vLLM's fused MoE kernels then run on those aligned copies. |
Other engines that load through their own load_weights | Default (no move) | Same reason. SGLang's fastsafetensors path is expected to copy too, but that is not verified here; check each engine's loader before relying on it. |
| A loader that computes on the loaded buffer: MoE expert offload, pool or slot swaps, delta loads | Files packed at 4096, and set_align(4096) | Only a page-aligned data section matches a fresh allocation for the fused kernel. Packing makes it free; the explicit request catches a file that is not packed. |
Code written against the gds copier's 16-byte contract | FASTSAFETENSORS_DMABUF_ALIGN=16 | Same placement as gds. |
An engine that already loads safetensors by mmap receives tensors at their file offsets, 8-byte aligned, so it already accepts what the default gives.
There are three controls. FASTSAFETENSORS_DMABUF_ALIGN sets the alignment, a power of two from 1 to 4096, for every DMA-BUF copier in the process. A caller that drives the copier itself can call set_align() on it before wait_io. And wait_io(noalign=True) skips the move whatever the setting.
loader = SafeTensorsFileLoader(SingleGroup(), "cuda:0", use_dmabuf=True)
loader.add_filenames({0: [path]})
meta, _ = next(iter(loader.meta.values()))
copier = loader.copier_constructor(meta, loader.device, loader.framework)
if hasattr(copier, "set_align"): # the DMA-BUF copier
copier.set_align(4096) # in-place use: page-align the data section
gbuf = copier.submit_io(True, 16 << 30)
tensors = copier.wait_io(gbuf, owner=owner)
# copier.align_move_bytes: 0 for a file packed at 4096
When an alignment above 1 is set and the data section is not on it, the copier moves each piece's bytes inside its own allocation after the reads complete. Every allocation has one page more than the span it reads, so the move always fits. Overlapping device copies are undefined, so the bytes go through a temporary buffer of at most 64 MiB.
The safetensors format allows trailing spaces in the JSON header. Padding the header until 8 + header length is a multiple of 4096 puts the data section on a page, with no change to any tensor. This is what the EMO pipeline's pack_pool_layer.py --align 4096 does for its pool files:
import struct
with open(src, "rb") as f:
n = struct.unpack("<Q", f.read(8))[0]
header, body = f.read(n), f.read()
pad = (-(8 + n)) % 4096
with open(dst, "wb") as f:
f.write(struct.pack("<Q", n + pad) + header + b" " * pad + body)
For in-place use, check that each tensor's address agrees with its offset inside the data section modulo 4096. That holds when the data section starts on a page, either because the file was packed or because the copier moved it:
for name, t in tensors.items():
off = meta.tensors[name].data_offsets[0]
assert t.get_raw().data_ptr() % 4096 == off % 4096, name
The fastsafetensors tests check the same property on a CPU device for the default, 1, 16, 4096 and set_align(4096), with the file loaded in one piece and in several pieces under a small registration cap, and compare every value with the nogds reader.
| fastsafetensors commit | Copier behaviour | Used by |
|---|---|---|
a174cd2 | Never moves; tensors at their file offsets modulo 4 KiB | The published EMO results and the earlier weight-loading results |
4ebdd20 | Moves to 16 bytes unless noalign; FASTSAFETENSORS_DMABUF_ALIGN sets 1 to 4096 | Superseded |
9f77b8c | Moves nothing by default; set_align() or the variable asks for 2 to 4096 | Current branch tip; pinned by knlp's defconfig-emo-ifp |
With the default of 1, the current commit places tensors exactly as a174cd2 did, so results measured with that commit carry over to callers that do not ask for a move. In knlp's EMO pipeline the pool loader asks for 4096, but the packed files already start their data at 4096, so nothing moves. A pool-switch test gave the same load times within about 1% with the old and the new reader: 898 to 916 ms against 899 to 921 ms per 6.4 GB pool load, with every output correct.
The kernel slowdown was measured for one fused MoE Triton kernel on one GPU architecture (gfx1100). Other GPUs, other kernels and other tensor shapes may be more or less sensitive, and some may need no alignment beyond 16 bytes. The copy-out result covers one loader pattern on one checkpoint, and its gain over nogds is tens of milliseconds on a load of about 4 s, so it is a small effect. These runs used a kernel without the asynchronous DMA-BUF release patches (branch 2026-11-06-dmabuf-io-async-release), which remove about 14 ms per registration from every load. The comparison between alignment settings does not depend on them.
2026-10-28-iouring-dma-buf: fastsafetensors/copier/dmabuf.py (module docstring, "Alignment"), docs/overview.md ("Where the loaded tensors start") and tests/unit/test_dmabuf.py.scripts/emo_ifp/layer_offload.py, its loader.