> For the complete documentation index, see [llms.txt](https://docs.valohai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.valohai.com/notebook-executions/save-and-version.md).

# Save Your Work

Valohai automatically versions your notebook's final state when you stop it. You can also save outputs and log metrics while working, just like you would in a standard execution.

### Automatic Versioning

Every time you stop a notebook, Valohai saves:

* The final `.ipynb` file with all cell outputs
* Any files written to `/valohai/outputs/`
* Metadata logs you've created during the session

This means you can always return to previous notebook states. Your work is versioned without extra effort.

### Save Files During Your Session

Write files to the outputs directory to version them:

```python
import valohai

# Save a model file
output_path = valohai.outputs().path("model.h5")
model.save(output_path)

# Or use the direct path
output_path = "/valohai/outputs/model.h5"
model.save(output_path)
```

Files saved to `/valohai/outputs/` appear in your notebook execution's outputs tab. You can download them, use them as inputs in other jobs, or register them as model versions.

### Log Metrics and Metadata

Track metrics during training or experimentation using `valohai-utils`:

```python
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)
```

These logs appear in the Valohai UI under your notebook execution's metadata tab. You can visualize them, compare across runs, or export them for analysis.

> 💡 **Tip:** Use the same logging approach in notebooks and executions. This makes it easier to migrate code later.

### Run and Version as a Standard Execution

Once your notebook code is working, you can run it end-to-end as a versioned execution using the **Run Remote** button.

#### Setup with valohai.prepare

Add a cell at the top of your notebook to define the execution configuration:

```python
import valohai

valohai.prepare(
    step="training-experiment",
    image="python:3.9",
    default_inputs={
        "dataset": "s3://mybucket/data/train.csv",
    },
    default_parameters={
        "learning_rate": 0.001,
        "epochs": 10,
    },
)
```

This tells Valohai how to run your notebook as a standalone job.

#### Run Remote

Click the **Run Remote** button in Jupyter. Valohai will:

1. Execute your notebook top-to-bottom in a fresh environment
2. Create a standard execution (not a notebook execution)
3. Version the code, outputs, and metadata

The new execution runs independently—you can close your notebook, and the job continues. Your teammates can also run the same code without needing to interact with Jupyter.

> 💡 **When to use Run Remote:** Use this when you want to version a specific experiment, share reproducible results, or test your notebook in a clean environment before migrating to `valohai.yaml`.

### Next Steps

* [Convert to Production Script](/notebook-executions/notebook-to-execution.md) — Move from experimentation to production workflows
* [Push to Git](/notebook-executions/push-to-git.md) — Commit your notebook changes to version control
* [Collect Metrics](/experiment-tracking/collect-metrics.md) — Deep dive into metadata logging


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.valohai.com/notebook-executions/save-and-version.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
