Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions docs/sphinx_doc/source/tutorial/develop_workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ During Workflow development, repeatedly launching the full training process for
```{mermaid}
flowchart LR
A[Start Inference Model] --> B[Debug Workflow]
B --> B
B --> C[Check Experiences]
C --> B
```

To start the inference model, use the following command:
Expand All @@ -513,14 +514,22 @@ Here, `<config_file_path>` is the path to a YAML configuration file, which shoul
Once started, the model will keep running and wait for debug instructions; it will not exit automatically. You can then run the following command in another terminal to debug your workflow:

```bash
trinity debug --config <config_file_path> --module workflow --output-dir <output_dir> --plugin-dir <plugin_dir> --enable-profiling
trinity debug --config <config_file_path> --module workflow --output-dir <output_dir> [--plugin-dir <plugin_dir>] [--enable-profiling] [--disable-overwrite]
```

- `<config_file_path>`: Path to the YAML configuration file, usually the same as used for starting the inference model.
- `<output_dir>`: Directory to save the debug output. If not specified, the output will be saved to the `debug_output` in the current working directory.
- `<plugin_dir>` (optional): Path to the plugin directory. If your workflow or reward function modules are not built into Trinity-RFT, you can specify this parameter to load custom modules.
- `--enable-profiling` (optional): Enable performance profiling using [viztracer](https://github.com/gaogaotiantian/viztracer).
- `--disable-overwrite` (optional): Disable overwriting the output directory. If the directory is not empty, it will automatically change to a new directory with a timestamp suffix (e.g., `debug_output_20251203211200`) to avoid overwriting existing data.

During debugging, the `buffer.explorer_input.taskset` field in the config will be loaded to initialize the workflow's required task dataset and instance. Note that Debug Mode only reads the first sample in the dataset for testing. After running the above command, the workflow's return value will be automatically formatted and printed in the terminal for easy inspection and the output experiences will be saved to the `<output_dir>/experiences.db` file.
During debugging, the `buffer.explorer_input.taskset` field in the config will be loaded to initialize the workflow's required task dataset and instance. Note that Debug Mode only reads the first sample in the dataset for testing. After running the above command, the workflow's return experiences will be written to the `experiences.db` file in the specified output directory. Additionally, the metrics will be printed in the terminal for easy inspection.

```bash
trinity debug --config <config_file_path> --module viewer --output-dir <output_dir> --port 8502
```

This command launches the Experience Viewer at `http://localhost:8502` to visualize the experiences generated during debugging. You can inspect the generated experiences in a user-friendly interface.
Note that the viewer reads experiences from the `experiences.db` file in the specified output directory, so ensure that you have successfully run the workflow debug command beforehand and use the same output directory.

When debugging is complete, you can terminate the inference model by pressing `Ctrl+C` in its terminal.
14 changes: 11 additions & 3 deletions docs/sphinx_doc/source_zh/tutorial/develop_workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ class MyWorkflow(Workflow):
```{mermaid}
flowchart LR
A[启动推理模型] --> B[调试 Workflow]
B --> B
B --> C[检查 Experience]
C --> B
```

启动推理模型的命令如下:
Expand All @@ -509,14 +510,21 @@ trinity debug --config <config_file_path> --module inference_model
模型启动后会持续运行并等待调试指令,不会自动退出。此时,你可在另一个终端执行如下命令进行 Workflow 调试:

```bash
trinity debug --config <config_file_path> --module workflow --output-dir <output_dir> --plugin-dir <plugin_dir> --enable-profiling
trinity debug --config <config_file_path> --module workflow --output-dir <output_dir> [--plugin-dir <plugin_dir>] [--enable-profiling] [--disable-overwrite]
```

- `<config_file_path>`:YAML 配置文件路径,通常与启动推理模型时使用的配置文件相同。
- `<output_dir>`:调试输出保存目录。如果未指定,调试输出将保存在当前工作目录下的 `debug_output` 目录中。
- `<plugin_dir>`(可选):插件目录路径。如果你的 Workflow 或奖励函数等模块未内置于 Trinity-RFT,可通过该参数加载自定义模块。
- `--enable-profiling`(可选):启用性能分析,使用 [viztracer](https://github.com/gaogaotiantian/viztracer) 对 Workflow 运行过程进行性能分析。
- `--disable-overwrite`(可选):禁用输出目录覆盖功能。如果指定的文件夹非空,程序将自动创建一个带有时间戳后缀的新目录(例如 `debug_output_20251203211200`)以避免覆盖现有数据。

调试过程中,配置文件中的 `buffer.explorer_input.taskset` 字段会被加载,用于初始化 Workflow 所需的任务数据集和实例。需注意,调试模式仅会读取数据集中的第一条数据进行测试。运行上述命令后,Workflow 的返回值会自动格式化并打印在终端以供观察和查看,同时产出的 Experience 会保存到 `<output_dir>/experiences.db` 数据库中。
调试过程中,配置文件中的 `buffer.explorer_input.taskset` 字段会被加载,用于初始化 Workflow 所需的任务数据集和实例。需注意,调试模式仅会读取数据集中的第一条数据进行测试。运行上述命令后,工作流的返回 Experience 会被写入指定输出目录下的 `experiences.db` 文件中,而运行过程中记录的指标会打印在终端以便检查。

```bash
trinity debug --config <config_file_path> --module viewer --output-dir <output_dir> --port 8502
```

该命令会在 `http://localhost:8502` 启动 Experience Viewer,用于可视化调试过程中生成的 Experience。你可以在用户友好的界面中检查生成的 Experience。需注意,Viewer 会从指定输出目录下的 `experiences.db` 文件中读取 Experience,因此请确保你已成功运行过 Workflow 调试命令,且替换 `<output_dir>` 为实际的输出目录。

调试完成后,可在推理模型终端输入 `Ctrl+C` 以终止模型运行。
21 changes: 21 additions & 0 deletions tests/cli/launcher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def test_debug_mode(self, mock_load):
config="dummy.yaml",
module="workflow",
enable_profiling=True,
disable_overwrite=False,
output_dir=output_dir,
output_file=output_file,
plugin_dir="",
Expand All @@ -297,6 +298,26 @@ def test_debug_mode(self, mock_load):
config="dummy.yaml",
module="workflow",
enable_profiling=False,
disable_overwrite=False,
output_dir=output_dir,
output_file=output_file,
plugin_dir="",
),
):
launcher.main()

dirs = os.listdir(self.config.checkpoint_job_dir)
target_output_dir = [d for d in dirs if d.startswith("debug_output_")]
self.assertEqual(len(target_output_dir), 0)

with mock.patch(
"argparse.ArgumentParser.parse_args",
return_value=mock.Mock(
command="debug",
config="dummy.yaml",
module="workflow",
enable_profiling=False,
disable_overwrite=True,
output_dir=output_dir,
output_file=output_file,
plugin_dir="",
Expand Down
Loading