Refactor NRE loss logic to Strategy Pattern (Phase 2 of #1241)#1826
Open
Sumit6307 wants to merge 6 commits intosbi-dev:mainfrom
Open
Refactor NRE loss logic to Strategy Pattern (Phase 2 of #1241)#1826Sumit6307 wants to merge 6 commits intosbi-dev:mainfrom
Sumit6307 wants to merge 6 commits intosbi-dev:mainfrom
Conversation
Author
❌ 15 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
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
Building exactly on the maintainers' feedback and unified vision established in Phase 1 (NPE-C refactoring PR #1755), this PR executes Phase 2: fully extracting the NRE loss calculations (NRE_A, NRE_B, NRE_C, and BNRE) into composable, isolated strategies that conform to an NRELossStrategy Protocol.
By outsourcing AALRLoss, SRELoss, CNRELoss, and BNRELoss mathematically intensive routines to nre_loss.py, we entirely eliminate _loss() and _classifier_logits() from RatioEstimatorTrainer and its subclasses, creating a fully modular Ratio Estimation architecture.
Motivation
Presently, each NRE variant embeds complex classification and contrastive atom-generation logic tightly inside its respective _loss overridden method. As outlined in Option (a) of #1241, trainers should only orchestrate the training loop, while composable protocol-compliant Objects handle mathematical formulations.
Key Changes
NRE_A._loss)NRE_B._loss)NRE_C._loss)BNRE._loss)_loss_strategy: Optional[NRELossStrategy]inside _get_losses.Checklist
ruff checkformatting verified.