Bug: BatchLimiter incorrectly counts samples
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu với phương thức BatchLimiter.iter trong src/saev/utils/scheduling.py và chạy tests/test_batch_limiter.py bằng lệnh pytest được cung cấp. Xác minh các trường hợp batch không đồng đều và kết thúc sớm, sau đó xác nhận rằng limiter không trả về nhiều hơn số lượng sample được yêu cầu trong cả hai kịch bản.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 67
- Fork
- 12
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Imageomics/saev
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Imageomics/saev#30 · 3 bình luận ·
-
performance
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Imageomics/saev#26 · 1 reaction ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 52/100
Imageomics/saev#23 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
Imageomics/saev#11 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Imageomics/saev#10 ·
Tất cả issue của Imageomics/saev
Issue tương tự
-
Claiming namespace `apoint`Đang mởnamespace operations
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
EclipseFdn/open-vsx.org#13573 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
collective/icalendar#1854 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
rancher/rancher-ai-agent#412 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
TUDelftGeodesy/DePSI#134 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
HenriquesLab/rxiv-maker#335 ·