콘텐츠로 이동

ModelPackage

class 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(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 discarded while the models are still in use.

Warning

The package file is read again by create_model and load_entry, 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.

Methods

Name Description
__init__ Opens the specified MXQ package file.
create_model Creates a Model object from an MXQ entry in the package.
get_path Returns the path to the MXQ package file.
get_entry_names Returns the names of all entries in the package, in the order they are stored.
load_entry Reads the payload of a non-MXQ entry in the package into memory.

__init__

def __init__(self, path: str)

Opens the specified MXQ package file.

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

Parameters

  • path [in] — The path to the MXQ package file.

create_model

def create_model(
    self, entry_name: str, model_config: Optional[ModelConfig] = None
) -> Model

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

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").
  • model_config [in] — The configuration settings to initialize the Model. If None, the model is initialized in auto-core mode.

Returns

The created Model object.

get_path

def get_path(self) -> str

Returns the path to the MXQ package file.

Returns

The MXQ package file path.

get_entry_names

def get_entry_names(self) -> List[str]

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 create_model, and only the other entries can be passed to load_entry.

Returns

The entry names.

load_entry

def load_entry(self, entry_name: str) -> bytes

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 create_model for them.

Parameters

  • entry_name [in] — The name of the entry in the package (e.g. "manifest.json").

Returns

The entry payload.