Identity
ModuleIdentity()Pass-through layer that returns its input unchanged.
For any input the layer computes
with no learnable parameters.
Notes
Identity is primarily useful as a structural placeholder when a
layer slot must be filled but no transformation is desired. Common
scenarios include:
-
Ablation studies — swap out a component (e.g. a dropout or normalization layer) with
Identityto isolate its effect without refactoring the surroundingnn.Sequential. -
Conditional composition — build models where a sub-network is either a real layer or a no-op depending on a configuration flag::
head = nn.Linear(256, num_classes) if use_head else nn.Identity() -
Skip connections — act as the identity branch in a residual block when the channel dimensions already match, avoiding any projection.
- Input: any shape .
- Output: identical shape — same data, same storage.
Examples
Use as a drop-in replacement for a disabled component:
>>> import lucid
>>> import lucid.nn as nn
>>> layer = nn.Identity()
>>> x = lucid.randn(3, 64)
>>> y = layer(x)
>>> (y - x).abs().max().item() == 0.0
True
Conditional head in an ``nn.Sequential``-style pipeline:
>>> use_projection = False
>>> proj = nn.Linear(512, 512) if use_projection else nn.Identity()
>>> x = lucid.randn(1, 512)
>>> proj(x).shape
(1, 512)Methods (1)
forward
→Tensorforward(x: Tensor)Apply the linear transformation to the input tensor.
Parameters
inputTensorReturns
TensorOutput tensor of shape .