Mila
Deep Neural Network Library
Loading...
Searching...
No Matches
Mila::Distribution::ModelPackage Class Referenceexport

Everything a published or installable model is, as a directory. More...

Public Member Functions

const std::filesystem::path & directory () const noexcept
const ModelManifestmanifest () const noexcept
std::filesystem::path pathOf (const ModelFile &file) const
 Where a declared file lives in this package.
PackageValidation validate () const
 Check the package against its own manifest, reading every declared byte.

Static Public Member Functions

static ModelPackage open (const std::filesystem::path &directory)
 Read a package's manifest.

Detailed Description

Everything a published or installable model is, as a directory.

<package>/
mila.json the manifest
<weights>.safetensors the artifact
<tokenizer>.bin
LICENSE the source model's license text
NOTICE attribution the source license requires be carried verbatim
README.md model card, including the statement that changes were made

Member Function Documentation

◆ open()

ModelPackage Mila::Distribution::ModelPackage::open ( const std::filesystem::path & directory)
inlinestatic

Read a package's manifest.

Hashes nothing – that is validate()'s job.

Exceptions
std::runtime_errorif the directory holds no manifest, or a malformed one.

◆ pathOf()

std::filesystem::path Mila::Distribution::ModelPackage::pathOf ( const ModelFile & file) const
inline

Where a declared file lives in this package.

Exceptions
std::runtime_errorif the declared path would leave the package directory. A manifest can arrive from a hub, so a path is untrusted input and a .. in one is an attempt to write or read outside the package.

◆ validate()

PackageValidation Mila::Distribution::ModelPackage::validate ( ) const
inline

Check the package against its own manifest, reading every declared byte.

The byte count is checked before the digest so a truncated file reports its length rather than an opaque mismatch, which is the difference between "the transfer stopped" and "the bytes are wrong".


The documentation for this class was generated from the following file: