Skip to content

feat: multi-turn search R1 example #914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

soodoshll
Copy link
Contributor

What does this PR do ?

Address #657

Issues

List issues that this PR closes (syntax):

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the unit tests and functional tests locally? Visit our Testing Guide for how to run tests
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

Additional Information

  • ...

@github-actions github-actions bot added documentation Improvements or additions to documentation CI Relating to CI labels Aug 13, 2025
@soodoshll soodoshll marked this pull request as draft August 13, 2025 17:38
@github-actions github-actions bot removed documentation Improvements or additions to documentation CI Relating to CI labels Aug 13, 2025
@soodoshll soodoshll marked this pull request as ready for review August 13, 2025 18:32
@soodoshll soodoshll requested a review from wangshangsam August 13, 2025 18:32
Copy link
Contributor

@wangshangsam wangshangsam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a feeling that the retrieval server needs to be moved into nemo_rl/environments/search/, cuz SearchEnv seems to be coupled with this particular retrival server with its particular (HTTP) API design.


```bash
uv pip install -U cmake
git clone https://github.com/facebookresearch/faiss.git thirdparty/faiss
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the existing convention, it might make sense to make faiss a submodule of this repo.


The following instructions install Faiss-GPU from source. Please refer to [this](https://github.com/facebookresearch/faiss/blob/main/INSTALL.md) for more details.

```bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, it seems there are enough shell commands in here to automate them into a script.

Comment on lines 46 to 48
```
local_dir=./data/searchR1
uv run --active python searchr1_download.py --local_dir $local_dir
cat $local_dir/part_* > $local_dir/e5_Flat.index
gzip -d $local_dir/wiki-18.jsonl.gz
uv run --active python searchr1_dataset.py --local_dir $local_dir
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intend to replace this with bash prepare.sh?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, fixed.

Comment on lines +1 to +9
numpy==1.26.4
transformers
datasets
pyserini
huggingface_hub
# faiss-gpu-cu12
uvicorn
fastapi
torch==2.6.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
numpy==1.26.4
transformers
datasets
pyserini
huggingface_hub
# faiss-gpu-cu12
uvicorn
fastapi
torch==2.6.0
pyserini
huggingface_hub
# faiss-gpu-cu12
uvicorn
fastapi

Only include dependencies that are not already presented in pyproject.toml

return corpus


def read_jsonl(file_path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you annonate the types and add docstrings for all the functions in this file?

tokenizer: TokenizerType,
max_seq_length: int,
idx: int,
) -> DatumSpec:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add docstrings to the functions in this file.

# See the License for the specific language governing permissions and
# limitations under the License.

# Adapted from https://github.com/NovaSky-AI/SkyRL/blob/main/skyrl-train/examples/search/searchr1_dataset.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This is just a side note; no need to address anything)

Both files are from NovaSky-AI/SkyRL, but somehow this one has noticeably better coding style than examples/searchR1/retrieval_server.py

INITIAL_RETRY_DELAY = 1


class SearchEnvConfig(TypedDict):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add docstring for all classes and functions/methods in this file.

answer: Optional[str]


def call_search_api(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def call_search_api(
def _call_search_api(

This seems more like an internal helper function to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed



@ray.remote
class SearchEnv(EnvironmentInterface[SearchEnvMetadata]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add unit test for this. I'm suspecting that it's not gonna be easy to actually bring up a 2-GPU retrival server for unit tests, hence you might need to mock requests.session for unit testing this.

@euronymous-aithal
Copy link

@soodoshll will you be able to address comments ASAP

@wangshangsam
Copy link
Contributor

@soodoshll will you be able to address comments ASAP

@soodoshll is currently working on #883 which, as I understand, has a much higher priority over this Search-R1 example (i.e., a nice-to-have). If the priority should be the reverse, we can adapt accordingly.

@soodoshll
Copy link
Contributor Author

I have a feeling that the retrieval server needs to be moved into nemo_rl/environments/search/, cuz SearchEnv seems to be coupled with this particular retrival server with its particular (HTTP) API design.

A general issue is that the retrieval server might run in an environment (quite) different from the nemo-rl env. For example, faiss depends on numpy 1.x

soodoshll and others added 3 commits August 20, 2025 07:43
Signed-off-by: Qidong Su <[email protected]>

update

Signed-off-by: Qidong Su <[email protected]>

upd

Signed-off-by: Qidong Su <[email protected]>

stash

Signed-off-by: Qidong Su <[email protected]>

fix many things

Signed-off-by: Qidong Su <[email protected]>

stash

Signed-off-by: Qidong Su <[email protected]>

clean

Signed-off-by: Qidong Su <[email protected]>

clean

Signed-off-by: Qidong Su <[email protected]>

update copyright

Signed-off-by: Qidong Su <[email protected]>

update copyright

Signed-off-by: Qidong Su <[email protected]>

clean

fix

Signed-off-by: Qidong Su <[email protected]>

fix

Signed-off-by: Qidong Su <[email protected]>

fix

Signed-off-by: Qidong Su <[email protected]>
Signed-off-by: Qidong Su <[email protected]>
Signed-off-by: Qidong Su <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants