build_from_module()¶
Build an ONNX ModelPackage from a module instance and config.
from mobius import build_from_module
Signature¶
def build_from_module(
module: nn.Module,
config: BaseModelConfig,
task: str | ModelTask = "text-generation",
) -> ModelPackage:
Parameters¶
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
(required) |
An |
|
|
(required) |
Architecture configuration. The |
|
|
|
Task name string or |
Returns¶
ModelPackage — A dict-like collection of named ir.Model objects.
Examples¶
from mobius import build_from_module, ArchitectureConfig
from mobius.models import CausalLMModel
config = ArchitectureConfig(
vocab_size=32000,
max_position_embeddings=4096,
hidden_size=4096,
intermediate_size=11008,
num_hidden_layers=32,
num_attention_heads=32,
num_key_value_heads=32,
hidden_act="silu",
head_dim=128,
pad_token_id=0,
)
module = CausalLMModel(config)
pkg = build_from_module(module, config)
pkg["model"] # ir.Model
Behavior¶
Validates config (if
validate()is available)Casts module parameters to target dtype
Resolves the task and builds the ONNX graph
Applies optimization passes (identity elimination, CSE, etc.)