Repository navigation
Add Dataset.from_generator to materialize a stream or a Julia iterable - #111
Merged
Merged
Conversation
#109) `from_generator(source)` (also `Dataset.from_generator` and `Dataset(stream)`) writes the examples of an `IterableDataset`, a Julia iterable (or a function returning one, optionally yielding batches of columns with `batched = true`), or a Python generator function to a cached, memory-mapped `Dataset` in the "julia" format. A Julia source is cached under its content fingerprint, as for `map`; a stream is rebuilt on every call, in a temporary directory, unless given a `fingerprint`. The fingerprint is carried by the generator's pickle, so `features` and `split` stay in the cache key. An error in the generator is rethrown instead of `datasets`' uninformative `DatasetGenerationError`, and `num_proc > 1` throws an `ArgumentError`. Require `datasets >= 5.1` and drop the `_consolidate` workaround for older versions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Write `ds.map`/`ds.filter` (and `dd.`, `stream.`, `ds.shuffle`, ...) instead of a bare `map` or `filter`, which reads as Base's function. Examples use the property calls, docstring headers list `ds.map(f; kws...)` before the `map(f, ds::Dataset)` method, and Python-side names are written `datasets.Dataset.map`. Also drop the obsolete `datasets` < 4.8.3 note from the `RaggedVector` docstring. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`map` and `filter` are methods of `Base.map`/`Base.filter` on the package's types, so the unqualified `map(f, ds)` is unambiguous and idiomatic Julia. Keeps dropping the obsolete `datasets` < 4.8.3 note from the `RaggedVector` docstring. This reverts commit 5243e07. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #109.
Adds
from_generator(source), also reachable asDataset.from_generatorandDataset(stream). It writes the examples to a cached, memory-mappedDatasetin the"julia"format.sourcecan be:IterableDataset, with its Juliamap/filtersteps, iterated in-process (replaces theITERhack). The stream'sfeaturesandsplitcarry over.Dicts/NamedTuples, or a function returning one. Withbatched = trueit yields batches of columns, which are split into rows in Python.How it behaves:
map. A stream can't be fingerprinted, so withoutfingerprintit is rebuilt on every call, indatasets' temporary directory, so the HF cache doesn't fill up with unreusable copies.JuliaFunction), sofeaturesandsplitstay in the cache key.datasets' ownfingerprintkeyword would ignore them.datasets' uninformativeDatasetGenerationError.num_proc > 1: throws anArgumentError.Also raises the floor to
datasets >= 5.1and removes the_consolidateworkaround for older versions.Tested on TinyStories validation (stream + batched Julia
map+fingerprint): the rows are identical to the non-streamingmap, and a new session reuses the cache.🤖 Generated with Claude Code