PreprocessesInputAttribute

Attributes · AiDotNet.Attributes

Declares that the model transforms its input before the layer stack sees it, so the tensor reaching Layers[0] is NOT the tensor the caller passed to Predict.

Inheritance: Attribute → PreprocessesInputAttribute

For Beginners

most models feed their input straight into the first layer — the tensor you pass to Predict is exactly the tensor that layer receives. A few do a conversion step first. A time-series foundation model, for example, may turn a run of real-valued measurements into a list of whole-number token IDs before any layer runs, the same way a language model turns text into tokens. After that step the shape has changed completely, and it is the CONVERTED shape the first layer must accept — not the one the model advertises to callers.

How It Works

What it is for. The declared-input boundary check reads the model’s own [TensorLayout(Direction = Input)] and compares it against the first layer’s, to catch a model advertising an input rank its own stack rejects — a shape on which Predict can never succeed. That comparison is only meaningful when both declarations describe the SAME tensor. Where a conversion step sits between them they describe different tensors, both correctly, and the check would report a defect that is not there. This attribute is how a model says so.

Why an attribute and not a virtual property. This is a fact about the TYPE, not about any instance: whether a conversion step exists is fixed by the code, never by a constructor argument. As an attribute it can be read off the open generic type — before anything is constructed, and without closing the type over some particular numeric type just to reach a bool. A checker that had to build an instance first would silently stop exempting any model whose construction failed for an unrelated reason, which is the quiet kind of coverage loss this shape work exists to eliminate.

Why the reason is required. This attribute REMOVES a check, so an unexplained one is indistinguishable from a way to silence an inconvenient failure. The reason should name the conversion — the method that performs it — so the next reader can confirm the exemption still holds instead of taking it on trust. It is surfaced in the boundary check’s report, not just in the source.

When NOT to use this. If the model folds its input directly into the stack (foreach (var layer in Layers) current = layer.Forward(current);), a mismatch between the two declarations is a REAL defect and this attribute would hide it. Fix whichever declaration is wrong instead: either the model advertises a rank it cannot serve, or the first layer is the wrong layer for the input the model accepts. Reshaping alone does not qualify either — a rank change is exactly what the two declarations are supposed to disagree about visibly.

Constructors

Constructor Summary
PreprocessesInputAttribute(string reason) Creates the declaration.

Properties

Property Summary
string Reason { get; } Why the layer stack does not see Predict’s input.