tracker
orchard.tracking.tracker
¶
MLflow Tracker Implementation.
Provides MLflowTracker for experiment tracking and NoOpTracker as a silent fallback when MLflow is unavailable or tracking is disabled.
TrackerProtocol
¶
Bases: Protocol
Protocol defining the experiment tracker interface.
Both MLflowTracker and NoOpTracker implement this protocol, enabling type-safe dependency injection without inheritance.
NoOpTracker
¶
Silent no-op tracker used when MLflow is disabled or unavailable.
All methods mirror the MLflowTracker interface but perform no operations, ensuring zero overhead when tracking is not active.
MLflowTracker(experiment_name='orchard-ml')
¶
MLflow-based experiment tracker for Orchard ML runs.
Manages a single MLflow run lifecycle: parameter logging, per-epoch metrics, final test metrics, and artifact collection. Supports nested runs for Optuna trial tracking.
Attributes:
| Name | Type | Description |
|---|---|---|
experiment_name |
str
|
MLflow experiment name. |
Source code in orchard/tracking/tracker.py
start_run(cfg, run_name, tracking_uri)
¶
Start an MLflow run and log all config parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
Any
|
Config object with dump_serialized() method. |
required |
run_name
|
str
|
Human-readable run name (typically paths.run_id). |
required |
tracking_uri
|
str
|
SQLite URI for local MLflow storage. |
required |
Source code in orchard/tracking/tracker.py
log_epoch(epoch, train_loss, val_metrics, lr)
¶
Log per-epoch training metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epoch
|
int
|
Current epoch number (1-based). |
required |
train_loss
|
float
|
Training loss for this epoch. |
required |
val_metrics
|
Mapping[str, float]
|
Validation metrics dict with 'loss', 'accuracy', 'auc', 'f1'. |
required |
lr
|
float
|
Current learning rate. |
required |
Source code in orchard/tracking/tracker.py
log_test_metrics(test_acc, macro_f1)
¶
Log final test set metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_acc
|
float
|
Test set accuracy. |
required |
macro_f1
|
float
|
Test set macro-averaged F1 score. |
required |
Source code in orchard/tracking/tracker.py
log_artifact(path)
¶
Log a single file as an MLflow artifact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to file to log. |
required |
log_artifacts_dir(directory)
¶
Log all files in a directory as MLflow artifacts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
Path
|
Directory whose contents to log. |
required |
Source code in orchard/tracking/tracker.py
start_optuna_trial(trial_number, params)
¶
Start a nested MLflow run for an Optuna trial.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trial_number
|
int
|
Optuna trial number. |
required |
params
|
dict[str, Any]
|
Sampled hyperparameters for this trial. |
required |
Source code in orchard/tracking/tracker.py
end_optuna_trial(best_metric)
¶
End the current nested Optuna trial run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
best_metric
|
float
|
Best validation metric achieved in this trial. |
required |
Source code in orchard/tracking/tracker.py
create_tracker(cfg)
¶
Factory: returns MLflowTracker if tracking is configured, else NoOpTracker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
Any
|
Config object. If cfg.tracking is set and enabled, returns MLflowTracker. |
required |
Returns:
| Type | Description |
|---|---|
TrackerProtocol
|
Active tracker instance. |