Analysing Runs#
Everything ScaleFM knows about a run lives on disk, in the root_directory you gave to
scalefm.acquire(). There are a few ways to look at it:
| You want to... | Use |
|---|---|
| See how many trials are pending, running, done or crashed, and the best so far | scalefm.status |
| Get plots and CSV/text reports of the whole run, at any time | scalefm.analyze |
| Have those plots kept up to date while the run is going | live_plots=True |
| Follow per-epoch metrics from inside your training loop | TensorBoard |
Trial status: scalefm.status#
scalefm.status tells you where a run stands: how many trials are in each state, and the
best configuration found so far. It only reads the run; it does not write any files.
Using watch
To show the status repeatedly, on unix systems you can use
Plots and reports: scalefm.analyze#
scalefm.analyze() rebuilds the summary folder of a run from what is
on disk: the CSVs and the plots. It does not evaluate
anything, so you can call it
- after a run has finished, in particular one that ran without
live_plots=True; - while a run is still going, from another process or machine: it writes under the same lock as the workers;
- after collecting results asynchronously, or after importing trials.
Which plots?#
Every figure comes with a CSV of the exact points it shows, so you can re-plot them your own way.
Scaling plots#
If the runs return a positive cost, ScaleFM draws scaling plots in
summary/scaling/, each with a CSV of its points. All of them use log-log axes and
mark the Pareto frontier: the runs with the best result for their cost.
Files in summary/scaling/ |
Plot |
|---|---|
loss_over_cost.{png,csv} |
the loss of every run over its training cost, the frontier and the fit of the run's optimizer |
downstream/<name>_over_cost.{png,csv} |
the same for each metric in downstream_performances, with a frontier of its own |
parameters/<name>_over_cost.{png,csv} |
each number in the config or info_dict that varies, coloured by the loss, with the frontier runs circled |
pareto_optimal_points.json |
the runs on the frontier of loss over cost, with their configs |
If the runs also return an inference_cost, every plot is drawn over it too
(..._over_inference_cost), with frontiers of their own, since a model that is
cheap to train can still be expensive to use. Accuracy-like metrics (names
containing _acc or recall) are plotted as 1 - value. See
the evaluate function for the values to return.
The fit on loss_over_cost is the scaling law the run's optimizer names. The
Chinchilla law for the chinchilla optimizer, if the runs return n_params and
n_data, and a power law otherwise. scalefm.predict() uses the same one.
Prediction plot#
scalefm.predict(ROOT_DIRECTORY, target_costs) also saves summary/scaling/prediction.png, with its CSVs: the fit extended to the target
budgets (left), and the predicted loss after each finished run (right).
Live plots during a run#
Pass live_plots=True to have the plots
redrawn after every evaluated trial as well. Where to pass it depends on how your
trials are evaluated: via scalefm.acquire() or scalefm.save_pipeline_results() (see the evaluate function).
Overhead
Each refresh reads every trial and redraws the figures, so it gets slower as the run
grows. Next to a training job of a few minutes this is negligible, but for many cheap
evaluations, leave live_plots off and call scalefm.analyze() when you want to look.
What's on disk?#
ScaleFM keeps several human-readable files in the ROOT_DIRECTORY, and a summary folder
with reports on the run.
ROOT_DIRECTORY
├── configs
│ ├── config_1
│ │ ├── config.yaml # The configuration
│ │ ├── metadata.json # Its state, worker and timings
│ │ └── report.yaml # Its result, once evaluated
│ └── ...
├── summary
│ ├── full.csv # One row per trial
│ └── scaling/ # Scaling plots, if the runs report a cost
├── summary_tb/ # Scaling data for TensorBoard
├── optimizer_info.yaml # The optimizer's configuration
├── optimizer_state.pkl # The optimizer's state, shared between workers
└── pipeline_space.pkl # The search space
full.csv has every trial's hyperparameters, together with whatever result and cost
evaluate_pipeline returned.
TensorBoard integration#
Scaling data#
For runs that report a cost, ScaleFM logs to ROOT_DIRECTORY/summary_tb after
every evaluation, with or without live_plots, one step per run:
scaling/incumbent/loss: the best loss so far;scaling/frontier/<metric>_over_<cost>: the runs on each Pareto frontier so far, as(trial id, value, cost), for the loss and each downstream metric, over the cost and the inference cost.
The trial ids match summary/full.csv. Logging to TensorBoard never stops a run: if
it fails, it only warns and catches up at the next update. TensorBoard shows only 10
text entries per tag by default, so to see the frontier at every step, start it with
Logging your own metrics#
In ScaleFM we replaced the traditional TensorBoard SummaryWriter with the ConfigWriter to streamline the logging process. This integration enhances the ability to visualize and diagnose hyperparameter optimization workflows, providing detailed insights into metrics and configurations during training.
Overview of ConfigWriter#
The ConfigWriter serves as a versatile and efficient tool for logging various training metrics and hyperparameter configurations. It seamlessly integrates with the ScaleFM, enabling better visualization and analysis of model performance during hyperparameter searches.
To enable live logging of the incumbent trajectory, use the write_summary_incumbent argument when initializing ConfigWriter.
If a user only wishes to log the incumbent and does not want a specific writer for each configuration (i.e., no other logging in the run pipeline), they should simply trigger the scalefm.tblogger.WriteIncumbent() function in their run pipeline
Example Usage#
Below is an example implementation of the ConfigWriter for logging metrics during the training process:
import scalefm
# Substitute the TensorBoard SummaryWriter with ConfigWriter from ScaleFM
writer = scalefm.tblogger.ConfigWriter(write_summary_incumbent=True)
for i in range(max_epochs):
objective_to_minimize = training(
optimizer=optimizer,
model=model,
criterion=criterion,
train_loader=train_loader,
validation_loader=validation_loader,
)
# Gathering the gradient mean in each layer
mean_gradient = []
for layer in model.children():
layer_gradients = [param.grad for param in layer.parameters()]
if layer_gradients:
mean_gradient.append(
torch.mean(torch.cat([grad.view(-1) for grad in layer_gradients]))
)
###################### Start ConfigWriter Logging ######################
writer.add_scalar(tag="loss", scalar_value=objective_to_minimize, global_step=i)
writer.add_scalar(
tag="lr_decay", scalar_value=scheduler.get_last_lr()[0], global_step=i
)
writer.add_scalar(
tag="layer_gradient1", scalar_value=mean_gradient[0], global_step=i
)
writer.add_scalar(
tag="layer_gradient2", scalar_value=mean_gradient[1], global_step=i
)
scheduler.step()
print(f" Epoch {i + 1} / {max_epochs} Val Error: {objective_to_minimize} ")
# Logging hyperparameters and metrics
writer.add_hparams(
hparam_dict={"lr": lr, "optim": optim, "wd": weight_decay},
metric_dict={"loss_val": objective_to_minimize},
)
writer.close()
Visualizing Results#
The following command will open a local host for TensorBoard visualizations, allowing you to view them either in real-time or after the run is complete.
This image shows visualizations related to scalar values logged during training. Scalars typically include metrics such as loss, incumbent trajectory, a summary of losses for all configurations, and any additional data provided via the extra_data argument in the tblogger.log function.

This image represents visualizations related to logged images during training. It could include snapshots of input data, model predictions, or any other image-related information. In our case, we use images to depict instances of incorrect predictions made by the model.

The following images showcase visualizations related to hyperparameter logging in TensorBoard. These plots include three different views, providing insights into the relationship between different hyperparameters and their impact on the model.
In the table view, you can explore hyperparameter configurations across five different trials. The table displays various hyperparameter values alongside corresponding evaluation metrics.

The parallel coordinate plot offers a holistic perspective on hyperparameter configurations. By presenting multiple hyperparameters simultaneously, this view allows you to observe the interactions between variables, providing insights into their combined influence on the model.

The scatter plot matrix view provides an in-depth analysis of pairwise relationships between different hyperparameters. By visualizing correlations and patterns, this view aids in identifying key interactions that may influence the model's performance.
