Skip to content

fix: wire WeightedBCELoss into loss_fn dispatch, remove dead gradient-norm losses - #452

Merged
Demirrr merged 1 commit into
developfrom
fix/wire-weighted-bce-loss
Sep 16, 2026
Merged

Demirrr merged 1 commit into
developfrom
fix/wire-weighted-bce-loss

Conversation

@Demirrr

@Demirrr Demirrr commented Sep 15, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #443.

  • WeightedBCELoss existed in dicee/losses/custom_losses.py but had no matching branch in BaseKGE.__init__'s loss_fn dispatch — unreachable via config. It's self-contained (confidence-weighted BCE, no external state), so wiring it up as loss_fn="WeightedBCELoss" was straightforward. Added a short docstring while I was there.
  • GradientBasedLSLR/GradientBasedAdaptiveLSLR turned 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 extra gradient_norm argument none of them 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 inherently a post-backward-pass quantity loss_function never 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 — clean
  • mypy dicee/ --config-file=pyproject.toml — under develop baseline (fewer lines to check after the dead-code removal)
  • Added TestWeightedBCELoss (3 tests) in tests/test_unit_base_model.py; confirmed it fails against the pre-fix code
  • Ran tests/test_unit_base_model.py, test_neg_sample_margin.py, test_regression_distmult.py, test_custom_trainer.py — 76 passed
  • Manual end-to-end: loss_fn="WeightedBCELoss" trains DistMult on UMLS successfully
  • Confirmed no remaining references to GradientBasedLSLR/GradientBasedAdaptiveLSLR anywhere in dicee/ or tests/

Follow-up

…-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>
@Demirrr
Demirrr merged commit 8b394b3 into develop Sep 16, 2026
7 checks passed
@Demirrr
Demirrr deleted the fix/wire-weighted-bce-loss branch September 16, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WeightedBCELoss, GradientBasedLSLR, GradientBasedAdaptiveLSLR are unreachable via loss_fn

1 participant