fix: post token tracking nits (follow up on #392) - #429
Merged
Conversation
Signed-off-by: Sean Yang <seayang@nvidia.com>
Signed-off-by: Sean Yang <seayang@nvidia.com>
Signed-off-by: Sean Yang <seayang@nvidia.com>
Signed-off-by: seayang <seayang@nvidia.com> Signed-off-by: Sean Yang <seayang@nvidia.com>
Signed-off-by: Sean Yang <seayang@nvidia.com>
Signed-off-by: Sean Yang <seayang@nvidia.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Signed-off-by: seayang-nv <seayang@nvidia.com>
Signed-off-by: Sean Yang <seayang@nvidia.com>
Signed-off-by: Sean Yang <seayang@nvidia.com>
Signed-off-by: Sean Yang <seayang@nvidia.com> # Conflicts: # src/nemo_safe_synthesizer/data_processing/record_utils.py # src/nemo_safe_synthesizer/generation/batch.py # src/nemo_safe_synthesizer/generation/processors.py # src/nemo_safe_synthesizer/results.py
seayang-nv
marked this pull request as ready for review
April 22, 2026 17:53
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Follow-up cleanup PR that refactors recently introduced token-tracking and parsed-record codepaths for readability and minor efficiency improvements, without changing intended behavior (per PR description and review of the diffs).
Changes:
- Refactors
make_nss_summaryto populateSafeSynthesizerSummaryvia field lists/dicts instead of repetitive local wiring. - Avoids redundant scanning of batch responses when computing non-record token totals and warning context.
- Extracts a shared helper for “valid parsed dicts” in grouped processing and updates
ParsedResponsedocstring to reflect current usage.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/nemo_safe_synthesizer/results.py |
Collapses repetitive summary-field forwarding into _GENERATE_RESULT_FIELDS + _REPORT_SCORE_FIELDS driven dict construction. |
src/nemo_safe_synthesizer/generation/batch.py |
Introduces _record_token_totals() to reuse a single scan of responses for token aggregations (notably for total_non_record_tokens). |
src/nemo_safe_synthesizer/generation/processors.py |
Extracts _valid_parsed() helper to remove duplicated comprehensions in grouped record validation logic. |
src/nemo_safe_synthesizer/data_processing/record_utils.py |
Updates ParsedResponse docstring to describe valid_records/invalid_records/errors as primary convenience views. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
kendrickb-nvidia
approved these changes
Apr 27, 2026
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.
Summary
Addresses the four nit suggestions @binaryaaron left on #392 after the main token-tracking refactor was merged. No behavior change — all four are cleanups / readability improvements around code introduced in that PR.
Closes #426.
Changes
1.
results.py— collapse repetitive token-field wiringReplaced the 13-line block of
num_valid_records = None,if isinstance(results, GenerateJobResults): num_valid_records = results.num_valid_records, ...,SafeSynthesizerSummary(num_valid_records=num_valid_records, ...)with:_GENERATE_RESULT_FIELDStuple — names that pass through verbatim fromGenerateJobResultstoSafeSynthesizerSummary._REPORT_SCORE_FIELDSdict —{summary_field: report_score_name}for report-derived scores.make_nss_summarynow does a singlegetattrloop for the gen fields, computesvalid_record_token_fractioninline, projects report scores (orNone) via a dict comprehension, and**-unpacks both into oneSafeSynthesizerSummary(...)call. ~45 lines gone.2.
batch.py— single-pass token aggregationAdded a private
_record_token_totals() -> (valid, invalid)that walksself._responsesexactly once. The three token properties all share it:total_valid_record_tokens/total_invalid_record_tokensdestructure one side.total_non_record_tokensgets both and reuses them for the clamped-to-zero warning context (so theextra={}payload no longer re-triggers the scan).3.
processors.py— extract_valid_parsedhelperThe comprehension
[r.parsed for r in group_records if r.is_valid and r.parsed is not None]appeared twice insideGroupedDataProcessor._process_text_generation(non-unique-groupby check and order_by check). Hoisted into a module-level helper with a docstring explaining theis not Nonenarrows the type for static analysis (valid records always carryparsed).4.
record_utils.py— reframeParsedResponsedocstringDropped the "backward compatibility with callers that want the old parallel-list shape" framing. The doc now describes
valid_records/invalid_records/errorsas convenience views that projectrecordsinto the shapes expected by downstream aggregation code (parsed dicts / original text /(msg, validator)tuples).Pre-Review Checklist
Ensure that the following pass:
make format && make checkor via prek validation.make testpasses locallymake test-e2epasses locallymake test-ci-containerpasses locally (recommended)/syncon this PR to trigger a run (auto-triggers on ready-for-review)Pre-Merge Checklist
Other Notes