Skip to content

ModelPackage

#include <qbruntime/model_package.h>

class mobilint::ModelPackage

Represents an MXQ package (.mxqpkg) that packs multiple MXQ files into a single file.

Opens the package once and creates Model objects from its MXQ entries without unpacking it. Prefer this class to Model::create(mxq_pkg_path, entry_name, ...) when creating many models from the same package, because the package index is read only once.

Models created from a ModelPackage do not depend on it, so the ModelPackage may be destroyed while the models are still in use.

Warning

The package file is read again by createModel and loadEntry, and by the created models when they are launched. Moving or deleting the file before then makes those calls fail, and modifying it may make the models produce wrong results.

The const member functions, such as createModel and loadEntry, may be called concurrently from multiple threads on the same ModelPackage.

Static functions

Member Description
create Opens the specified MXQ package file.

create

static std::unique_ptr<ModelPackage> create(const std::string &mxq_pkg_path, StatusCode &sc)

Opens the specified MXQ package file.

Reads and validates the package index. The MXQ entries are not loaded until createModel is called.

Parameters

  • mxq_pkg_path [in] — The path to the MXQ package file.
  • sc [out] — A reference to a status code that will be updated to indicate whether the package was successfully opened or if an error occurred.

Returns

A unique pointer to the created ModelPackage object.

Member functions

Member Description
ModelPackage ×2
operator= ×2
createModel ×2 Creates a Model object from an MXQ entry in the package.
getPath Returns the path to the MXQ package file.
getEntryNames Returns the names of all entries in the package, in the order they are stored.
loadEntry Reads the payload of a non-MXQ entry in the package into memory.

ModelPackage

ModelPackage(const ModelPackage &other)=delete
ModelPackage(ModelPackage &&other) noexcept

operator=

ModelPackage & operator=(const ModelPackage &rhs)=delete
ModelPackage & operator=(ModelPackage &&rhs) noexcept

createModel

std::unique_ptr<Model> createModel(const std::string &entry_name, StatusCode &sc) const

Creates a Model object from an MXQ entry in the package.

The model is initialized in auto-core mode.

Note

The created Model object must be launched before performing inference. See Model::launch for more details.

Parameters

  • entry_name [in] — The name of the MXQ entry in the package (e.g. "block_0_expert_0.mxq").
  • sc [out] — A reference to a status code that will be updated to indicate whether the model was successfully created or if an error occurred.

Returns

A unique pointer to the created Model object.

std::unique_ptr<Model> createModel(const std::string &entry_name, const ModelConfig &config, StatusCode &sc) const

Creates a Model object from an MXQ entry in the package and configuration.

Note

The created Model object must be launched before performing inference. See Model::launch for more details.

Parameters

  • entry_name [in] — The name of the MXQ entry in the package (e.g. "block_0_expert_0.mxq").
  • config [in] — The configuration settings to initialize the Model.
  • sc [out] — A reference to a status code that will be updated to indicate whether the model was successfully created or if an error occurred.

Returns

A unique pointer to the created Model object.

getPath

std::string getPath() const

Returns the path to the MXQ package file.

Returns

The MXQ package file path.

getEntryNames

std::vector<std::string> getEntryNames() const

Returns the names of all entries in the package, in the order they are stored.

The names include entries that are not MXQ files, such as a manifest. Only MXQ entries can be passed to createModel, and only the other entries can be passed to loadEntry.

Returns

The entry names.

loadEntry

StatusCode loadEntry(const std::string &entry_name, std::vector<uint8_t> &buffer) const

Reads the payload of a non-MXQ entry in the package into memory.

The whole payload is read at once and verified against the checksum stored in the package. This is intended for small entries such as a manifest. MXQ entries are rejected; use createModel for them.

Parameters

  • entry_name [in] — The name of the entry in the package (e.g. "manifest.json").
  • buffer [out] — A reference to a byte vector that will store the entry payload. Its previous contents are discarded.

Returns

A status code indicating whether the entry was successfully read or if an error occurred. StatusCode::ModelPackage_FailedToReadEntry is returned for an MXQ entry.