|
Mila
Deep Neural Network Library
|
safetensors container support: dtype naming and a two-phase writer. More...
#include <cstdint>#include <cstdio>#include <filesystem>#include <format>#include <map>#include <memory>#include <stdexcept>#include <string>#include <vector>import Dnn.TensorDataType;import Dnn.TensorTypes;import nlohmann.json;Classes | |
| class | Mila::Dnn::Serialization::SafeTensorsWriter |
| Writes a safetensors file: u64 header length, JSON header, packed data. More... | |
Namespaces | |
| namespace | Mila |
| Mila main API namespace. | |
Enumerations | |
| enum class | Mila::Dnn::Serialization::TensorSavePass { Declare , Write } |
| Which pass of a two-phase save a component is being driven through. More... | |
Functions | |
| TensorDataType | Mila::Dnn::Serialization::fromSafeTensorsDataTypeName (const std::string &name) |
| Mila type for a safetensors dtype spelling. | |
| size_t | Mila::Dnn::Serialization::storageBytesPerElement (TensorDataType type) |
| Byte width of one stored element of the given type. | |
| std::string | Mila::Dnn::Serialization::toSafeTensorsDataTypeName (TensorDataType type) |
| safetensors dtype spelling for a Mila type. | |
Variables | |
| constexpr const char * | Mila::Dnn::Serialization::kMilaConfigMetadataKey = "mila_config" |
| Key under which the Mila architecture config is stored in metadata. | |
| constexpr const char * | Mila::Dnn::Serialization::kMilaQuantizationMetadataKey = "mila_quantization" |
| Key marking an artifact whose weights are already quantized. | |
safetensors container support: dtype naming and a two-phase writer.
The distribution artifact is written in the safetensors layout so that any reader can verify a Mila file without running Mila. Reading is handled by PretrainedModelReader, which sniffs the container and shares one staging path across both formats.
|
exportstrong |
Which pass of a two-phase save a component is being driven through.
Exists so a component visits its tensors from ONE ordered body rather than two. The writer requires bodies in declaration order, and two separate walks would be free to drift out of agreement with no diagnostic until the file is read back.
| Enumerator | |
|---|---|
| Declare | Reserve each tensor's byte range in the header. |
| Write | Stream each tensor's bytes, in declaration order. |
|
inlineexport |
|
inlineexport |
Byte width of one stored element of the given type.
Packed 4-bit types report one byte because two elements share it; a packed tensor therefore declares its physical (halved) column count, and the byte count follows from the declared shape with no special case.
|
inlineexport |
|
inlineconstexprexport |
|
inlineconstexprexport |
Key marking an artifact whose weights are already quantized.
Present only on pre-quantized artifacts. Its absence, or the value "none", means the weights are in the declared compute precision and the load path quantizes as it always has.
The value names the policy, not just the fact of quantization, because the storage dtype cannot distinguish one from another: FP4 at group 128 and at group 64 are both packed into U8. Only this string lets a load refuse the wrong one.