Feature Request: StratifiedBatchSampler for Guaranteed Subgroup Representation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.8k
- Forks
- 726
- Avg merge
- 5d 21h
- Merged PRs (30d)
- 5
Description
🚀 Feature
When training on datasets with class imbalance, it is critical to have every subgroup represented in every batch. PyTorch's built-in WeightedRandomSampler allows us to assign weights to each subgroup but still relies on random chance, meaning it does not strictly guarantee that rare classes will appear in a specific batch.
For algorithms like Group Distributionally Robust Optimization (DRO) or Contrastive Learning, this is critical since if a group is not represented in a batch, the loss component can potentially become zero and can destabilize training.
If this makes sense, we also have to take care of this question:
- Discarding or Oversampling:
StratifiedBatchSamplercan either oversample the group with the least datapoints or it can create the total number of batches such that it exhausts the subgroup with the least amount of datapoints, which leads to wastage of datapoints of highly-represented classes. We should discuss whether we want to keep both options or not, and which option would act as the default then.
I already have a working prototype of this from a recent project and can modify it for this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository files, tests, or entry points are named. Start by locating Ignite's existing data-loading and sampler APIs, then review the prototype and the oversampling-versus-discarding question. Done means agreeing on the API and default behavior, implementing guaranteed subgroup representation, and adding coverage for both supported sampling choices.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data, machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100