Mila 0.13.48
Deep Neural Network Library
Loading...
Searching...
No Matches
Mila::Dnn::Serialization Namespace Reference

Classes

class  ArchiveSerializer
 Interface for hierarchical archive serializers. More...
struct  ITensorBlob
 Type-erased interface for a serialized tensor blob. More...
class  ModelArchive
 ModelArchive provides high-level helpers for component serialization. More...
 Metadata for pretrained model. More...
class  PretrainedModelReader
 Reader for Mila pretrained binary format. More...
 Type-safe metadata container for component serialization. More...
class  Serializer
 Minimal base interface for model serialization backends. More...
struct  TensorBlob
 Concrete tensor blob owning a TensorBuffer-backed raw byte buffer. More...
 Metadata for a tensor blob in pretrained model format. More...
 Metadata describing a tensor in serialized form. More...
class  ZipSerializer
 ZIP archive serializer built on miniz. More...

Typedefs

using json = nlohmann::json
using Mila::Dnn::Serialization::MetadataValue
 Type-safe metadata value supporting common serialization types.

Enumerations

enum class  DType : uint32_t { Float32 = 0 , Float16 = 1 , BFloat16 = 2 , Int32 = 3 }
enum class  Mila::Dnn::Serialization::OpenMode { Read , Write }
 Mode indicating whether the archive is used for reading or writing. More...
enum class  Mila::Dnn::Serialization::SerializationMode { Checkpoint , WeightsOnly , Architecture }
 Modes for serialization and deserialization. More...

Functions

constexpr std::string_view Mila::Dnn::Serialization::archiveModeToString (OpenMode mode)
 Convert ArchiveMode to string.
TensorDataType dtypeToTensorDataType (uint32_t dtype)
template<typename MR = Compute::CpuMemoryResource>
requires isValidTensor<dtype_t::UINT8, MR>
TensorBlob< MR > Mila::Dnn::Serialization::readTensorBlob (const ModelArchive &archive, const std::string &prefix, int device_id=0)
 Read tensor metadata and raw bytes from prefix into a typed blob.
std::string Mila::Dnn::Serialization::serializationModeToString (SerializationMode mode)
 Convert a SerializationMode value to a human-readable string.
void Mila::Dnn::Serialization::writeTensorBlob (ModelArchive &archive, const std::string &prefix, const TensorMetadata &meta, const void *data, size_t size)
 Write tensor metadata and raw bytes under the given prefix into archive.

Typedef Documentation

◆ json

◆ MetadataValue

Initial value:
std::variant<
std::string,
int64_t,
double,
bool,
std::vector<int64_t>,
std::vector<double>,
std::vector<std::string>
>

Type-safe metadata value supporting common serialization types.

Encapsulates primitive types, strings, and structured data without exposing the underlying serialization format to user code.

Enumeration Type Documentation

◆ DType

enum class Mila::Dnn::Serialization::DType : uint32_t
strong
Enumerator
Float32 
Float16 
BFloat16 
Int32 

◆ OpenMode

enum class Mila::Dnn::Serialization::OpenMode
exportstrong

Mode indicating whether the archive is used for reading or writing.

Preconditions:

  • The underlying ModelSerializer should be opened for the matching operation (openForRead for Read, openForWrite for Write) before calling archive helpers.

Semantics:

  • Read : permits read operations (readJson, readBlob, file queries).
  • Write : permits write operations (writeJson, writeBlob, add data).

Example:

auto serializer = std::make_unique<ZipSerializer>( ... );
serializer->openForWrite(...);
ModelArchive archive( std::move(serializer), ArchiveMode::Write );
archive.writeJson("meta.json", j);
ModelArchive provides high-level helpers for component serialization.
Definition ModelArchive.ixx:47
Enumerator
Read 
Write 
Examples
/__w/Mila/Mila/Mila/Src/Dnn/Serialization/ModelArchive.ixx.

◆ SerializationMode

Modes for serialization and deserialization.

Selects which parts of a network are saved or restored:

  • Checkpoint: full state (architecture + weights + optimizer state)
  • WeightsOnly: only parameter tensors
  • Architecture: only network topology and metadata
Enumerator
Checkpoint 
WeightsOnly 
Architecture 
Examples
/__w/Mila/Mila/Mila/Src/Dnn/Components/Activations/Gelu/Gelu.ixx, and /__w/Mila/Mila/Mila/Src/Dnn/Components/Normalization/Softmax.ixx.

Function Documentation

◆ archiveModeToString()

std::string_view Mila::Dnn::Serialization::archiveModeToString ( OpenMode mode)
constexprexport

Convert ArchiveMode to string.

Examples
/__w/Mila/Mila/Mila/Src/Dnn/Serialization/ModelArchive.ixx.
Here is the caller graph for this function:

◆ dtypeToTensorDataType()

TensorDataType Mila::Dnn::Serialization::dtypeToTensorDataType ( uint32_t dtype)
inline
Here is the caller graph for this function:

◆ readTensorBlob()

template<typename MR = Compute::CpuMemoryResource>
requires isValidTensor<dtype_t::UINT8, MR>
TensorBlob< MR > Mila::Dnn::Serialization::readTensorBlob ( const ModelArchive & archive,
const std::string & prefix,
int device_id = 0 )
export

Read tensor metadata and raw bytes from prefix into a typed blob.

Allocates a TensorBuffer<UINT8, MR> sized to total_bytes and reads directly into it via readBlobInto — no intermediate vector copy. When MR is CudaPinnedMemoryResource the returned blob carries a pinned host pointer ready for direct DMA in copyFromBlob.

Template Parameters
MRMemory resource for the blob data buffer. Defaults to CpuMemoryResource.
Parameters
archiveModelArchive to read from
prefixPath prefix for tensor files (e.g., "tensors/weight")
device_idDevice index passed to the memory resource constructor.
Returns
TensorBlob<MR> owning the metadata and raw byte buffer.
Exceptions
std::runtime_errorif read operations fail or size mismatch detected
Here is the call graph for this function:

◆ serializationModeToString()

std::string Mila::Dnn::Serialization::serializationModeToString ( SerializationMode mode)
export

Convert a SerializationMode value to a human-readable string.

Parameters
modeThe serialization mode to convert.
Returns
A short string identifying the mode ("Checkpoint", "WeightsOnly", or "Architecture").
Here is the caller graph for this function:

◆ writeTensorBlob()

void Mila::Dnn::Serialization::writeTensorBlob ( ModelArchive & archive,
const std::string & prefix,
const TensorMetadata & meta,
const void * data,
size_t size )
inlineexport

Write tensor metadata and raw bytes under the given prefix into archive.

Writes: prefix + "/meta.json" — TensorMetadata as SerializationMetadata prefix + "/data.bin" — raw tensor bytes

Parameters
archiveModelArchive to write to
prefixPath prefix for tensor files (e.g., "tensors/weight")
metaTensor metadata
dataPointer to raw tensor bytes
sizeNumber of bytes to write
Exceptions
std::runtime_errorif write operations fail
Here is the call graph for this function:
Here is the caller graph for this function: