Conv2D Shared Bounds #
Shared NF backend utilities for Conv2D forward/backward runtime-to-spec approximation.
This file contains the common arithmetic error updates and tensor-shaped Conv2D bound builders used
by both ConvForward and ConvBackward. The node constructors live in the direction-specific
files; the shared definitions stay here so the forward and VJP proofs do not duplicate the same
fold/error algebra.
The key idea is to treat Conv2D as a pure spec definition (Spec.conv2d_spec /
Spec.conv2d_backward_spec) instantiated at:
- spec scalars:
ℝ - runtime scalars:
NF β fexp rnd(rounding after each primitive op)
and then prove explicit bounds of the form:
toSpec (runtime_result) ≈ spec_result
compatible with the tape/DAG composition theorems in:
PyTorch correspondence / citations #
Our image tensor shape is C × H × W (no batch dimension), and the kernel shape is
outC × inC × kH × kW. This matches the per-example core of PyTorch’s conv2d (which normally
expects N × C × H × W inputs and supports extra features like groups).
https://pytorch.org/docs/stable/generated/torch.nn.functional.conv2d.html
https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html
Small helper bounds for list folds #
Absolute-error update for one rounded addition in the NF backend.
Instances For
Absolute-error update for one rounded multiplication in the NF backend.
Instances For
Fold a rounded sum while tracking an absolute-error budget, starting from an explicit state.
Instances For
foldAddStateFrom started at (0,0).
Instances For
Component access: getAtOrZero respects approxT #
Padding reads #
Approximation bound for reading padded inputs.
Both the forward and backward Conv2D approximation proofs reduce to reading a padded input tensor
at indices (c,p,q) and comparing the runtime read (in R) against the spec read (in ℝ).
Conv2D forward: pointwise error bound for one output scalar #
Output height for a 2D convolution.
Instances For
Output width for a 2D convolution.
Instances For
Pointwise absolute-error bound for one Conv2D output scalar in the NF backend.
Implementation note:
we replay the same fold structure as Spec.conv2d_spec, but track an explicit absolute-error
budget alongside the runtime accumulator. This keeps the bound aligned with the runtime addition
order (which matters for worst-case rounding error).
Instances For
Tensor of pointwise Conv2D absolute-error bounds for the full output image.
Instances For
conv2dPointBound and conv2dBoundTensor provide the data needed for a Conv2D
runtime→spec approximation lemma, but the full end-to-end FwdNode/RevNode instances are
intentionally deferred.
Reason: a direct proof that these bounds are sound for the current Spec.conv2d_spec definition
is non-trivial and requires careful performance engineering (similar to the Conv2D fderiv file).
The design intent is to keep Conv2D as a "big op" with its own proof module, instead of slowing
down the core NF numeric library.