Arbitrary-Rank Block Masks #
Masked prediction is not intrinsically an image operation. A model may hide intervals in a signal,
rectangles in an image, cuboids in a volume, or blocks in a higher-dimensional simulation field.
This module describes a mask by a rank-indexed policy tensor. The extents come from the input
tensor's type, while blocks : Tensor (Option Nat) [d] selects the axes that form a block
grid.
none means that an axis does not participate in the block index. some k groups that axis into
consecutive blocks of width k. The selected block-grid coordinates are flattened in row-major
order, and one congruence class modulo period is hidden. A zero period, a zero block width, a rank
mismatch, or an out-of-bounds coordinate hides nothing.
The executable mask and its coordinate theorems use the same finite predicate. Consequently the runtime training sample cannot silently use a different patch convention from the one stated in Lean.
Flat index of the block a coordinate falls in, or none when the coordinate is out of range or no
axis is blocked at all.
The walk goes over shape and policy together. An axis with none contributes nothing; an axis with
some blockSize contributes its block coordinate as one digit of a mixed-radix number whose radix
is the number of blocks along that axis. used is what distinguishes "block 0" from "nothing was
blocked", which the caller has to tell apart.
Instances For
Is the block containing this coordinate hidden by the mask with the given period and offset?
Hiding every period-th block rather than sampling at random is a deliberate choice: a mask is
then reproducible from two numbers, which is what makes the self-supervised examples in the guide
comparable across machines and across runs.
Instances For
Zero out the hidden blocks of a tensor, recursing over the leading axes and collecting the coordinate prefix on the way down.
The result is rebuilt with stackLeading rather than written in place, so a masked tensor is an
ordinary value and the mask cannot depend on evaluation order.
Instances For
Reading one coordinate out of a masked tensor is the same as reading it out of the original and zeroing it when its block is hidden.
This is the lemma that makes apply usable in proofs. apply is defined by recursion on the
remaining shape, unstacking one axis at a time, so its unfolded form talks about stackLeading and
prefixes of coordinates rather than about masking. Stated pointwise it says what a reader expects a
mask to mean, and the Option.map on the right is just getSpec reporting an out-of-range
coordinate the same way on both sides.
Set every scalar in a selected block to zero, preserving the tensor's arbitrary-rank shape.
For example, policies [none, some 4, some 4] repeat a 4-by-4 block mask across the first axis;
[some 8] masks intervals in a signal; and [some 2, some 2, some 2] masks volume blocks.
Instances For
A visible in-bounds coordinate is copied unchanged by the mask.
Create a masked-reconstruction sample after validating the requested target width.
The model input retains its original shape. The target is a row-major prefix of the unmasked source because TorchLean's compact decoder heads produce matrices.
Instances For
Create a masked-reconstruction sample with arbitrary batch and data shapes.
The model input retains its original shape. The target is a row-major prefix of the unmasked source. An invalid reconstruction width is reported at the ordinary executable boundary rather than requiring callers to provide a theorem.
Instances For
One batch row of block-MAE training as a finite predictive-view contract.
Instances For
The runnable block-MAE row objective is exactly the finite MAE objective.