Repository navigation
flow: Partition and Reduce, keyed partitions in flows (plan PR 1) - #176
Merged
Merged
Conversation
Two operators that run a shuffle inside a flow. A Partition runs a TaskMany once per input on all of that input's batches and makes `parts` pieces; once every input's pieces exist (the barrier), Reduce runs a TaskWith per partition on piece j of every input in input order, and Maps may follow. Results come by partition. WithLike names a TaskWith's element type, ManyLike.Part is Movable & Deinitable, and partition_of is a stable splitmix64 / FNV-1a hash. Flows without a Partition run the same code. Gate: tests/test_flow_partition.mojo and three compile-fail cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017TycsyUqdnuDeZrYc3z6wV
Renaming TaskWith's parameter would break callers passing X= by keyword. The trait member is named Elem instead, set as `comptime Elem = Self.X`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017TycsyUqdnuDeZrYc3z6wV
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.
PR 1 of DESIGN.md's "Keyed partitions in flows (plan, 2026-11-29)" (#175).
What was built
Partition[T: ManyLike, parts, budget=4]: oneTaskManyper input, run on all of that input's batches in the read's order (rt.remote_many[T](refs, parts)). It makespartspieces, and an input with no batches makes none. Its budget counts tasks in flight plus finished inputs waiting for one, and the read opens no new stream while it is full.Reduce[T: WithLike, budget=16]: after the barrier, oneTaskWithper partitionj, on piecejof every input in input order. Each piece ref is released as soon as its reducer is submitted.Map/MapWithmay follow it.Executor: two chains joined by a barrier. The first chain ends at
FlowRun.L, the operator before thePartition. The executor waits on each partition task's first piece only. At the barrier it checks every piece'serror_of.nexthands out oneFlowResultper partition (input= partition index), andrunreturns results by partition. A failed flow releases every piece (_abandon).Compile-time checks (
Flow._check):Partition, and it is followed by aReduceReducecomes right after aPartitionPartition'sInisSeq[<prev Out>], checked by nameReduce's task takes anInt, and its pieces match thePartition'sparts >= 1At run time,
startchecks that aPartition's task is aTaskManyand aReduce's is aTaskWith.Core:
ManyLike.Partis nowMovable & Deinitable.WithLiketrait (exported fromdista), exposing aTaskWith's element typeX.dista.flow.partition_of(key, parts): splitmix64 for anInt, FNV-1a 64 (fnv1a64) for aStringSpan, moduloparts. Unseeded and stable; the test pins fixed values.README "Flows" bullet, CHANGELOG (Added and Changed), DESIGN.md: PR 1 marked done, with a "PR 1, as built" note.
Flows without a
PartitionhaveP = -1andL = N - 1, and they run the same steps as before.Deviations from the plan (also in DESIGN.md, "PR 1, as built")
TaskWith's element parameter is nowX_, withcomptime X = Self.X_. Mojo doesn't let a struct parameter stand for a trait'scomptimemember ("required member 'X' is not specified"). Positional uses are unchanged.Partitionon fails the flow instead of rerunning. That covers a partition task's loss, a piece's loss at the barrier, and a reducer's loss. Rerunning before the barrier, and the clear message after it, are PR 2. Losses before thePartitionstill rerun their input.partition_oftakes aStringSpan, the typefnv1a64takes.Reduce's Int check is also asserted inReduce.submit_with, which is where the compiler reports it.The plan's unverified point
The head accepts a reducer with zero inputs. With no inputs, or with every input empty, all
partsreducers run on an emptySeqand each partition is handed out once (test_inputs_with_no_batches_and_no_inputs).Verified
On the Mac (osx-arm64):
tests/test_flow_partition.mojo: 7/7 pass.parts4, with aMapbefore and after; counts and integer sums equal one process'sDict, every key exactly once, each partition handed out oncert.stats()objects, results, located and errors all 0)to_bits, sums mixing 1e12 and 0.1)partition_of's pinned valuestests/test_flow.mojo15/15 andtests/test_shuffle.mojo9/9 pass, unchanged.tests/compile_fail.shpasses, with three new cases:reduce_without_partition,reduce_wrong_piece,reduce_not_int.pixi run -e fmt format-checkis clean.pixi run -e embed bench-embed-stubbuilds and its check passes.pixi run testpasses (rc 0).On Linux (
sai, a fresh HTTPS clone of this branch):test_flow_partition7/7 andtest_flow15/15 pass.🤖 Generated with Claude Code
https://claude.ai/code/session_017TycsyUqdnuDeZrYc3z6wV