Reshape and transpose

Reshape · node type · Reshape, Flatten, Transpose, Squeeze, Unsqueeze

Changes how values are arranged into axes without changing the values themselves.

Also called Reshape, Flatten, Transpose, Permute, Squeeze, Unsqueeze

Figure 1. Reshape and transpose inside Upscale a low-resolution photo, a real model in WeightSpace. The 3 outlined nodes are Reshape and transpose; select any node for its shapes and parameters.

What it does

Reshape regroups the same numbers into a different shape, for example flattening a [C, H, W] feature map into one vector for a dense head, or splitting a [T, D] tensor into [T, heads, D/heads] for attention. Transpose reorders axes, such as moving channels last or swapping time and batch. These operations are bookkeeping: they cost little and learn nothing, but they make up a large share of the nodes in exported transformer graphs. Atlas hides the shape arithmetic that only computes their targets.

Formula

Flatten: [N, C, H, W] → [N, C·H·W]Transpose(perm): Y[iperm(0), …] = X[i0, …]

Shapes and parameters

Shapes
Same number of elements in and out; only the arrangement of axes changes.
Parameters
None.
Used for
Between convolutional features and dense heads, inside every multi-head attention, around recurrent layers that expect time first, and at model outputs.

Figure 2. The typed ports of Reshape and transpose, in the same format as every model drawing. Letters such as N or C stand for any size.

In WeightSpace

Read-only in WeightSpace today.

Where it appears