clearml-docs/docs/guides/set_offline.md

102 lines
3.8 KiB
Markdown
Raw Normal View History

2021-07-14 07:36:25 +00:00
---
title: Storing Task Data Offline
---
If your computer is offline, or you do not want a Task's data and logs stored in the ClearML Server, use
the **Offline Mode** option. In this mode, all the data and logs that the Task captures from the code are stored in a
2023-05-18 09:17:21 +00:00
local session folder, which can be later uploaded to the [ClearML Server](../deploying_clearml/clearml_server.md).
2021-07-14 07:36:25 +00:00
2021-09-09 10:17:46 +00:00
## Setting Task to Offline Mode
2021-07-14 07:36:25 +00:00
2023-05-18 09:17:21 +00:00
You can enable offline mode in one of the following ways:
* Before initializing a task, use the [`Task.set_offline`](../references/sdk/task.md#taskset_offline) class method and set
the `offline_mode` argument to `True`
```python
from clearml import Task
2024-01-10 12:40:19 +00:00
2023-05-18 09:17:21 +00:00
# Use the set_offline class method before initializing a Task
Task.set_offline(offline_mode=True)
# Initialize a Task
task = Task.init(project_name="examples", task_name="my_task")
```
* Before running a task, set `CLEARML_OFFLINE_MODE=1`
2021-07-14 07:36:25 +00:00
2024-06-23 07:00:06 +00:00
:::warning
2023-06-13 09:21:35 +00:00
Offline mode only works with tasks created using [`Task.init()`](../references/sdk/task.md#taskinit) and not with those created
using [`Task.create()`](../references/sdk/task.md#taskcreate).
2023-04-03 07:27:43 +00:00
:::
2023-05-18 09:17:21 +00:00
All the information captured by the Task is saved locally. Once the task script finishes execution, it's zipped. The
session's zip folder's location is `~/.clearml/cache/offline/<task_id>.zip`.
2021-07-14 07:36:25 +00:00
2023-05-18 09:17:21 +00:00
The task's console output displays the task ID and a path to the folder with the session's captured information:
2021-07-14 07:36:25 +00:00
```console
ClearML Task: created new task id=offline-372657bb04444c25a31bc6af86552cc9
...
...
ClearML Task: Offline session stored in /home/user/.clearml/cache/offline/b786845decb14eecadf2be24affc7418.zip
```
2021-08-09 08:26:09 +00:00
## Uploading Session Data
2021-07-14 07:36:25 +00:00
Upload the session's execution data that the Task captured offline to the ClearML Server using one of the following:
2021-07-14 07:36:25 +00:00
* `clearml-task` CLI
```bash
clearml-task --import-offline-session "/home/user/.clearml/cache/offline/b786845decb14eecadf2be24affc7418.zip"
```
Pass the path to the zip folder containing the session with the `--import-offline-session` parameter.
2023-04-16 07:13:04 +00:00
* [`Task.import_offline_session`](../references/sdk/task.md#taskimport_offline_session) method.
```python
from clearml import Task
Task.import_offline_session(
session_folder_zip="/home/user/.clearml/cache/offline/b786845decb14eecadf2be24affc7418.zip"
)
```
In the `session_folder_zip` argument, insert the path to the zip folder containing the session.
2023-04-03 07:27:43 +00:00
To upload the session from the same script that created it, first close the task then disable offline mode:
```python
Task.set_offline(offline_mode=True)
task = Task.init(project_name="examples", task_name="my_task")
# task code
task.close()
Task.set_offline(False)
Task.import_offline_session(task.get_offline_mode_folder())
```
2022-06-30 10:51:02 +00:00
You can also use the offline task to update the execution of an existing previously executed task by providing the
2023-10-01 07:31:48 +00:00
previously executed task's ID. To avoid overwriting metrics, you can specify the initial iteration offset with
2022-12-12 12:30:17 +00:00
`iteration_offset`.
2022-06-30 10:51:02 +00:00
```python
Task.import_offline_session(
session_folder_zip="path/to/session/.clearml/cache/offline/b786845decb14eecadf2be24affc7418.zip",
previous_task_id="12345679",
iteration_offset=1500
)
```
Both options will upload the Task's full execution details and outputs and return a link to the Task's results page on
the ClearML Server:
2021-07-14 07:36:25 +00:00
```console
ClearML: Importing offline session from /home/user/.clearml/cache/offline/b786845decb14eecadf2be24affc7418.zip
ClearML results page: https://app.clear.ml/projects/4043a1657f374e9298649c6ba72ad233/experiments/bb8b0f6fa0f94536a0d27fb55f02d3a5/output/log
2021-07-14 07:36:25 +00:00
```
The session details can be viewed in the ClearML WebApp, in the "my_task" experiment of the "examples"
project, as specified when initializing the Task.