Set seed with prefetch for reproducibility
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Domain
- data-engineering
Research direction
Start by tracing dmx.set_state and the prefetch(prefetch_size=4, num_threads=4) entry point shown in the Python example. Investigate how multiple prefetch threads affect sample ordering and seed state. Done means repeated runs with the same seed and more than one thread return the same samples and batch values.
Written by the indexing model from the issue text.
Description
Currently, the only way to the seed is with mlx.data.core.set_state, but this only controls the seed for .shuffle(). When using .prefetch with num_threads > 1, the samples returned are not deterministic and therefore not reproducible.
Is there a way to set the seed when prefetching with more than one thread?
import mlx.data.core as dmx
from mlx.data.datasets import load_mnist
dmx.set_state(42)
train = load_mnist(root=None, train=True)
dset = (
train.shuffle()
.to_stream()
.key_transform("image", lambda x: x.astype("float32") / 255)
.batch(32)
.prefetch(prefetch_size=4, num_threads=4) # non-deterministic with > 1 thread
)
for i, data in enumerate(dset):
print(data["image"].sum())
if i == 2:
break
- Dominant language
- C++
- Stars
- 483
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Contributor 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 ml-explore/mlx-data
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
ml-explore/mlx-data#114 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
ml-explore/mlx-data#113 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
ml-explore/mlx-data#55 · 2 reactions ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
ml-explore/mlx-data#54 · 2 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ml-explore/mlx-data#47 · 1 comment ·
All issues in ml-explore/mlx-data
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-samples#453 ·