src/autograd/reduce_to_fold_PROOF.bend open laws/TODOs
raw source on the hub · import bendtorch-core@0.1.0.0/src/autograd/reduce_to_fold_PROOF.bend as Reduce_to_fold_PROOF
30 imports
import Base import ../shape/core.bend as Shape import ../storage/main.bend as Storage import ../storage/LAWS.bend as StorageLaws import ../storage/arith.bend as Arith import ../tensor/core.bend as Core import ../tensor/layout.bend as Layout import ../tensor/lifecycle.bend as Lifecycle import ../tensor/elementwise.bend as Elementwise import ../tensor/word_conversion.bend as Conversion import ../tensor/permutation_mapping.bend as Mapping import ../tensor/projection_LAWS.bend as Projection import ../tensor/projection_PROOF.bend as ProjectionProof import ../tensor/contracts/replayed.bend as Replayed import ../tensor/contracts/pointwise.bend as Pointwise import ../tensor/contracts/pointwise_proof.bend as PointwiseProof import ../tensor/contracts/broadcast_proof.bend as BroadcastProof import ../tensor/contracts/fold.bend as Fold import ../tensor/contracts/sum.bend as Sum import ../tensor/contracts/LAWS.bend as Contracts import ./reduce.bend as Reduce import ./reduce_LAWS.bend as ReduceLaws import ./reduce_fold.bend as ReduceFold import ./reduce_fold_PROOF.bend as FoldProof import ./reduce_fold_LAWS.bend as Laws import ../storage/api.bend as Api import ../storage/array.bend as ArrayCore import ../tensor/read_contract.bend as Reads import ../tensor/contracts/binary_storage_proof.bend as Owned import ./reduce_replayed_proof.bend as Replay
Definitions
def planned_shapes source · line 32 · raw
@left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @result:Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan> -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape)
def shapes_construct source · line 39 · raw
@+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @-left_padding:Nat -> @-right_padding:Nat -> @-minimal:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.PadMinimal<left_padding, right_padding> -> @-output:List<&2, U32> -> @-aligned:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Aligned(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.pad(left_padding, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(left)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.pad(right_padding, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(right)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.naturals(output)) -> @+result:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.ConstructResult<output> -> {planned_shapes(left, right, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.broadcast_checked.construct(left, right, left_padding, right_padding, minimal, output, aligned, result)) == (left, right) : Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape)}
def shapes_align source · line 51 · raw
@+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+left_padding:Nat -> @+right_padding:Nat -> @-minimal:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.PadMinimal<left_padding, right_padding> -> @+alignment:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Alignment<0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.pad_words(left_padding, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(left)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.pad_words(right_padding, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(right))> -> {planned_shapes(left, right, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.broadcast_checked.align(left, right, left_padding, right_padding, minimal, alignment)) == (left, right) : Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape)}
def shapes_checked source · line 64 · raw
@+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> {planned_shapes(left, right, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.broadcast_checked(left, right)) == (left, right) : Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape)}
def first source · line 72 · raw
@pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape
def second source · line 76 · raw
@pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape
def plan_shapes source · line 80 · raw
@+target:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @planned:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.broadcast_checked(target, shape) == Done{plan} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan>} -> {(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.left_shape(plan), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan)) == (target, shape) : Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape)}
def plan_left source · line 86 · raw
@+target:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @planned:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.broadcast_checked(target, shape) == Done{plan} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan>} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.left_shape(plan) == target : 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape}
def plan_right source · line 92 · raw
@+target:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @planned:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.broadcast_checked(target, shape) == Done{plan} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan>} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan) == shape : 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape}
def target_index source · line 98 · raw
@+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @+position:Nat -> U32
def source_index source · line 101 · raw
@+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @+position:Nat -> U32
def target_below source · line 106 · raw
@+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @+target:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+left:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.left_shape(plan) == target : 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape} -> @+position:Nat -> @below:{Nat.is_lt(position, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)))) == True{} : Bool} -> {Nat.is_lt(0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_fold.target_offset(plan, position), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(target))) == True{} : Bool}Contribution position position lands on a target cell below the target's
count.
def source_below source · line 112 · raw
@+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan) == shape : 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape} -> @+position:Nat -> @below:{Nat.is_lt(position, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)))) == True{} : Bool} -> {Nat.is_lt(0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_fold.contribution_offset(plan, position), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape))) == True{} : Bool}
def some_injective source · line 118 · raw
@-A:Type -> @-x:A -> @-y:A -> @equal:{Some{x} == Some{y} : Maybe<&1, A>} -> {x == y : A}
def indices_found source · line 121 · raw
@+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @+cursor:Nat -> @+below:{Nat.is_lt(cursor, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)))) == True{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/projection_LAWS.indices_result(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise.input_indices(plan, U32.from_nat(cursor))) == Some{(target_index(plan, cursor), source_index(plan, cursor))} : Maybe<&1, Pair(U32, U32)>}
def contribution_count source · line 132 · raw
@+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @same:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape) : List<&2, U32>} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan))) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape)) : Nat}
def contribution_room source · line 137 · raw
@+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @same:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape) : List<&2, U32>} -> {Nat.is_le(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)))) == True{} : Bool}
def fitted_same source · line 144 · raw
@+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @same:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape) : List<&2, U32>} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/layout.words_same(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape)) == True{} : Bool}
def run_lift source · line 153 · raw
@+target:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @+planned:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.broadcast_checked(target, shape) == Done{plan} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan>} -> @+same:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape) : List<&2, U32>} -> @+fill:F32 -> @+ops:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/LAWS.Op> -> @-P:(@_:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Type) -> @h:0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_replayed_proof.Final(plan, target, shape, fill, ops, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.index_map(plan), 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/LAWS.created(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.count(target), 0.0), P) -> @-fits:{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/lifecycle.logical_length(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/replayed.storage(shape, fill, ops)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape)) : Nat} -> P(0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.reduce_to(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Packed{shape, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.TTensor{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/replayed.storage(shape, fill, ops), fits}}, target))The parallel reduce over a replayed contribution, in the transport form of
Replay.Final.
def cell_fiber source · line 195 · raw
@+target:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @+planned:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.broadcast_checked(target, shape) == Done{plan} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan>} -> @+same:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape) : List<&2, U32>} -> @+fill:F32 -> @+ops:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/LAWS.Op> -> @+index:U32 -> @+inside:{Nat.is_lt(U32.to_nat(index), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(target))) == True{} : Bool} -> {Some{0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_replayed_proof.cell_word(plan, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.index_map(plan), shape, fill, ops, U32.to_nat(index))} == 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_LAWS.fiber(plan, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/LAWS.words(shape, fill, ops, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape))), index, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape))) : Maybe<&2, F32>}A target cell of the replayed reduce holds ReduceLaws.fiber over the
contribution's words.
def reduce_to_fiber source · line 212 · raw
@+target:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @+planned:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.broadcast_checked(target, shape) == Done{plan} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan>} -> @+same:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape) : List<&2, U32>} -> @+fill:F32 -> @+ops:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/LAWS.Op> -> @-fits:{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/lifecycle.logical_length(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/replayed.storage(shape, fill, ops)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape)) : Nat} -> 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_fold_LAWS.ReduceToContract<target, shape, index => 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_LAWS.fiber(plan, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/LAWS.words(shape, fill, ops, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape))), index, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape))), other => 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/replayed.value(shape, fill, ops, other), 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.reduce_to(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Packed{shape, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.TTensor{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/replayed.storage(shape, fill, ops), fits}}, target)>