Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions grail/infrastructure/delta_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def apply_sparse_delta(

# Infer dtype from base_state if not specified
if target_dtype is None:
if not base_state:
raise ValueError("Cannot infer target_dtype: base_state is empty")
target_dtype = next(iter(base_state.values())).dtype

for name, base_tensor in base_state.items():
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/infrastructure/test_delta_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ def test_dtype_conversion(self) -> None:

assert result["weight"].dtype == torch.bfloat16

def test_empty_base_state_raises_value_error(self) -> None:
"""Test that empty base_state with target_dtype=None raises ValueError instead of StopIteration."""
with pytest.raises(ValueError, match="Cannot infer target_dtype: base_state is empty"):
apply_sparse_delta({}, {}, {}, target_dtype=None)

def test_empty_base_state_with_explicit_dtype(self) -> None:
"""Test that empty base_state with explicit target_dtype returns empty dict."""
result = apply_sparse_delta({}, {}, {}, target_dtype=torch.float32)
assert result == {}


class TestRoundTrip:
"""Test round-trip: compute delta, apply delta, verify identical."""
Expand Down