Skip to content

Commit 8648d4d

Browse files
authored
Add Experience Viewer (#427)
1 parent e95c923 commit 8648d4d

File tree

7 files changed

+476
-20
lines changed

7 files changed

+476
-20
lines changed

docs/sphinx_doc/source/tutorial/develop_workflow.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ During Workflow development, repeatedly launching the full training process for
499499
```{mermaid}
500500
flowchart LR
501501
A[Start Inference Model] --> B[Debug Workflow]
502-
B --> B
502+
B --> C[Check Experiences]
503+
C --> B
503504
```
504505

505506
To start the inference model, use the following command:
@@ -513,14 +514,22 @@ Here, `<config_file_path>` is the path to a YAML configuration file, which shoul
513514
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:
514515

515516
```bash
516-
trinity debug --config <config_file_path> --module workflow --output-dir <output_dir> --plugin-dir <plugin_dir> --enable-profiling
517+
trinity debug --config <config_file_path> --module workflow --output-dir <output_dir> [--plugin-dir <plugin_dir>] [--enable-profiling] [--disable-overwrite]
517518
```
518519

519520
- `<config_file_path>`: Path to the YAML configuration file, usually the same as used for starting the inference model.
520521
- `<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.
521522
- `<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.
522523
- `--enable-profiling` (optional): Enable performance profiling using [viztracer](https://github.com/gaogaotiantian/viztracer).
524+
- `--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.
523525

524-
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.
526+
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.
527+
528+
```bash
529+
trinity debug --config <config_file_path> --module viewer --output-dir <output_dir> --port 8502
530+
```
531+
532+
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.
533+
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.
525534

526535
When debugging is complete, you can terminate the inference model by pressing `Ctrl+C` in its terminal.

docs/sphinx_doc/source_zh/tutorial/develop_workflow.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,8 @@ class MyWorkflow(Workflow):
495495
```{mermaid}
496496
flowchart LR
497497
A[启动推理模型] --> B[调试 Workflow]
498-
B --> B
498+
B --> C[检查 Experience]
499+
C --> B
499500
```
500501

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

511512
```bash
512-
trinity debug --config <config_file_path> --module workflow --output-dir <output_dir> --plugin-dir <plugin_dir> --enable-profiling
513+
trinity debug --config <config_file_path> --module workflow --output-dir <output_dir> [--plugin-dir <plugin_dir>] [--enable-profiling] [--disable-overwrite]
513514
```
514515

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

520-
调试过程中,配置文件中的 `buffer.explorer_input.taskset` 字段会被加载,用于初始化 Workflow 所需的任务数据集和实例。需注意,调试模式仅会读取数据集中的第一条数据进行测试。运行上述命令后,Workflow 的返回值会自动格式化并打印在终端以供观察和查看,同时产出的 Experience 会保存到 `<output_dir>/experiences.db` 数据库中。
522+
调试过程中,配置文件中的 `buffer.explorer_input.taskset` 字段会被加载,用于初始化 Workflow 所需的任务数据集和实例。需注意,调试模式仅会读取数据集中的第一条数据进行测试。运行上述命令后,工作流的返回 Experience 会被写入指定输出目录下的 `experiences.db` 文件中,而运行过程中记录的指标会打印在终端以便检查。
523+
524+
```bash
525+
trinity debug --config <config_file_path> --module viewer --output-dir <output_dir> --port 8502
526+
```
527+
528+
该命令会在 `http://localhost:8502` 启动 Experience Viewer,用于可视化调试过程中生成的 Experience。你可以在用户友好的界面中检查生成的 Experience。需注意,Viewer 会从指定输出目录下的 `experiences.db` 文件中读取 Experience,因此请确保你已成功运行过 Workflow 调试命令,且替换 `<output_dir>` 为实际的输出目录。
521529

522530
调试完成后,可在推理模型终端输入 `Ctrl+C` 以终止模型运行。

tests/cli/launcher_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ def test_debug_mode(self, mock_load):
275275
config="dummy.yaml",
276276
module="workflow",
277277
enable_profiling=True,
278+
disable_overwrite=False,
278279
output_dir=output_dir,
279280
output_file=output_file,
280281
plugin_dir="",
@@ -297,6 +298,26 @@ def test_debug_mode(self, mock_load):
297298
config="dummy.yaml",
298299
module="workflow",
299300
enable_profiling=False,
301+
disable_overwrite=False,
302+
output_dir=output_dir,
303+
output_file=output_file,
304+
plugin_dir="",
305+
),
306+
):
307+
launcher.main()
308+
309+
dirs = os.listdir(self.config.checkpoint_job_dir)
310+
target_output_dir = [d for d in dirs if d.startswith("debug_output_")]
311+
self.assertEqual(len(target_output_dir), 0)
312+
313+
with mock.patch(
314+
"argparse.ArgumentParser.parse_args",
315+
return_value=mock.Mock(
316+
command="debug",
317+
config="dummy.yaml",
318+
module="workflow",
319+
enable_profiling=False,
320+
disable_overwrite=True,
300321
output_dir=output_dir,
301322
output_file=output_file,
302323
plugin_dir="",

0 commit comments

Comments
 (0)