class

Identity

extendsModule
Identity()
source

Pass-through layer that returns its input unchanged.

For any input x\mathbf{x} the layer computes

f(x)=xf(\mathbf{x}) = \mathbf{x}

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 Identity to isolate its effect without refactoring the surrounding nn.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 ()(\ast).
  • Output: identical shape ()(\ast) — 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)

fn

forward

Tensor
forward(x: Tensor)
source

Apply the linear transformation to the input tensor.

Parameters

inputTensor
Input tensor of shape (,in_features)(*, \text{in\_features}).

Returns

Tensor

Output tensor of shape (,out_features)(*, \text{out\_features}).