Train a Model
Train a model from your predictive query, training table, and graph snapshot, then inspect the metrics and saved artifacts of the completed fit. These calls use Kumo Engine and run synchronously in your Python process on Linux, macOS, or Windows through WSL2, or in a Snowflake or Databricks notebook. The training API is shared. Scratch storage and model publication differ by deployment.
Prerequisites
Before you start, complete the following prerequisites:
- Define the
queryas described in Predictive Queries. - Prepare the
training_tableandsnapshotas described in Generate or Supply Training Tables.
Model Plan
Request a plan suited to the query, then inspect it before starting training:
The suggestion uses graph and query metadata and does not start training.
For weighted supplied training rows, pass the same TrainingTableSpec as train_table_spec= so that the suggestion accounts for sample weights.
The plan is a kumoapi.model_plan.ModelPlan.
Its inferred values are resolved for your task during training.
Useful plan sections include the following:
For a short initial run, restrict the number of experiments and epochs and disable refits:
Choose your training budget based on the task and dataset. These settings are a starting point, not a model-quality target.
training_job.metrics selects built-in metrics, and training_job.tune_metric chooses the metric used to select the model.
For example, a regression task can use metrics=["mae", "mse", "rmse"] and tune_metric="mae".
To calculate a custom metric function, score held-out predictions after training and compare them with separately retained ground truth.
Training-table generation has its own plan passed to query generation. Changing the model plan does not regenerate the training table’s labels or splits.
For more information, refer to the Model Plan Guide.
How fit Selects a Model
fit() runs up to training_job.num_experiments trials, one after another, and chooses each trial’s configuration after the previous trial ends.
Each trial trains on the training rows and scores the validation rows with tune_metric after every epoch.
Two settings can end a trial early.
Early stopping (optimization.early_stopping) ends it when its own validation score stops improving.
Pruning (training_job.pruning) compares its score with earlier trials, using the configured min_epochs, patience, and min_delta.
The suggested plan uses k=3, min_epochs=2, and patience=1: from the second epoch on, a trial ends when its score beats none of the three best earlier trials at that epoch.
Kumo never prunes the first three trials.
The following diagram shows when trials end and how the selected checkpoint and the refits use the training, validation, and test rows.
Validation rows choose the model and test rows score it. Stopping settings follow the suggested plan. Configurations and metric values are illustrative.
The epoch with the best validation score across all trials is the selected checkpoint.
refit_trainval retrains that configuration for the same number of epochs on the training and validation rows.
Plans suggested with RunMode.NORMAL or RunMode.BEST enable it. RunMode.FAST, used earlier on this page, and RunMode.DEBUG leave it off.
refit_full also retrains it on every row, including test, so that model has no test score.
Test rows score the selected checkpoint and the training and validation refit.
Predictions from the fitted model use the model trained on the most rows by default: the full refit when enabled, otherwise the training and validation refit, otherwise the selected checkpoint.
Train a Model
Kumo selects an available device by default (accelerator="auto").
To choose explicitly, pass accelerator="cpu", accelerator="gpu" for NVIDIA CUDA, or accelerator="mps" for an Apple silicon GPU to Trainer.
Kumo uses the selected device for both training and prediction.
Construct a trainer and select the graph snapshot explicitly:
For reference, the trainer.fit() signature is as follows:
The training table supplies rows, labels, splits, and generation settings. The snapshot supplies graph data and features. You can reuse the same training table with a compatible updated snapshot without regenerating its labels.
trainer.model_plan is the public configuration for the next fit.
You can modify it or assign another ModelPlan before fitting again.
Each fit uses its own run directory, and the trainer’s fitted state then represents the most recent successful fit.
Keep earlier results if you need their model bundles.
Without warm_start, each fit() starts fresh, including when called on a loaded trainer.
To reuse a trained model for inference, load its saved bundle.
Start a New Run From a Trained Model
Pass a fitted or loaded Trainer as warm_start to initialize a new run from its selected model.
Continue from the fitted trainer, training_table, and snapshot above:
For a retained model, replace previous = trainer with previous = Trainer.load("/path/to/retained-models/model-v1"), or retrieve it through its publication connector.
Keep the source bundle available throughout the fit.
The new run reuses the source’s selected weights, optimizer state, fitted encoders, model architecture, and neighbor sampling.
The destination plan’s optimization and training controls, including the epoch budget above, still apply.
Changing the destination’s encoder or architecture settings does not replace the inherited fitted model structure.
The source and destination must have the same task type. Forecasting does not support warm starts. Supply a compatible training table and graph snapshot, including compatible targets and features. Use a complete compatible bundle containing the selected checkpoint and resolved model plan. An older bundle containing only unresolved search settings is not a reliable warm-start source.
A warm start creates a separate training run and leaves the source trainer available for inference.
It does not resume an interrupted job at its last step.
Use next_trainer and next_result for the new model’s predictions and artifacts.
Metrics and Training Results
A completed fit returns the following attributes, rather than a hosted job handle:
Inspect the available metric names instead of assuming every task returns the same keys:
Metrics depend on the task, configured evaluation metrics, and splits evaluated by the run. For example, classification can report AUROC, while regression can report MAE. Unavailable or nonfinite metrics can be omitted, so an empty split dictionary is not a score of zero. Refer to Read Retained Model Metrics and Read Holdout Predictions.
Every successful fit saves the metadata needed to reload the bundle in another process, including its query, model plan, and effective generation settings. An export is not required for reload. The bundle lives under execution scratch unless you retain it elsewhere. In local Python, copy or publish it to retained filesystem or object storage. In a Snowflake notebook, publish it to Snowflake Model Registry or preserve the complete local bundle before notebook storage is removed. In a Databricks notebook, publish it to Unity Catalog or copy the complete bundle from scratch to a Unity Catalog volume before the cluster stops.
Next Steps
To keep the trained model beyond execution scratch, publish it. For a supported connector destination, supply ModelOutputConfig to the fit call and publish the complete bundle to durable storage or a model registry. With a DatabricksConnector, publish to Unity Catalog, or copy the bundle to a Unity Catalog volume after fitting.
Record the returned publication name, version, or path so that another process can retrieve the same bundle.
For details, refer to Publish and Retrieve Models.
Continue to Training Diagnostics, Inspect Model Explanations, or Make Predictions.