Skip to main content

FLOR: Experiment Management for ML Engineers

You can use FLOR to take checkpoints during model training. These checkpoints allow you to restore arbitrary training data post-hoc and efficiently, thanks to memoization and parallelism speedups on replay.

FLOR is a suite of machine learning tools for hindsight logging. Hindsight logging is an optimistic logging practice favored by agile model developers. Model developers log training metrics such as the loss and accuracy by default, and selectively restore additional training data --- like tensor histograms, images, and overlays --- post-hoc, if and when there is evidence of a problem.

FLOR is software developed at UC Berkeley's RISE Lab, and is being released as part of an accompanying VLDB publication.

Installation

pip install pyflor

FLOR expects a recent version of Python (3.7+) and PyTorch (1.0+).

git checkout -b flor.shadow
python3 examples/linear.py --flor linear

Run the linear.py script to test your installation. This script will train a small linear model on MNIST. Think of it as a ''hello world'' of deep learning. We will cover FLOR shadow branches later.

ls ~/.flor/linear

Confirm that FLOR saved checkpoints of the linear.py execution on your home directory. FLOR will access and interpret contents of ~/.flor automatically. Do watch out for storage footprint though. If you see disk space running out, check ~/.flor. FLOR includes utilities for spooling its checkpoints to S3.

Preparing your Training Script

from flor import MTK as Flor
for epoch in Flor.loop(range(...)):
    ...

First, wrap the iterator of the main loop with FLOR's generator: Flor.loop. The generator enables FLOR to parallelize replay of the main loop, and to jump to an arbitrary epoch for data recovery.

from flor import MTK as Flor

import torch

trainloader: torch.utils.data.DataLoader
testloader:  torch.utils.data.DataLoader
optimizer:   torch.optim.Optimizer
net:         torch.nn.Module
criterion:   torch.nn._Loss

Flor.checkpoints(net, optimizer)
for epoch in Flor.loop(range(...)):
    for data in Flor.loop(trainloader):
        inputs, labels = data
        optimizer.zero_grad()
        outputs = net(inputs)
        loss = criterion(outputs, labels)
        loss.backward()
        optimizer.step()
        print(f"loss: {loss.item()}")
    eval(net, testloader)

That's it, your training code is now ready for record-replay.

Training your model

python3 training_script.py --flor NAME [your_script_flags]

Before we train your model, make sure that your model training code is part of a git repository. Model training is exploratory and it's common to iterate dozens of times before finding the right fit. We'd hate for you to be manually responsible for managing all those versions. Instead, we ask you to create a FLOR shadow branch that we can automatically commit changes to. Think of it as a sandbox: you get the benefits of autosaving, without worrying about us poluting your main branch with frequent & automatic commits. Later, you can merge the changes you like.

In FLOR, all experiments need a name. As your training scripts and configurations evolve, keep the same experiment name so FLOR associates the checkpoints as versions of the same experiment. If you want to re-use the name from the previous run, you may leave the field blank.

Hindsight Logging

from flor import MTK as Flor
import torch

trainloader: torch.utils.data.DataLoader
testloader:  torch.utils.data.DataLoader
optimizer:   torch.optim.Optimizer
net:         torch.nn.Module
criterion:   torch.nn._Loss

for epoch in Flor.loop(range(...)):
    for batch in Flor.loop(trainloader):
        ...
    eval(net, testloader)
    log_confusion_matrix(net, testloader)

Suppose you want to view a confusion matrix as it changes throughout training. Add the code to generate the confusion matrix, as sugared above.

python3 training_script.py --replay_flor

You first switch to the FLOR shadow branch, and select the version you wish to replay from the git log list. In our example, we won't checkout version, because we want to replay the latest version, which is selected by default.

You will tell FLOR to replay by setting the flag --replay_flor. FLOR is performing fast replay, so you may generalize this example to recover ad-hoc training data. In our example, FLOR will compute your confusion matrix and automatically skip the nested training loop by loading its checkpoints.

from flor import MTK as Flor
import torch

trainloader: torch.utils.data.DataLoader
testloader:  torch.utils.data.DataLoader
optimizer:   torch.optim.Optimizer
net:         torch.nn.Module
criterion:   torch.nn._Loss

for epoch in Flor.loop(range(...)):
    for batch in Flor.loop(trainloader, probed=True):
        ...
    eval(net, testloader)
    log_confusion_matrix(net, testloader)

Now, suppose you also want TensorBoard to plot the tensor histograms. In this case, it is not possible to skip the nested training loop because we are probing intermediate data. We tell FLOR to step into the nested training loop by setting probed=True.

Although we can't skip the nested training loop, we can parallelize replay or re-execute just a fraction of the epochs (e.g. near the epoch where we see a loss anomaly).

python3 training_script.py --replay_flor PID/NGPUS [your_flags]

As before, you tell FLOR to run in replay mode by setting --replay_flor. You'll also tell FLOR how many GPUs from the pool to use for parallelism, and you'll dispatch this script simultaneously, varying the pid:<int> to span all the GPUs. To run segment 3 out of 5 segments, you would write: --replay_flor 3/5.

If instead of replaying all of training you wish to re-execute only a fraction of the epochs you can do this by setting the value of ngpus and pid respectively. Suppose you want to run the tenth epoch of a training job that ran for 200 epochs. You would set pid:9and ngpus:200.

We provide additional examples in the examples directory. A good starting point is linear.py.

Publications

To cite this work, please refer to the Hindsight Logging paper (VLDB '21).

FLOR is open source software developed at UC Berkeley. Joe Hellerstein (databases), Joey Gonzalez (machine learning), and Koushik Sen (programming languages) are the primary faculty members leading this work.

This work is released as part of Rolando Garcia's doctoral dissertation at UC Berkeley, and has been the subject of study by Eric Liu and Anusha Dandamudi, both of whom completed their master's theses on FLOR. Our list of publications are reproduced below. Finally, we thank Vikram Sreekanti, Dan Crankshaw, and Neeraja Yadwadkar for guidance, comments, and advice. Bobby Yan was instrumental in the development of FLOR and its corresponding experimental evaluation.

License

FLOR is licensed under the Apache v2 License.

Metadata

Release files for pyflor 2.5.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyflor 2.5.6
File Size Uploaded Provenance Actions
pyflor-2.5.6.tar.gz 39.4 kB Without provenance Details for pyflor-2.5.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyflor 2.5.6
File Interpreter ABI Platform Actions
pyflor-2.5.6-py3-none-any.whl Python 3 none any Details for pyflor-2.5.6-py3-none-any.whl

Total release size: 90.1 kB

Release files / pyflor-2.5.6.tar.gz

Download URL pyflor-2.5.6.tar.gz
Size 39.4 kB
Tags Source
SHA-256 checksum
How to use checksums
14729eaa18b4ca22ee2a65d8eabbaf1f0a3d41b0789f29d25822802aded4250c
BLAKE2b-256 checksum
How to use checksums
0ca9bf7e9ea664dfb23603fc67ac5b60129b24ae7b120966e67c893369ac5fac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release files / pyflor-2.5.6-py3-none-any.whl

Download URL pyflor-2.5.6-py3-none-any.whl
Size 50.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3c3d1208cadf6ab355b45f20216de5d9eb9307f80d52c15e7320d9cca16c2b16
BLAKE2b-256 checksum
How to use checksums
af81fa9fc38715e83659f401e89446c0843b60b05bbf2ed7e8c76b8283a6fe65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Security for pyflor 2.5.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.5.6 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page