Sacred
Sacred is a tool to configure, organize, log, and reproduce computational experiments. It is designed to introduce only minimal overhead, while encouraging modularity and configurability of experiments.

What you will get with this integration?

With Neptune + Sacred integration the following metadata will be logged automatically for you:
    Hyper-parameters
    Losses & metrics
    Training code(Python scripts or Jupyter notebooks) and git information
    Dataset version
    Model Configuration
You can also log other metadata types like interactive charts, video, audio, and more. See What can you log and display?

Step 0: Before you start

Make sure that:

Install neptune-client[sacred], sacred, torch, and torchvision

Depending on your operating system open a terminal or CMD and run this command:
1
pip install neptune-client[sacred] sacred torch torchvision
Copied!
For more help see installing neptune-client.
This integration is tested with neptune-client[sacred]==0.9.19, sacred==0.8.2, torch==1.9.0, and torchvision==0.10.0.

Step 1: Initialize a Neptune Run

Place this code snippet at the beginning of your script or notebook cell
1
import neptune.new as neptune
2
3
run = neptune.init(project = '<YOUR_WORKSPACE/YOUR_PROJECT>',
4
api_token = '<YOURR_API_TOKEN>')
Copied!
This opens a new Run in Neptune that allows you to log various objects.
You need to authenticate yourself and open an existing project. Here is how: You can use the api_token='ANONYMOUS' and project='common/sacred-integration' to explore without having to create a Neptune account.

Step 2: Add NeptuneObserver() to your sacred experiment's observers

1
# Create sacred experiment
2
ex = Experiment('image_classification', interactive=True)
3
4
# Add NeptuneObserver
5
ex.observers.append(NeptuneObserver(run=neptune_run))
Copied!
Using NeptuneObsever the following is automatically logged to Neptune UI for you:
    Hyperparameters
    Loss
    Metrics

Step 3: Run your experiment and explore metadata in Neptune UI

After you define your @ex.config(hyperparameters and configuration) and @ex.main(training loop) you can run your experiment as you normally would.
1
ex.run()
Copied!
After running your script or notebook cell you will get a link similar to: https://app.neptune.ai/o/common/org/sacred-integration/e/SAC-11/ with common/sacred-integration replaced by your project, and SAC-11 replaced by your run.
Click on the link to open the Run in Neptune to watch your model training live.
Initially, it may be empty but keep the tab with the Run open to see your experiment metadata update in real-time.

Step 4: Log artifacts

When sacred.Experiment.add_artifact() is called with a filename and optionally a name this will trigger an event in the Neptune0bserver to upload the file to Neptune.
1
ex.add_artifact(filename='model_weights', name=f'./model.pth')
Copied!
The same goes for sacred resources.

Step 5: Stop Neptune Run

Once you are done logging, you should stop tracking the Run using the stop() method. This is only needed when logging from a notebook or some other interactive environment.
1
run.stop()
Copied!

How to ask for help?

Please visit the Getting help page. Everything regarding support is there

What’s next

Last modified 1mo ago