﻿# ONNX Runtime 1.32 borrowed initializers: skipping a host copy extends the caller’s lifetime obligation

Direct initializer borrowing in 1.32 removes a host copy only for eligible buffers; preserve source ownership and immutability for every dependent session.

Author: Retrivium team
Updated: 2026-11-15
Canonical URL: https://retrivium.ai/journal/week46-engine-ort-borrowed-external-initializer-lifetime/
Language: en

ONNX Runtime 1.32.0 extends direct external-initializer borrowing to AddExternalInitializers for eligible CPU buffers. The default remains copying. Opting into borrowing changes the ownership contract: source memory must remain alive and unchanged until all sessions using it are released, rather than being disposable immediately after session construction.

## An opt-in changes when cleanup is legal

The copying route can detach session storage from caller-owned bytes. The borrowing route intentionally avoids that detachment. A proposed test gives the source an explicit owner retained with the session, then verifies inference before releasing both in the documented order. Do not test premature release by relying on memory that happens not to be overwritten. Such a passing run would demonstrate allocator luck rather than a valid lifetime contract.

## Eligibility is more than a configuration flag

The release specifies alignment, size and host-endianness conditions for direct borrowing. An enabled option therefore does not prove a particular tensor avoided copying. A memory test should inspect the effective route and include eligible and ineligible controls. Otherwise a copied small or misaligned tensor can make an application look lifetime-safe while its larger eligible production weights remain borrowed under the same option.

## Shared source buffers can serve several sessions

If several sessions borrow one mapping, the last dependent session determines when that mapping can be released. Track that relationship explicitly rather than tying cleanup to whichever session finishes first. A proposed lifecycle case closes sessions in different orders and verifies remaining users. Treat read-only source data as immutable even if a language wrapper exposes a writable view, because accidental mutation can change another session’s weights without rebuilding its graph.

## A host-copy saving is a scoped result

This feature concerns eligible host initializer storage and does not establish zero-copy GPU execution. Measure host peak memory and startup separately from device placement. This article reports the release borrowing contract and proposed ownership tests without new benchmarks or a blanket recommendation to enable it. The useful result names the borrowed buffers, their owners and the session lifetime over which immutability is guaranteed.

## Sources

- [ONNX Runtime v1.32.0 release](https://github.com/microsoft/onnxruntime/releases/tag/v1.32.0)
- [ONNX Runtime pull request #33877](https://github.com/microsoft/onnxruntime/pull/33877)

## Related reading

- [ONNX external data: release the graph and relative tensor files together](/journal/fg2-onnx-external-data-relative-artifact-release/)
- [ONNX Runtime I/O binding: a device pointer needs an owner and a valid lifetime](/journal/fg2-onnxruntime-io-binding-device-buffer-lifetime/)
