ExternalTensorΒΆ
- class onnx_ir.ExternalTensor(location: PathLike | str, offset: int | None, length: int | None, dtype: DataType, *, shape: Shape, name: str, doc_string: str | None = None, metadata_props: dict[str, str] | None = None, base_dir: PathLike | str = '')ΒΆ
An immutable concrete tensor with its data store on disk.
This class uses memory mapping to avoid loading the tensor into memory, when the data type is supported by numpy. Otherwise, the tensor is loaded into memory lazily when accessed.
Calling
shape
does not incur IO. Checking shape before loading the tensor is recommended if IO overhead and memory usage is a concern.To obtain an array, call
numpy()
. To obtain the bytes, calltobytes()
.The
location
must be a relative path conforming to the ONNX specification. Given the correctbase_dir
, thepath
is computed to be the full path to the data file. Users should expect that thepath
always leads to the correct file. At initialization, paths are not checked. It is the userβs responsibility to ensure the paths are valid and accessible.- locationΒΆ
The location of the data file. It is the path relative to the base directory.
- base_dirΒΆ
The base directory for the external data. It is used to resolve relative paths. At serialization, only the
location
is serialized into the βlocationβ field of theTensorProto
.
- offsetΒΆ
The offset in bytes from the start of the file.
- lengthΒΆ
The length of the data in bytes.
- dtypeΒΆ
The data type of the tensor.
- shapeΒΆ
The shape of the tensor.
- nameΒΆ
The name of the tensor. It must be specified.
- doc_stringΒΆ
The documentation string.
- metadata_propsΒΆ
The metadata properties.
- rawΒΆ
- display(*, page: bool = False) None ΒΆ
Pretty print the object.
- Parameters:
page β Whether to page the output.
- invalidate() None [source]ΒΆ
Invalidate the tensor.
The external tensor is invalidated when the data is known to be corrupted or deleted.
- property meta: MetadataStoreΒΆ
The metadata store for intermediate analysis.
Write to the
metadata_props
if you would like the metadata to be serialized to the ONNX proto.
- numpy() ndarray [source]ΒΆ
Return the tensor as a numpy array.
The data will be memory mapped into memory and will not taken up physical memory space.