Sacred integration guide#
Sacred is a tool to configure, organize, log, and reproduce computational experiments. With the Neptune-Sacred integration, you can log the following metadata automatically:
- Metrics and losses
- Training code and Git information
- Dataset version
- Model configuration
Before you start#
Installing the integration#
To use your preinstalled version of Neptune together with the integration:
To install both Neptune and the integration:
Passing your Neptune credentials
Once you've registered and created a project, set your Neptune API token and full project name to the
NEPTUNE_PROJECT environment variables, respectively.
To find your API token: In the bottom-left corner of the Neptune app, expand the user menu and select Get my API token.
To find your project: Your full project name has the form
workspace-name/project-name. To copy the name, click the menu in the top-right corner and select Edit project details.
While it's not recommended especially for the API token, you can also pass your credentials in the code when initializing Neptune.
For more help, see Set Neptune credentials.
If you'd rather follow the guide without any setup, you can run the example in Colab .
Sacred logging example#
Track your metadata with Neptune by adding a
NeptuneObserver to the observers of your Sacred experiment.
Create a run:
If you haven't set up your credentials, you can log anonymously:
Create a Sacred experiment:
If you're in an interactive environment such as Jupyter Notebook, you need to add the argument
For details about this safeguard, see the Sacred documentation .
NeptuneObserverinstance to the observers of the experiment and pass the created run:
To stop the connection to Neptune and sync all data, call the
Run your experiment as you normally would.
To open the run, click the Neptune link that appears in the console output.
Select the Charts section to view the model training metrics live, or create a custom dashboard.
When you call
sacred.Experiment.add_artifact() with a filename and optionally a name, this triggers an event in the
NeptuneObserver to upload the file to Neptune.
The same applies to Sacred resources. For details, see the Sacred documentation .
Manually logging metadata#
If you have other types of metadata that are not covered in this guide, you can still log them using the Neptune client library.
When you initialize the run, you get a
run object, to which you can assign different types of metadata in a structure of your own choosing.
import neptune # Create a new Neptune run run = neptune.init_run() # Log metrics or other values inside loops for epoch in range(n_epochs): ... # Your training loop run["train/epoch/loss"].append(loss) # Each append() appends a value run["train/epoch/accuracy"].append(acc) # Upload files run["test/preds"].upload("path/to/test_preds.csv") # Track and version artifacts run["train/images"].track_files("./datasets/images") # Record numbers or text run["tokenizer"] = "regexp_tokenize"