Customizing Your Notebook Environment
Want to tweak your notebook’s setup? Here’s how:
- Choose Your Base Image: Start by selecting a Docker image from public registries like Docker Hub. Popular choices could be Jupyter TensorFlow Notebook or PyTorch.
- Install Additional Libraries: If your chosen image doesn’t have everything you need, no worries! You can easily add more packages directly in your notebook:
!pip install matplotlib
- Jupyter Installation: If your Docker image doesn’t include Jupyter Notebook or Jupyter Lab, Valohai will handle the installation during the setup.
Run and version a notebook as a standard Valohai execution
Saving Your Work Automatically
Every time you finish working on a notebook in Valohai, the system saves the latest version for you. This means you can pick up right where you left off next time you open it.
Using ‘Run Remote’ for Better Teamwork
It’s a good idea to use the Run Remote
option in Valohai. This lets you run the whole notebook from start to finish on its own, and it keeps this version separate. This way, your team can easily use your notebook. They won’t have to worry about setting anything up; they can just start running the cells.
You need to set up the notebook using valohai.prepare
and press Run remote. This will start a new execution (not a notebook execution) for you, running your code from beginning to end as if it were a .py
file.
Setting Up Your Notebook
Start by adding a new cell that defines the Valohai step and it’s properties.
Here is the example of using valohai.prepare
:
import valohai
valohai.prepare(
step='your-step-name',
image='your-docker-image:tag',
default_inputs={
'input-name': 'input-url'
},
default_parameters={
'param1': value1,
'param2': value2
}
)
Check out our documentation page with the instructions on how to set up your step in Valohai using valohai-utils
. This will help you get everything ready to go.
Saving Data and Logging
Whether it’s saving your model or keeping track of important metrics, here’s how you do it in Valohai Notebooks (spoiler: it’s the same as you do it in Execution, Pipelines or Tasks):
- Save Your Files: Designate where to save your output, and use your framework’s save function:
output_path = valohai.outputs().path("model.h5") # or /valohai/outputs/model.h5
model.save(output_path)
- Logging Metadata: Use
valohai-utils
for logging metrics like accuracy and losses:
import valohai
for i in range(10):
with valohai.metadata.logger() as logger:
logger.log("iteration", i)
logger.log("accuracy", model.accuracy)
logger.log("loss", model.loss)