ConcatThenSplitIterDataset drops a document when restored from a JSON-serialized state
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- data-engineering
Research direction
Start by locating _CtsState, _EMPTY_SLICE, and the slice comparisons in ConcatThenSplitIterDataset; the issue identifies _CtsState.__post_init__ as one possible fix. Run the JSON serialization reproduction, then check that restoring its state produces the same packed elements as an uninterrupted run.
Written by the indexing model from the issue text.
Description
_CtsState.remainder_slices marks "no remainder" (or a whole, unsliced remainder) with the tuple
sentinel _EMPTY_SLICE = (-1, -1), and has_remainder, _CtsElement.split and
get_sliced_features compare slices against it with !=. A state that goes through JSON, as
checkpoints do, comes back with lists ([-1, -1]), which never equal the tuple. set_state then
takes the next parent element as a remainder and get_sliced_features slices it [-1:-1], so that
element is dropped from the packed stream.
Reproduction (grain 0.2.18; the comparisons are the same on main):
import json
import numpy as np
import grain.python as pygrain
import grain.experimental as gx
docs = [{"text": (np.arange(n) + 100 * i).astype(np.int32)} for i, n in enumerate((3, 5, 8, 4, 6))]
def build():
return iter(gx.ConcatThenSplitIterDataset(pygrain.MapDataset.source(docs).to_iter_dataset(),
length_struct={"text": 8}))
whole = build()
windows = [next(whole)["text"].tolist() for _ in range(4)]
stopped = build()
next(stopped)
state = json.loads(json.dumps(stopped.get_state())) # {'remainder_slices': {'text': [-1, -1]}, ...}
resumed = build()
resumed.set_state(state)
print([next(resumed)["text"].tolist() for _ in range(3)], windows[1:]) # StopIteration: a document was dropped
With state["remainder_slices"] converted back to tuples the restore matches the uninterrupted run.
A fix: normalize the slices to tuples in _CtsState.__post_init__ (or compare tuple(sl)).
- Dominant language
- Python
- Stars
- 792
- Forks
- 89
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 16
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from google/grain
-
Closing an mp_prefetch iterator stops its worker processes one at a timePossibly taken @jabrailkhalil claimed this 7 days ago. Opentype:bug
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
`stats._iter_weakref_registry` keeps refs of dead iterators, and a new iterator at a reused address is not registeredPossibly taken @Shr3yash claimed this 7 days ago. Opentype:bug
Difficulty 3/5 Half a day Newbie friendliness 55/100
Maintainers usually reply within 1 day
-
type:bug
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Maintainers usually reply within 1 day
-
mp_prefetch: a reference cycle per finished shard, and SharedMemory closed by two threadsPossibly taken @mahdi-shafiei claimed this 11 days ago. Opentype:bug
Difficulty 4/5 3-5 days Newbie friendliness 20/100
Maintainers usually reply within 1 day
-
mp_prefetch silently drops elements that cannot be pickledPossibly taken @rioyu123 claimed this 9 days ago. Opentype:bug
Difficulty 3/5 1-2 days Newbie friendliness 78/100
Maintainers usually reply within 1 day
Similar issues
-
Pull-through from gcr.io returns 500 when pulling using podman/buildahPossibly taken A pull request linked to this issue is open or already merged. OpenIssue Triage-Needed
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
pulp/pulp_container#2581 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
521xueweihan/HelloGitHub#4040 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
ClanGenOfficial/clangen#6313 ·
Maintainers usually reply within 2 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
bug(trainer): CustomTrainer func_args with non literal values fail inside the TrainJobPossibly taken @avanishkasar claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
kubeflow/sdk#879 · 1 comment ·
Maintainers usually reply within 1 day