Skip to content

Bug: apply_sparse_delta crashes with StopIteration when base_state is empty and target_dtype is None #66

Description

@Grizouforever

Description

apply_sparse_delta in grail/infrastructure/delta_checkpoint.py (line 137) crashes with an unhandled StopIteration exception when base_state is an empty dict and target_dtype is None.

if target_dtype is None:
    target_dtype = next(iter(base_state.values())).dtype  # StopIteration if base_state == {}

This is called from checkpoint_consumer.py at lines 439-444 and 1315-1319 with target_dtype=None, making those call sites vulnerable to the crash.

Steps to Reproduce

from grail.infrastructure.delta_checkpoint import apply_sparse_delta

apply_sparse_delta({}, {}, {}, target_dtype=None)
# StopIteration raised, not caught by caller

Expected Behavior

A clear ValueError with a descriptive message: "Cannot infer target_dtype: base_state is empty".

Actual Behavior

StopIteration propagates up through the call stack, crashing the caller.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions