ML Model Factory SDK¶
Project-team quickstart¶
The Python import is ml_model_factory; install from the maintained
usecase_code\50-ml-model-factory project or its copy in the repository of your project. Configure
scenarios under user-config; do not edit shared engines or generated notebooks.
1. Prepare the local environment¶
From the repository root:
Set-Location .\usecase_code\50-ml-model-factory
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install -e ".[train]"
.\.venv\Scripts\python.exe -m ml_model_factory --help
.\.venv\Scripts\python.exe -m ml_model_factory validate --scenario user-config\model\scenarios\diabetes.json
.\.venv\Scripts\python.exe -m ml_model_factory usecases --pattern batch --task-folder classification --technology notebook
Use Python 3.10–3.13 and the declared dependency ranges. Package installation
needs access to your approved package feed; the following examples themselves
make no cloud calls. train installs local training dependencies, not Azure
credentials or compute.
2. Validate configuration and inspect a route with Python¶
Save as inspect_model.py in the model-factory root and run
.\.venv\Scripts\python.exe .\inspect_model.py. This reads the existing
scenario and catalog without downloading data, training or writing files.
import json
from pathlib import Path
from ml_model_factory.config import load_json, validate_scenario
from ml_model_factory.usecases import describe, find
scenario = validate_scenario(load_json(Path("user-config/model/scenarios/diabetes.json")))
route = find("batch", "classification", "notebook")
print(json.dumps({"scenario": scenario["name"],
"features": scenario["features"],
"route": describe(route, [scenario])}, indent=2))
Choose batch, online or streaming, then a task and technology from the use-case catalog. The local classification notebook and its prerequisites reuse the same engines. A supported catalog entry or rendered notebook is not evidence that its cloud training or serving route has succeeded.
3. Optional local CSV preparation, training and evaluation¶
Prerequisites: an already-reviewed, local diabetes.csv matching the
scenario's features and label, dataset
licensing/terms, and the local train dependencies above. Data is not bundled
with the starter. No Kaggle credentials or network download is hidden here;
see the explicit ingest implementation
if you separately choose ingestion.
This teaching scenario is not clinical decision support. Review missing values, cohort representativeness and intended use. Do not substitute arbitrary data, lower quality thresholds or treat a passing tutorial as production approval.
Save as train_local.py in the model-factory root and run it with the component
interpreter. Each run uses a fresh output folder and preserves the scenario's
split, estimator and quality gates. Only local artifacts are produced.
import json
from pathlib import Path
from uuid import uuid4
from ml_model_factory.config import load_json, validate_scenario
from ml_model_factory.data import prepare
from ml_model_factory.training import train
from ml_model_factory.evaluation import evaluate
scenario = validate_scenario(load_json(Path("user-config/model/scenarios/diabetes.json")))
csv_path = Path(input("Path to the reviewed local diabetes.csv: ").strip()).resolve(strict=True)
run_dir = Path("ml-environment/outputs/diabetes") / ("local-" + uuid4().hex)
prepared, model, report = run_dir / "prepared", run_dir / "model", run_dir / "report"
manifest = prepare(scenario, csv_path, prepared)
train(scenario, prepared, model)
evaluation = evaluate(scenario, prepared, model, report)
print(json.dumps({"output": str(run_dir), "split_rows": manifest["split_rows"],
"metrics": evaluation["metrics"]}, indent=2))
Inspect prepared\manifest.json, the local MLflow model and
report\metrics.json, quality-gate.json, comparison.json and
responsible-ai.json. A failed gate raises an error and records the failure;
stop and investigate rather than changing its result. This code neither
registers a model nor deploys an endpoint.
CLI equivalents are prepare --scenario ... --input ... --output ...,
train --scenario ... --prepared ... --model-output ... and
evaluate --scenario ... --prepared ... --model ... --output ...;
use python -m ml_model_factory <command> --help for the exact arguments.
4. Optional Azure work and gated registration¶
First create your own runtime.local.json with operator-reviewed existing
workspace, compute, environment and storage bindings; see
project-specific settings,
offline preview and the
model-factory guide. Install the declared azure extra only
for that path. Approved identity/private connectivity, compatible pinned
environments and cost budgets are prerequisites, not outcomes of this tutorial.
For Azure ML SDK v2, the real functions are
render, submit, registration_definition and register.
render writes local job definitions; submit creates a billed cloud run.
Registration requires a completed factory pipeline with matching scope,
evaluation lineage and a passing downloaded quality gate. Local training files
alone cannot satisfy that cloud registration contract.
The following is a function definition only; it makes no cloud call until you explicitly invoke it after reviewing the completed job and its target. Keep the real champion's compatible held-out evaluation and selection policy. The first-model case is a separate explicit policy decision, not a default.
from pathlib import Path
from ml_model_factory.config import load_json, validate_runtime
from ml_model_factory.azureml import register
def register_reviewed_winner(runtime_path: Path, completed_job_name: str,
model_name: str, policy_path: Path,
champion_report_path: Path) -> str:
runtime = validate_runtime(load_json(runtime_path))
policy = load_json(policy_path)
champion = load_json(champion_report_path)
return register(completed_job_name, runtime, model_name,
selection_policy=policy, champion_evaluation=champion)
See the full SDK/CLI registration and selection tutorial
and actual SDK wrapper /
CLI v2 wrapper.
Endpoint deployment is a further reviewed operation; serving CLI mutations
preview unless --execute is supplied. Cloud routes can still fail because
of environment, data, networking or backend limitations. No live ML success
is claimed here, and no implementation repair or gate bypass is part of onboarding.
For agent workloads, start with the Agent Factory SDK.