src/tensor/parallel_LAWS.bend open laws/TODOs
raw source on the hub · import bendtorch-core@0.1.0.0/src/tensor/parallel_LAWS.bend as Parallel_LAWS
3 imports
import Base import ../storage/model.bend as Model import ./parallel.bend as Parallel
Laws
law parallel_build_balanced provedin PROOF.bendsource · line 15 · raw
@-Q:Data -> @-P:Data -> @-A:Type -> @-B:Type -> @-prepare:(@+q:Q -> P) -> @-split:(@_:Pair(A, B) -> Pair(Pair(A, B), Pair(A, B))) -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+q:Q -> @+depth:Nat -> @+splits:Nat -> @+count:Nat -> @+base:Nat -> @state:Pair(A, B) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, depth, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.build(Q, P, A, B, prepare, split, cell, q, depth, splits, count, base, state))
For every split, the parallel build is a balanced tree of its depth.
law parallel_build_cells provedin PROOF.bendsource · line 35 · raw
@-Q:Data -> @-P:Data -> @-A:Type -> @-B:Type -> @-prepare:(@+q:Q -> P) -> @-split:(@_:Pair(A, B) -> Pair(Pair(A, B), Pair(A, B))) -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+q:Q -> @+depth:Nat -> @+splits:Nat -> @+count:Nat -> @+base:Nat -> @state:Pair(A, B) -> @keeps:(@+position:Nat -> @inside:Bool -> {Pair.snd(F32, Pair(A, B), cell(prepare(q), position, state, inside)) == state : Pair(A, B)}) -> @first:{Pair.fst(Pair(A, B), Pair(A, B), split(state)) == state : Pair(A, B)} -> @second:{Pair.snd(Pair(A, B), Pair(A, B), split(state)) == state : Pair(A, B)} -> Holds<@+path:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Path(depth) -> {0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.observe(F32, depth, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.build(Q, P, A, B, prepare, split, cell, q, depth, splits, count, base, state), path) == Some{Pair.fst(F32, Pair(A, B), cell(prepare(q), Nat.add(0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.offset(depth, path), base), state, Nat.is_lt(Nat.add(0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.offset(depth, path), base), count)))} : Maybe<&2, F32>}>If each cell hands its input state back and the split copies the state
into both halves, then for every split each slot of the build, cell
base + offset, holds the F32 the cell function computes for it from the
input state, the padding past count included.
law parallel_build_sequential provedin PROOF.bendsource · line 60 · raw
@-Q:Data -> @-P:Data -> @-A:Type -> @-B:Type -> @-prepare:(@+q:Q -> P) -> @-split:(@_:Pair(A, B) -> Pair(Pair(A, B), Pair(A, B))) -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+q:Q -> @+depth:Nat -> @+splits:Nat -> @+count:Nat -> @+base:Nat -> @state:Pair(A, B) -> @keeps:(@+position:Nat -> @inside:Bool -> {Pair.snd(F32, Pair(A, B), cell(prepare(q), position, state, inside)) == state : Pair(A, B)}) -> @first:{Pair.fst(Pair(A, B), Pair(A, B), split(state)) == state : Pair(A, B)} -> @second:{Pair.snd(Pair(A, B), Pair(A, B), split(state)) == state : Pair(A, B)} -> Holds<@+path:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Path(depth) -> {0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.observe(F32, depth, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.build(Q, P, A, B, prepare, split, cell, q, depth, splits, count, base, state), path) == 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.observe(F32, depth, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.build(Q, P, A, B, prepare, split, cell, q, depth, 0n, count, base, state), path) : Maybe<&2, F32>}>Under the same two facts, the parallel build and the one-thread build (no split) hold the same F32 in every slot, so no output word depends on the split or on the thread count.
Types
type Holds source · line 11 · raw
@-P:Type -> Data
Holds@-P:Type -> @-proof:P -> Holds<P>