Support distributed eval via --distributed#63
Open
TonyChen06 wants to merge 2 commits into
Open
Conversation
The evaluator generated one turn at a time: for every sample it looped over response ranges and called generate() per turn with batch size 1. Restructure into two phases: flatten_eval_turns expands every (sample, turn) pair into a flat work item (prefix ids, masked signal indices, per-sample encoder outputs, ground truth), then generation runs over chunks of --eval_batch_size turns, left-padded to the chunk max with signal indices shifted per item. Results are reassembled in the original order before the (unchanged) metric computation. --eval_batch_size defaults to 1, which preserves today's behavior exactly: same generate() calls in the same order, verified on a real eval (277 turn pairs, sampling on): 277/277 generations and all metrics identical to main. With batching, greedy decoding at eval_batch_size=4 reproduces 75-77% of eval_batch_size=1 generations exactly (signal and rgb configs, untrained connector); the remainder differ through bfloat16 batched kernels reaching different logit argmaxes on near-ties. Aggregate metrics agree to the third decimal. index_nested now returns the squeezed per-sample entry; its only caller is the new flatten step.
Shard the flattened turn list across ranks (turns[rank::world_size] — an exact partition, so no post-gather deduplication is needed), generate locally, then all_gather_object the results and sort by the original order; every rank computes identical metrics from the full gathered set. The model is unwrapped from DDP for generate(). main_evaluator initializes/destroys the process group when --distributed is passed and gates prints and file writes to rank 0. Single-process behavior is unchanged (world_size == 1 keeps the full turn list and skips the gather).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
evaluate()shards the flattened turn list across ranks withturns[rank::world_size]— an exact partition, so unlike Batched and distributed eval (without full determinism feature) #12'sDistributedSamplerapproach there are no padding duplicates and no dedup step. Each rank generates its shard; results areall_gather_object-ed, sorted back to original order, and every rank computes identical metrics from the full set.generate().main_evaluator.pycallsinit_dist()/cleanup()when--distributedis passed (flag already exists) and gates prints/file writes to rank 0.world_size == 1short-circuits both the shard and the gather).Launch:
torchrun --standalone --nproc_per_node=N src/main_evaluator.py ... --distributedVerification (2× RTX A5000 via torchrun vs the 1-GPU reference, greedy, 277 turn pairs)
Note: this touches the same
main_evaluator.pyregion as #54; whichever merges second has a trivial conflict to resolve.