Bug: BatchLimiter incorrectly counts samples
Nessuno ha ancora preso questa issue.
- #18 di @samuelstevens — chiusa senza merge
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 45/100
Direzione di ricerca
Inizia con il metodo BatchLimiter.iter in src/saev/utils/scheduling.py ed esegui tests/test_batch_limiter.py usando il comando pytest fornito. Verifica i casi di batch di dimensioni diverse e di terminazione anticipata, quindi conferma che il limiter non produca più campioni del numero richiesto in entrambi gli scenari.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
The BatchLimiter class in src/saev/utils/scheduling.py incorrectly counts the number of samples seen during iteration, leading to premature termination or overcounting when the actual batch size is smaller than the expected batch size.
Location
src/saev/utils/scheduling.py:114
Root Cause
In the __iter__ method, the code always increments self.n_seen by self.batch_size:
self.n_seen += self.batch_size
if self.n_seen > self.n_samples:
return
However, the actual batch yielded might have fewer samples than self.batch_size, particularly:
- For the last batch when
drop_last=False - For dataloaders with uneven dataset sizes
This causes the limiter to overcount samples, terminating the iterator at the wrong time.
Expected Behavior
The BatchLimiter should count the actual number of samples in each batch, not assume all batches have size self.batch_size.
Actual Behavior
The limiter terminates based on incorrect counts, yielding either too many or too few samples.
Example
If we have:
- A dataloader with 105 samples
batch_size = 32drop_last = Falsen_samples = 100(what we want from BatchLimiter)
The batches would be: [32, 32, 32, 9]
But the counter would be: [32, 64, 96, 128]
When the counter hits 128 > 100, it returns after yielding all 105 samples (not 100).
Reproduction
See the unit tests in tests/test_batch_limiter.py which demonstrate this bug:
uv run --no-dev python -m pytest tests/test_batch_limiter.py -v
Test results:
test_batch_limiter_with_uneven_batches: Expected ≤100 samples, got 105test_batch_limiter_early_termination: Expected 100 samples, got 160
Proposed Fix
Change line 114 to count the actual batch size instead of always using self.batch_size.
See PR for the implementation.
- Lingua principale
- Python
- Stelle
- 67
- Fork
- 12
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Imageomics/saev
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
Imageomics/saev#30 · 3 commenti ·
-
performance
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
Imageomics/saev#26 · 1 reazione ·
-
Incorrect shape assertion in test_decode_prefixes_device_handlingForse già presa @samuelstevens l’ha presa 368 giorni fa. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 52/100
Imageomics/saev#23 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
Imageomics/saev#11 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
Imageomics/saev#10 ·
Tutte le issue di Imageomics/saev
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Graphify-Labs/graphify#4524 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
topoteretes/cognee#5982 ·
I maintainer di solito rispondono entro 1 giorno
-
Patches of derivations with `__structuredAttrs` are ignoredForse già presa @KiaraGrouwstra l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 81/100
nix-community/vulnix#184 ·
-
New InternshipApertanew_internship
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
aws-samples/sample-per-model-bedrock#295 ·
I maintainer di solito rispondono entro 1 giorno