Skip to content

feat(hslm): OHEM — online hard example mining for fast convergence#564

Merged
gHashTag merged 1 commit into
mainfrom
feat/318-ohem-hard-example-mining
Apr 30, 2026
Merged

feat(hslm): OHEM — online hard example mining for fast convergence#564
gHashTag merged 1 commit into
mainfrom
feat/318-ohem-hard-example-mining

Conversation

@gHashTag

Copy link
Copy Markdown
Owner

Summary

Online Hard Example Mining (OHEM) for faster training convergence.

New file

  • src/b2t/ohem.zig — 186 LOC

How it works

  • Per-example loss ranking
  • Keep top hard_ratio (default 70%) hardest examples
  • Discard easy examples that contribute little gradient signal
  • Result: faster convergence by focusing optimization on informative samples

Features

  • OhemMiner: sort by loss, select hardest fraction
  • OhemConfig: hard_ratio, min_keep, loss_threshold
  • LossStats: mean, max, min, variance, above-mean count
  • Configurable keep ratio with safety floor (min_keep)

Tests (5)

  • Selects hardest examples (sorted by loss)
  • Respects min_keep floor
  • Handles empty input
  • Equal losses: any subset valid
  • Loss stats computation

Closes #318

- Add src/b2t/ohem.zig
- OhemMiner: select top-K% hardest examples by loss
- Sort by loss descending, keep hard_ratio fraction
- Configurable: hard_ratio (0.7), min_keep, loss_threshold
- LossStats: mean, max, min, variance, above-mean count
- 5 tests: hardest selection, min_keep, empty input,
  equal losses, loss stats

Closes #318
@gHashTag gHashTag merged commit 27a045b into main Apr 30, 2026
9 of 19 checks passed
@gHashTag gHashTag deleted the feat/318-ohem-hard-example-mining branch April 30, 2026 00:49
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.

feat(hslm): OHEM — online hard example mining for fast convergence

1 participant