|
Mila 0.13.48
Deep Neural Network Library
|
Reader for Mila pretrained binary format. More...

Public Member Functions | |
| PretrainedModelReader (const std::filesystem::path &filepath) | |
| Open a Mila model file for reading. | |
| ~PretrainedModelReader () | |
| bool | close () |
| const std::string & | getFilename () const noexcept |
| size_t | getMaxTensorSizeBytes () const |
| Get the maximum byte size across all tensors in the index. | |
| const PretrainedMetadata & | getPretrainedMetadata () const |
| Get pretrained model metadata. | |
| std::vector< std::string > | getTensorNames () const |
| Get list of all tensor names in the model. | |
| size_t | getTensorSizeBytes (const std::string &name) const |
| Get the raw byte size of a named tensor. | |
| bool | hasTensor (const std::string &name) const |
| Check if tensor exists. | |
| bool | isOpen () const noexcept |
| template<typename MR = Compute::CpuMemoryResource> requires isValidTensor<dtype_t::UINT8, MR> | |
| TensorBlob< MR > | readTensorBlob (const std::string &name, int device_id=0) |
| Read raw tensor bytes by name into a memory-resource-typed blob. | |
Private Member Functions | |
| const TensorBlobMetadata & | getTensorBlobMetadata (const std::string &name) const |
| void | parseMetadataJSON (const std::string &json) |
| void | readHeader () |
| void | readMetadata () |
| void | readTensorIndex () |
Private Attributes | |
| std::ifstream | file_ |
| std::string | filename_ |
| std::filesystem::path | filepath_ |
| PretrainedMetadata | metadata_ |
| uint32_t | num_tensors_ { 0 } |
| std::unordered_map< std::string, TensorBlobMetadata > | tensor_index_ |
Static Private Attributes | |
| static constexpr uint32_t | MAGIC = 0x4D494C41 |
| static constexpr uint32_t | VERSION = 1 |
Reader for Mila pretrained binary format.
File format:
Provides flat key-value access to tensors by name:
Usage:
|
inlineexplicit |
Open a Mila model file for reading.
| filepath | Path to .bin model file. |
| std::runtime_error | if file cannot be opened or format is invalid. |

|
inline |

|
inline |

|
inlinenoexcept |
|
inline |
Get the maximum byte size across all tensors in the index.
Returns the largest nbytes value in the tensor index. All sizes are known at construction time. No I/O is performed.
|
inline |
Get pretrained model metadata.

|
inlineprivate |

|
inline |
Get list of all tensor names in the model.

|
inline |
Get the raw byte size of a named tensor.
All sizes are known at construction time from the tensor index. No I/O is performed.
| name | Tensor name. |
| std::runtime_error | if name is not found. |

|
inline |
Check if tensor exists.
|
inlinenoexcept |
|
inlineprivate |

|
inlineprivate |

|
inlineprivate |


|
inline |
Read raw tensor bytes by name into a memory-resource-typed blob.
Allocates a TensorBuffer<UINT8, MR> of the exact tensor byte size and reads directly from the file into it. No intermediate buffer is used. When MR is CudaPinnedMemoryResource the returned blob data is page-locked, enabling direct DMA to device in copyFromBlob without a staging copy.
| MR | Memory resource for the blob data buffer. Defaults to CpuMemoryResource. |
| std::runtime_error | if the tensor is not found or the read fails. |


|
inlineprivate |

|
private |
|
private |
|
private |
|
staticconstexprprivate |
|
private |
|
private |
|
private |
|
staticconstexprprivate |