Skip to content
class

Identity

extendsModule
Identity(args: object = (), kwargs: object = {})

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)

Used by 1

Constructors

1
dunder

__init__

→None
__init__(args: object = (), kwargs: object = {})

Accept and ignore any arguments.

So Identity can stand in wherever a layer is built from arguments — norm_layer(dim), act(inplace=True) — without a special case at the call site. It raised on any argument before.

Instance methods

1
fn

forward

→Tensor
forward(input: Tensor)

Return the input unchanged.

Parameters

inputTensor
Input of any shape.

Returns

Tensor

input itself.