Skip to content

bug(python): StreamingDataset state_dict is stale with multi-process DataLoader workers #3967

Closed

Description

@AyushExel

LanceDB version

No response

What happened?

Problem

When StreamingDataset uses a PyTorch DataLoader with num_workers > 0, iteration advances private dataset copies in worker processes. Calling state_dict() on the parent dataset therefore returns stale resume state.

Reproduction

dataset = StreamingDataset(table, num_splits=2, shuffle=False)
loader = DataLoader(
    dataset,
    batch_size=2,
    num_workers=2,
    multiprocessing_context="spawn",
)

seen = next(iter(loader))["id"].tolist()
checkpoint = dataset.state_dict()

resumed = StreamingDataset(table, num_splits=2, shuffle=False)
resumed.load_state_dict(checkpoint)
remaining = [row["id"] for row in resumed]

With rows [1, 2, 10, 20], the observed values are:

seen: [1, 2]
samples_consumed_per_split: [0, 0]
remaining: [1, 10, 2, 20]

Rows 1 and 2 are replayed because the parent checkpoint was not updated.

Full-epoch restart is unaffected because the trainer starts a fresh dataset  with the next epoch; no within-epoch worker position is required.

Sharing producer progress directly is insufficient because DataLoader prefetch can advance workers beyond the batches the trainer has consumed.

### Desired behavior

Support consumer-committed worker checkpoint state so state_dict() reflects
the last batch consumed by the trainer.

Until then, exact mid-epoch checkpoints require num_workers=0.


### Are there known steps to reproduce?

_No response_

Activity

  1. added
    bug
    on Aug 19, 2026
  2. sarwarbhuiyan commented on Aug 21, 2026

    @sarwarbhuiyan
    Contributor

    Checkpoint configuration/provenance validation is now separated into #4018. This issue remains the worker-progress/consumer-commit problem: parent-visible state must not advance merely because workers prefetched rows the trainer has not consumed.

  3. brunosrz commented on Aug 22, 2026

    @brunosrz

    This looks like the same defect as #3751 ("StreamingDataset checkpointing doesn't work when num_workers > 0"), filed on July 31 — same root cause, described from the other end. #3751 states it concisely ("the samples consumed counters are process-local"), and this one contributes the reproduction and the concrete observed values, so they complement each other rather than conflict.

    Worth linking them so the discussion does not fork: there is already root-cause analysis and a proposed approach in the comments on #3751.

    One detail that may help whoever picks it up: the resume state read by state_dict() lives in plain instance attributes (_resume_offset, _resume_positions), but streaming.py already carries _worker_stats = RawArray(ctypes.c_int64, 8) for exactly this problem, with a comment noting it is picklable across the process boundary. The mechanism for crossing back to the parent is already in the file — it just is not what the checkpoint path reads from.

    Not claiming this, just flagging the duplicate.

  4. added a commit that references this issue on Aug 24, 2026
    105fd73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions