Legacy training_tools Migration#
The original mnn.utils.training_tools package remains importable for compatibility, but its split implementation files are legacy APIs. New code should use the single-file API in mnn.utils.training_tools_api.
The new module consolidates the public classes and functions from general_prepare.py, functional.py, and general_train.py into one explicit import surface. The legacy files are expected to be removed in a future release.
From version 0.2.1, training_tools_api.make_model() constructs Torch-first models by default. Existing YAML model fields are accepted and translated to the new constructor names, including num_class, use_cov, predict_bias_var, bn_bias_var, ln_bias, ln_bias_var, and record_bn_mean_var. The mnn_core criterion names are likewise mapped to their Torch-first *Torch implementations; legacy criterion arguments such as num_class, num_sample, is_classify, regular_cov, and normalise are translated as well. config_mnn_activation() configures the shared mnn.mnn_core.torch_activation core used by MomentActivation.
To intentionally construct the old model family for checkpoint comparison or migration, set use_legacy_api: true in the model metadata:
MODEL:
meta:
arch: mnn_mlp
mlp_type: mnn_mlp
use_legacy_api: true
Migration Table#
Legacy API |
New API |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
New Torch MLP to legacy MLP conversion |
|
New Torch MLP to constructed legacy MLP conversion |
|
Example#
Legacy:
from mnn.utils.training_tools import general_train
general_train.general_train_pipeline(args)
New:
from mnn.utils import training_tools_api
training_tools_api.general_train_pipeline(args)
Build a legacy MLP from a new Torch-first MLP:
from mnn.models import MomentMlp
from mnn.utils.torch_legacy import build_legacy_mlp_from_torch
new_model = MomentMlp([784, 512], num_classes=10)
legacy_model = build_legacy_mlp_from_torch(new_model)
Notes#
The old package-level exports such as
mnn.utils.training_tools.make_dataloaderremain available for now.The new module keeps the same training pipeline behavior but defaults model construction, MNN activation configuration, and MNN criteria to the Torch-first API.
meta.use_legacy_api: trueis the explicit compatibility switch for constructingMnnMlp,SnnMlp,MnnMlpNoRho,MnnMlpMeanOnly, orAnnMlp.Torch-to-legacy MLP helpers live in
mnn.utils.torch_legacy;training_tools_apire-exports them for compatibility.Torch-to-legacy MLP helpers support
MomentMlp,MomentMlpNoCorrelation, andMomentRateMlp; CNN/SNN conversion remains separate.This refactor does not make training tools Torch-only; dataset preparation, seeding, and NumPy-to-Tensor helpers still use NumPy where the original workflow requires it.