Repository navigation
fix: wire WeightedBCELoss into loss_fn dispatch, remove dead gradient-norm losses - #452
Merged
Merged
Conversation
…-norm losses (#443) WeightedBCELoss existed in dicee/losses/custom_losses.py but had no matching branch in BaseKGE.__init__'s loss_fn dispatch, making it unreachable via config. It's self-contained (confidence-weighted BCE, no external state needed) - wire it up as loss_fn="WeightedBCELoss". GradientBasedLSLR and GradientBasedAdaptiveLSLR turned out to be more broken than the issue described: their entire class bodies were wrapped in a triple-quoted string (not importable at all, let alone reachable), they called their inner losses with an extra gradient_norm argument none of LabelSmoothingLoss/LabelRelaxationLoss/AdaptiveLabelSmoothingLoss/ AdaptiveLabelRelaxationLoss accept, GradientBasedAdaptiveLSLR used np.std without importing numpy, and - most fundamentally - nothing anywhere computes or threads a gradient_norm into a loss call (it's a post-backward-pass quantity that training_step never captures). This is a new feature, not a wiring gap, so instead of resurrecting broken dead code: remove it and track the actual design work in #451. Adds regression coverage for WeightedBCELoss (tests/test_unit_base_model.py:: TestWeightedBCELoss), confirmed to fail against the pre-fix code. Fixes #443 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
Fixes #443.
WeightedBCELossexisted indicee/losses/custom_losses.pybut had no matching branch inBaseKGE.__init__'sloss_fndispatch — unreachable via config. It's self-contained (confidence-weighted BCE, no external state), so wiring it up asloss_fn="WeightedBCELoss"was straightforward. Added a short docstring while I was there.GradientBasedLSLR/GradientBasedAdaptiveLSLRturned out to be more broken than WeightedBCELoss, GradientBasedLSLR, GradientBasedAdaptiveLSLR are unreachable via loss_fn #443 described: their whole class bodies were wrapped in a"""..."""string (not importable at all), they called their inner losses with an extragradient_normargument none of them accept,GradientBasedAdaptiveLSLRusednp.stdwithout importingnumpy, and — most fundamentally — nothing anywhere computes or threads agradient_norminto a loss call (it's inherently a post-backward-pass quantityloss_functionnever sees). This is a new feature, not a wiring gap, so I removed the dead code rather than resurrect something that was never functional, and opened Design gradient-norm-based adaptive loss scheduling (GradientBasedLSLR / GradientBasedAdaptiveLSLR) #451 to track the actual design work.Test plan
ruff check dicee/ --line-length=200— cleanmypy dicee/ --config-file=pyproject.toml— underdevelopbaseline (fewer lines to check after the dead-code removal)TestWeightedBCELoss(3 tests) intests/test_unit_base_model.py; confirmed it fails against the pre-fix codetests/test_unit_base_model.py,test_neg_sample_margin.py,test_regression_distmult.py,test_custom_trainer.py— 76 passedloss_fn="WeightedBCELoss"trains DistMult on UMLS successfullyGradientBasedLSLR/GradientBasedAdaptiveLSLRanywhere indicee/ortests/Follow-up