Skip to content

Conversation

@finbarrtimbers
Copy link
Collaborator

@finbarrtimbers finbarrtimbers commented Nov 18, 2025

Summary

  • remove the conflicting data validation from PendingQueriesMap and switch the reference counter to an in-place increment so callers can manage their own data guarantees

Testing

  • uv run pytest open_instruct/test_grpo_fast.py -k pending_queries_map (fails: unable to download torch wheel from download.pytorch.org)

Codex Task


Note

Reworks PendingQueriesMap to store a single data dict with reference counting and updates all call sites and tests to use the new insert/pop contract.

  • Core refactor:
    • PendingQueriesMap now stores dataset_idx -> [data: dict, count], with typed methods insert(dataset_idx, data) and pop(dataset_idx) -> data returning copies; in-place refcount increments/decrements with thread-safe locking.
    • Removed tuple-based (query, ground_truth, dataset, raw_query) handling; all consumers now access fields from returned data.
  • Pipeline updates:
    • accumulate_inference_batches and reward prep now use pending_data[...] for k_queries, k_ground_truths, k_datasets, k_raw_queries.
    • data_preparation_thread signature typed to PendingQueriesMap.
    • add_prompt_to_generator inserts a structured data dict and passes raw prompt to PromptRequest.
  • Tests:
    • Added create_pending_data helper.
    • Updated all usages to new PendingQueriesMap.insert/pop API, including multi-sample/refcount and concurrency tests.
    • Adjusted streaming and accumulation tests to assert using dict fields and updated queue handling.

Written by Cursor Bugbot for commit 992131b. This will update automatically on new commits. Configure here.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @finbarrtimbers, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request streamlines the PendingQueriesMap class by centralizing query data into a dictionary and implementing in-place reference counting. These changes simplify the class's API, making it more robust and easier to manage by reducing argument complexity and ensuring data consistency. The update also includes corresponding adjustments in related functions and test cases to align with the new data handling approach.

Highlights

  • PendingQueriesMap Data Structure: The internal storage of PendingQueriesMap has been refactored to store query-related data as a single dictionary alongside the reference count, improving data encapsulation.
  • In-place Reference Counting: The reference counter for pending queries now uses an in-place increment/decrement mechanism, simplifying the logic for managing multiple references to the same query.
  • Simplified API for insert and pop: The insert and pop methods of PendingQueriesMap now operate with a single data dictionary, reducing the number of arguments and making the interface cleaner.
  • Improved Type Hinting: The type hint for the pending_queries_map parameter in data_preparation_thread has been corrected to PendingQueriesMap, enhancing code clarity and maintainability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request simplifies the PendingQueriesMap by using a dictionary to store data and an in-place increment for the reference counter, which is a good improvement for efficiency and flexibility. The changes are consistently applied across the codebase, including the tests. My main feedback is a suggestion to further improve the maintainability of PendingQueriesMap by using a dataclass instead of a list[Any] to store pending query data, which would make the code more readable and type-safe.

def __init__(self):
self._map = {} # dataset_idx -> (query, ground_truth, dataset, count)
# dataset_idx -> [data, count]
self._map: dict[int, list[Any]] = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using list[Any] to store [data, count] can be a bit ambiguous and relies on magic-number indexing (e.g., [1] for the count). For better code clarity and type safety, consider using a dataclass to structure this data. A PendingItem dataclass with data and count attributes would make the code more self-documenting and accesses more explicit (e.g., self._map[dataset_idx].count += 1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants