Bug: BatchLimiter incorrectly counts samples
まだ誰も着手していません。
- #18 @samuelstevens による — マージされずにクローズ
評価
調査の方向性
src/saev/utils/scheduling.py の BatchLimiter.iter メソッドから始め、提供された pytest コマンドを使って tests/test_batch_limiter.py を実行します。サイズの異なるバッチと早期終了のケースを検証し、その後、どちらのシナリオでも limiter が要求された数を超えるサンプルを生成しないことを確認します。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 67
- フォーク
- 12
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Imageomics/saev のほかの issue
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
Imageomics/saev#30 · コメント 3 件 ·
-
performance
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
Imageomics/saev#26 · リアクション 1 件 ·
-
Incorrect shape assertion in test_decode_prefixes_device_handling対応中かも @samuelstevens が 379 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 52/100
Imageomics/saev#23 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
Imageomics/saev#11 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
Imageomics/saev#10 ·
Imageomics/saev の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
[oblt-aw][autodoc] Document obs-aw-automerge contract and fix automerge doc inconsistencies対応中かも @github-actions が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
admission-deferred priority: medium status: ready work-class: scoped
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
melodic-software/claude-code-plugins#10887 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
backend bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
PoCInnovation/Distribox#255 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
google/langextract#598 ·
メンテナーはふだん 1 日以内に返信