IAttentionBlockDecorator<T>

Interfaces · AiDotNet.Interfaces

A layer that WRAPS an attention block, adding something to its output without replacing how the block itself is invoked.

Implements: ILayer<T>

Known implementations: TLoRAAttentionAdapter<T>

How It Works

This exists because invoking an attention block is not uniform: self-attention takes Forward(x), while cross-attention needs its conditioning passed through a type-specific overload (ForwardWithContext or a two-argument Forward). A decorator that only overrides Forward(x) therefore matches none of those type tests and falls through to the single-argument path, which SILENTLY DROPS the conditioning — the wrapped model still runs, and produces plausible-looking output computed without the text embedding at all.

Splitting the wrapper into “how do I call the inner block” (the caller’s existing dispatch, applied to Inner) and “what do I add afterwards” (PostProcess) keeps the inner invocation exactly as it was. Callers should prefer this over a type test against any concrete decorator, so new adapters need no changes at the call site.

Properties

Property Summary
ILayer<T> Inner { get; } Gets the wrapped block, which should be invoked using whatever dispatch the caller would have used had it not been wrapped.

Methods

Method Summary
Tensor<T> PostProcess(Tensor<T> innerOutput) Transforms the wrapped block’s output.