verl icon indicating copy to clipboard operation
verl copied to clipboard

trainer.rollout_data_dir: TypeError: Object of type bool_ is not JSON serializable

Open hustmf opened this issue 10 months ago • 2 comments

System Info

When enabling trainer.rollout_data_dir, error happened in dumping data TypeError: Object of type bool_ is not JSON serializable

Information

  • [ ] The official example scripts
  • [ ] My own modified scripts

Tasks

  • [ ] An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • [ ] My own task or dataset (give details below)

Reproduction

verl main (dcb871f3) sglang v0.5.7

Expected behavior

TypeError: Object of type bool_ is not JSON serializable

hustmf avatar Jan 14 '26 07:01 hustmf

I fixed this and opened PR #5810: https://github.com/verl-project/verl/pull/5810

The fix normalizes numpy-backed rollout metadata before writing rollout_data_dir JSONL entries, so values like numpy.bool_, np.int64, and nested ndarray content no longer fail json.dumps(...).

I also added CPU tests covering both the recursive conversion helper and _dump_generations writing a real JSONL file with numpy metadata.

chenshui223 avatar Mar 30 '26 08:03 chenshui223

中文:这个 issue 中报告的 trainer.rollout_data_dir 写 JSONL 时遇到 numpy.bool_ 无法序列化的问题,当前看起来已经由后续合并的修复覆盖了。

证据:

  • #6062 已合并,并明确说明为 json.dumps 增加 default=str fallback,用于修复 numpy 2.x 下 numpy.bool_ 不再是 Python bool 子类导致的 JSON 序列化崩溃:https://github.com/verl-project/verl/pull/6062
  • #6167 已合并,并在 RayPPOTrainer._log_rollout_data 边界将 numpy-backed reward_extra_infos_dict 转为 native/list 数据,避免 numpy typed values 直接进入 rollout JSON dump:https://github.com/verl-project/verl/pull/6167
  • 当前 verl/trainer/ppo/ray_trainer.py 中,rollout dump 路径已经包含 .tolist() 转换和 json.dumps(..., default=str) fallback。

因此我认为这个 issue 可以按已修复关闭。如果仍然需要保证嵌套 numpy 标量/数组在 JSONL 中保持原生 bool/int/list 类型而不是 fallback 字符串,可以继续在 #5810 跟进更严格的递归转换和测试:https://github.com/verl-project/verl/pull/5810

English: The trainer.rollout_data_dir JSONL dumping failure reported here appears to be covered by later merged fixes.

Evidence:

  • #6062 was merged and explicitly added a default=str fallback to json.dumps for the numpy 2.x numpy.bool_ serialization crash: https://github.com/verl-project/verl/pull/6062
  • #6167 was merged and converts numpy-backed reward_extra_infos_dict values at the RayPPOTrainer._log_rollout_data boundary before rollout JSON dumping: https://github.com/verl-project/verl/pull/6167
  • The current verl/trainer/ppo/ray_trainer.py rollout dump path now contains both the .tolist() boundary conversion and the json.dumps(..., default=str) fallback.

So this issue looks safe to close as fixed. If stricter native-type preservation for nested numpy scalars/arrays is still desired, that can continue in #5810: https://github.com/verl-project/verl/pull/5810

This response was generated by a scheduled Codex GPT5.5 issue processing task.

Kirrito-k423 avatar Jul 30 '26 01:07 Kirrito-k423