Skip to content

fix(looper): accept calibration inputs without len() (#4192) - #4291

Merged
Qubitium merged 1 commit into
mainfrom
fix/4192-iterable-calibration
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/4192-iterable-calibration

Conversation

@ZX-ModelCloud

Copy link
Copy Markdown
Collaborator

Summary

LoopProcessor.__init__ called len() on the raw calibration dataset before
CalibrationConfig.prepare_dataset ran. prepare_calibration_dataset accepts
datasets.IterableDataset and generic iterables, which do not implement
__len__, so quantize() crashed with:

TypeError: object of type '...' has no len()

Model-specific prepare_dataset overrides (for example Qwen3-VL) also keep
image iterators lazy, so the raw input must not be materialised before
preparation.

Fix

  • Only run the pre-prepare empty/size checks when the input exposes a length.
  • Verify emptiness on the prepared result, which every input type reaches.
  • Materialise an unsized prepared result so per-layer replay, batch accounting
    and token statistics receive a reusable, sized dataset.
  • Keep the short-dataset warning for unsized inputs by checking the prepared
    batch count after preparation.

Tests

Added to tests/test_looper_concurrency.py:

  • Unsized iterable calibration input reaches prepare_dataset untouched.
  • datasets.IterableDataset calibration input is accepted.
  • An unsized prepare_dataset result is materialised.
  • Empty unsized input is still rejected after preparation.

Existing coverage still passes: empty sized input is rejected before
preparation, and an input emptied by preparation reports the post-prepare
error.

Fixes #4192

datasets.IterableDataset and plain generators are documented calibration inputs, but LoopProcessor.__init__ called len() on the raw dataset before prepare_dataset could materialise it, so quantize() crashed with TypeError.

Run the pre-prepare empty/size checks only when the input exposes a length, and verify emptiness on the prepared result instead. Materialise an unsized prepared result so the per-layer replay and batch accounting still get a reusable, sized dataset.
@Qubitium
Qubitium merged commit b7a352f into main Nov 16, 2026
6 of 8 checks passed
@Qubitium
Qubitium deleted the fix/4192-iterable-calibration branch November 16, 2026 07:47
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.

[BUG] quantize() crashes on datasets.IterableDataset / any iterable without len(), although the calibration helper accepts them

2 participants