RL icon indicating copy to clipboard operation
RL copied to clipboard

feat: Multi-turn tool calling on BFCLv3 dataset

Open slikhite-1 opened this issue 1 year ago • 2 comments

This PR implements an end-to-end example for training a model on multi-turn tool calling using GRPO with the BFCLv3 dataset. The example leverages preprocessed data uploaded to HuggingFace, where preprocessing includes adding tool descriptions and formatting. It also provides evaluation scripts to compare trained and untrained models, along with a README that documents the example in detail, and results on Qwen 2.5 3B

Summary by CodeRabbit

  • New Features
    • Introduced multi-turn tool-calling environment with reward-based rollouts.
    • Added support for BFCL v3 multi-turn datasets for training and evaluation.
    • Provided new built-in tools (filesystem, math, messaging, ticketing, trading, social, vehicle control).
    • Enabled multi-turn evaluation and GRPO training via new scripts and configs.
    • Improved logging with serialized environment metadata.
  • Documentation
    • Added a comprehensive guide for multi-turn tool calling; linked from the guides index.
  • Chores
    • Included a new dependency for JSON Lines data processing.

slikhite-1 avatar Sep 25 '25 19:09 slikhite-1

📝 Walkthrough

Walkthrough

Adds BFCL v3 multi-turn tool-calling capability: new environment, tool APIs, datasets, processors, configs, training and eval scripts. Extends rollout/eval control flow for multi-turn episodes, adds logging of env metadata, and updates distributed registry. Includes documentation and dependency addition.

Changes

Cohort / File(s) Summary
Documentation
docs/guides/multi_turn_bfcl.md, docs/index.md
New guide for multi-turn tool calling with BFCL v3; index updated to link the guide.
Configs: GRPO and Eval
examples/configs/grpo_bfclv3.yaml, examples/configs/evals/bfcl_eval.yaml, examples/configs/evals/eval.yaml
New GRPO BFCLv3 training config and BFCL eval config; minor no-op edit to base eval config.
Run scripts
examples/run_grpo_bfclv3.py, examples/run_eval.py
New GRPO training script for BFCL multiturn; eval script now conditionally uses MultiTurnToolEnvironment and passes tokenizer; function signatures updated accordingly.
Algorithms: GRPO logging
nemo_rl/algorithms/grpo.py
Adds JSON serialization of per-sample extra_env_info into log_data.metadata.
Eval flow
nemo_rl/evals/eval.py
Adds multi-turn evaluation branch, tokenizer plumbing, rollout integration, and data collection for rewards and logs.
Rollouts
nemo_rl/experience/rollouts.py
Adds BFCL helper to append next user question during multi-turn rollouts; integrates into continuation path.
Distributed registry
nemo_rl/distributed/ray_actor_environment_registry.py
Registers MultiTurnToolEnvironment to system Python executable.
Environment: Multi-turn tools
nemo_rl/environments/multi_turn_tool_environment.py
New multi-turn tool environment with turn parsing, tool execution, rewards, and Ray actor support.
Tool APIs
nemo_rl/environments/tools/gorilla_file_system.py, .../math_api.py, .../message_api.py, .../ticket_api.py, .../trading_bot.py, .../twitter_api.py, .../vehicle_control.py
Adds multiple simulated tool APIs with stateful operations; vehicle_control.py updates method return signatures to structured dicts.
Datasets: Eval
nemo_rl/data/datasets/eval_datasets/__init__.py, .../bfclv3.py
Adds BFCLDataset and wiring for eval dataset loading from HF Hub.
Datasets: Response
nemo_rl/data/datasets/response_datasets/__init__.py, .../bfcl_multiturn.py
Adds BFCLMultiturnDataset loading train/val JSONL from HF Hub with formatted output.
Processors
nemo_rl/data/processors.py
Adds BFCL single-turn and multi-turn processors with chat templating, tokenization, and env metadata passthrough.
Data config
nemo_rl/data/__init__.py
Adds optional filter_long_samples to DataConfig.
Project dependencies
pyproject.toml
Adds jsonlines dependency.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant User
  participant RunScript as run_grpo_bfclv3.py
  participant Ray as Ray Cluster
  participant Policy as GRPO Policy
  participant Env as MultiTurnToolEnvironment
  participant Tools as ToolManager/APIs

  User->>RunScript: Launch with grpo_bfclv3.yaml
  RunScript->>Ray: init()
  RunScript->>Policy: setup(model, tokenizer, gen_cfg)
  RunScript->>Env: create actors (bfcl_multiturn, max_turns)
  loop Training Steps
    Policy->>Env: rollout request (batch)
    Env->>Tools: load scenario (model/GT instances)
    loop per turn (<= max_turns)
      Policy->>Env: assistant response
      Env->>Env: parse <tool> call, validate
      Env->>Tools: execute model and GT calls
      Env-->>Policy: observation, reward fragment, metadata
      Policy->>Policy: GRPO update (rewards, baseline)
    end
    Policy->>RunScript: log rewards + metadata (JSON)
  end
sequenceDiagram
  autonumber
  participant User
  participant EvalScript as run_eval.py
  participant Loader as load_response_dataset
  participant Dataloader
  participant VLLM as vLLM Generation
  participant Env as MultiTurnToolEnvironment

  User->>EvalScript: Run with bfcl_eval.yaml
  EvalScript->>Loader: load_response_dataset("bfcl_multiturn")
  Loader-->>EvalScript: dataset (train/val)
  EvalScript->>Env: create if bfcl_multiturn.enable
  EvalScript->>Dataloader: build with tokenizer
  alt Multi-turn enabled
    loop Batches
      EvalScript->>VLLM: generate turns (rollout)
      VLLM-->>Env: assistant messages
      Env-->>EvalScript: rewards, logs, extra_env_info
    end
  else Single-turn
    EvalScript->>VLLM: generate once
  end
  EvalScript-->>User: prompts, responses, rewards

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120+ minutes

Possibly related PRs

  • NVIDIA-NeMo/RL#977 — Refactors dataset loading and updates imports/signatures; overlaps with added BFCL datasets and changed eval/run script signatures here.

Suggested labels

documentation, r0.4.0

Suggested reviewers

  • odelalleau
  • ashors1

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Test Results For Major Changes ⚠️ Warning The PR introduces a large new feature set, including multi-turn tool environments, datasets, processors, and training scripts, which clearly qualifies as a major change. However, neither the PR description nor the linked documentation provide concrete testing or evaluation results—there are no logs, metrics summaries, or performance comparisons demonstrating successful runs or guarding against regressions. Because the required testing information is missing for such a substantial update, the custom check fails. Please update the PR description with the relevant validation details, such as commands executed, logs, metrics, or evaluation results (especially any convergence or performance figures), so reviewers can confirm the new functionality has been tested. Once those results are documented, this check can pass.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Title Check ✅ Passed The title succinctly captures the core feature addition by indicating support for multi-turn tool calling on the BFCLv3 dataset, matching the pull request’s primary objective. It is concise, descriptive, and free of extraneous details or vague terminology. The use of the “feat:” prefix follows conventional commit style without introducing noise. Team members scanning the history will immediately understand the main enhancement delivered by this changeset.
✨ Finishing touches
  • [ ] 📝 Generate Docstrings
🧪 Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Sep 25 '25 19:09 coderabbitai[bot]

Thank you for your hard work on this. I really appreciate the effort you put into it. Would you please put some more test result in PR docs?

RayenTian avatar Oct 11 '25 03:10 RayenTian