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 therefore describes a mask by two rank-indexed vectors:
shape : Vector Nat dgives the tensor extents;blocks : Vector (Option Nat) dselects 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.
Compute the row-major index of the block containing coordinate.
Axes marked none are ignored, so the same spatial mask is repeated across batch, channel, token,
or feature axes. The final Boolean records whether at least one axis participates in the block grid.
Instances For
Read a scalar from a shape-indexed tensor using runtime coordinates.
Instances For
Recursively apply a block mask while accumulating the current coordinate.
Instances For
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
Exact coordinate semantics of blockMask, including out-of-bounds coordinates.
A visible in-bounds coordinate is copied unchanged by the mask.
Apply the same block mask independently to each row of a batch.
Instances For
Coordinate semantics of one row of blockMaskBatch.
Create a masked-reconstruction sample from a batch of arbitrary-rank tensors.
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; reconDim may be the entire sample or a
smaller prefix for an experiment.
Instances For
The model input of a block-MAE sample is exactly the masked source batch.
The target of a block-MAE sample is the requested prefix of the unmasked source batch.
Every decoder coordinate participates in the compact reconstruction objective.
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.