Papers
Topics
Authors
Recent
Search
2000 character limit reached

Shifted Chunk Transformer

Updated 21 April 2026
  • Shifted Chunk Transformer is a variant that partitions data into non-overlapping chunks and applies local self-attention with cyclic shifts for global information flow.
  • The architecture employs strategies like multi-scale windows and feature fusion to achieve long-range dependency modeling with linear complexity relative to window size.
  • Empirical studies across domains such as bio-signals, ASR, vision, and language modeling demonstrate its competitive performance and computational efficiency.

A Shifted Chunk Transformer is a Transformer variant that partitions the sequence (or higher-dimensional input) into non-overlapping local "chunks" or "windows," constrains self-attention to be local within these chunks, and alternates layers with shifted chunk boundaries; this design enables efficient global context propagation with reduced computational cost compared to global attention. The mechanism originated in efficient vision Transformers—most notably Swin Transformer—but has since been formalized and adapted for 1D, 2D, and higher-dimensional data, as well as for modeling long-range dependencies in LLMs and time series. Shift operations—cyclic or offset shifts of chunk boundaries between layers or heads—enable signals to propagate across chunk borders. Recent work has further generalized the paradigm to multi-scale, multi-shift, and hybrid sparse attention settings.

1. Architectural Principles and Chunk Partitioning

The core idea is to partition an input X∈RN×dX\in\mathbb{R}^{N \times d} into non-overlapping chunks/windows of fixed size ww, yielding P=N/wP=N/w chunks: Partition(X,w)={X(1),X(2),…,X(P)},X(p)∈Rw×d\mathrm{Partition}(X, w) = \{ X^{(1)}, X^{(2)}, \ldots, X^{(P)} \}, \quad X^{(p)} \in \mathbb{R}^{w \times d} where each chunk contains a contiguous block of tokens, e.g., Xi,:(p)=X(p−1)w+i,:X^{(p)}_{i,:} = X_{(p-1)w + i, :}. Self-attention is performed independently within each chunk, confining computation to local neighborhoods and reducing complexity from O(N2d)O(N^2 d) (global SA) to O(Nwd)O(N w d) (w≪Nw\ll N) (Cheng et al., 2023, Wang et al., 2022).

For higher-dimensional data, partitioning generalizes to non-overlapping spatial windows (image/video), assembling chunks as D-dimensional blocks with appropriate reshaping (Cheng et al., 2023, Zha et al., 2021). Non-divisible boundaries can be handled by padding or dropping leftover tokens.

2. Shifted Chunk Mechanism and Cross-Chunk Propagation

To restore global connectivity lost in strictly local chunked attention, each subsequent block (or attention head group) processes a sequence that is cyclically shifted by s=⌊w/2⌋s=\lfloor w/2 \rfloor: SHIFT(X,s)i=X(i−smod  N),:\mathrm{SHIFT}(X, s)_i = X_{(i-s \mod N), :} Chunks are then computed over the shifted sequence, so each shifted chunk overlaps the borders of two adjacent regular chunks from the previous layer, enabling signal flow across original chunk boundaries (Cheng et al., 2023, Wang et al., 2022).

Alternating regular and shifted chunk attention propagates information globally over a small number of layers. Empirically, a sequence of such alternations is sufficient to recover a large receptive field while never exceeding the per-layer ww0 cost (Wang et al., 2022, Guo, 2023).

3. Multi-Scale and Multi-Shift Extensions

The architecture can be extended to multi-scale attention by computing parallel attention streams over multiple window sizes ww1 within each layer (Cheng et al., 2023). Each scale captures distinct receptive fields:

  • Each branch partitions and attends over its window size.
  • Outputs ww2 for each scale are projected/fused via a learnable feature fusion mechanism such as weighted averaging with attention-pooling over the global sequence:

ww3

with ww4 formed by concatenating global-pooled features from all scales (Cheng et al., 2023).

Further, generalized shift strategies are used within and across heads:

  • Fixed per-head shifts (SCCA_fixed): Half the heads perform local chunk attention, half attend to a fixed offset (e.g., by rolling K/V by ww5).
  • Multi-offsets per head (SCCA_flow): Each head is rolled by a different chunk-sized offset, and across all heads, the union of receptive fields covers the full sequence in one layer (Guo, 2023).

Dilated strategies (Shifted Dilated Attention): Within each head, attention is computed over noncontiguous, strided key indices, further increasing the attention span for each token (Guo, 2023).

4. Implementation Patterns and Layer Construction

The shifted chunk mechanism is realized in attention blocks as follows (standard for both sequence and image/video):

  1. Partition ww6 into chunks/windows.
  2. Apply Q/K/V projections and attention restricted within each chunk.
  3. Alternate with a sequence cyclically shifted by half-window (or other offsets), again chunking and attending locally.
  4. Revert the cyclic shift to align outputs to the input order.
  5. Optionally, perform multi-scale parallel streams and combine via feature fusion.

High-level pseudocode for a single layer (multi-scale, with both regular and shifted partitions) (Cheng et al., 2023): Partition(X,w)={X(1),X(2),…,X(P)},X(p)∈Rw×d\mathrm{Partition}(X, w) = \{ X^{(1)}, X^{(2)}, \ldots, X^{(P)} \}, \quad X^{(p)} \in \mathbb{R}^{w \times d}0 For SCCA/LongMixed, per-head chunk rolling and mixed strategies are used; see (Guo, 2023) for detailed PyTorch-style pseudocode.

Table: Comparison of Key Shifted-Chunk Mechanisms

Variant Shift Structure Receptive Field Growth
Standard Chunk (no shift) None ww7 per layer, slow global mixing
Shifted Chunk (alt. layers) Layerwise cyclic shift ww8 after ww9 layers
SCCA_fixed Half-head K/V roll Crosses chunk boundaries per layer
SCCA_flow Headwise rolling Full sequence covered in one layer
SDA Strided per-head Non-contiguous; fills globally over layers

5. Computational Complexity and Parallelism

Chunked/shifted attention reduces memory/computation relative to global self-attention:

  • Full self-attention: P=N/wP=N/w0 FLOPs, P=N/wP=N/w1 memory.
  • Chunked attention: P=N/wP=N/w2, window size P=N/wP=N/w3.
  • Multi-scale: P=N/wP=N/w4.

SCCA and related per-head shifting strategies maintain P=N/wP=N/w5 (assuming P=N/wP=N/w6 heads). Dilated strategies can interpolate between chunked (P=N/wP=N/w7) and global (P=N/wP=N/w8), allowing design trade-offs (Guo, 2023).

Such designs admit full parallelism in training: chunk partitioning, cyclic shifting, and masked dot products can be implemented with gather/scatter operations, allowing batches of sequences with arbitrary padding (Wang et al., 2022). Streaming and incremental inference is possible by caching partial keys/values for past chunks and using hard masks to enforce causality and receptive-field constraints (Du et al., 2024).

6. Empirical Applications and Benchmarks

Shifted Chunk Transformers have been validated in diverse domains:

  • ECG Classification: MSW-Transformer with multi-scale shifted windows and feature-fusion yields state-of-the-art macro-F1 and sample-F1 on PTBXL-2020, demonstrating effective sequence modeling in bio-signals (Cheng et al., 2023).
  • End-to-End ASR: SChunk-Transformer achieves character error rate (CER) competitive with quadratic-complexity methods but with strictly linear scaling, e.g., SChunk-Conformer achieves 5.77% CER on AISHELL-1 vs 5.55% for U2 at reduced training time (Wang et al., 2022).
  • Spatio-Temporal Learning: SCT outperforms or matches state-of-the-art ConvNet and pure-Transformer baselines across Kinetics-400/600, UCF101, HMDB51, with fewer parameters and FLOPs, demonstrating the effectiveness of tiny-patch, local-global abstraction, and shifted motion modeling (Zha et al., 2021).
  • Long-Context Language Modeling: SCCA extends LLaMA2-7B to 8K tokens in a single V100 via SCCA_fixed/SCCA_flow/LongMixed, outperforming previous sparse attention in perplexity for both story (PG19) and pile benchmarks (Guo, 2023).
  • Low-Latency Text-to-Speech: Incremental FastPitch with chunk-based FFT blocks and receptive-field-masked attention achieves a ~4× reduction in first-chunk latency over standard FastPitch with negligible MOS degradation, supporting real-time TTS (Du et al., 2024).

7. Generalizations and Design Principles

Shifted Chunk Transformers generalize to arbitrary chunk shapes and dimensions:

  • 1D: Sequences (NLP, audio, bio-signal).
  • 2D: Images (windows, patches).
  • 3D+: Videos, multi-modal. Variable chunk/shift size per layer or per head increases flexibility. Design choices include:
  • Shift amount (usually P=N/wP=N/w9) for optimal overlap.
  • Cyclic or zero-padding for wrapping, affecting border effects and context propagation.
  • Scale selection and feature fusion for multi-scale designs.
  • Combination with dilated/simple sparse patterns for maximum receptive field at sub-quadratic cost (Cheng et al., 2023, Guo, 2023).

Receptive field, latency, and memory footprint can be directly controlled via chunk size, shift strategy, and number of alternations, providing a tunable front for latency-accuracy trade-off critical in streaming, incremental, and edge deployment contexts (Wang et al., 2022, Du et al., 2024).


References:

  • (Cheng et al., 2023) "MSW-Transformer: Multi-Scale Shifted Windows Transformer Networks for 12-Lead ECG Classification"
  • (Wang et al., 2022) "Shifted Chunk Encoder for Transformer Based Streaming End-to-End ASR"
  • (Zha et al., 2021) "Shifted Chunk Transformer for Spatio-Temporal Representational Learning"
  • (Guo, 2023) "SCCA: Shifted Cross Chunk Attention for long contextual semantic expansion"
  • (Du et al., 2024) "Incremental FastPitch: Chunk-based High Quality Text to Speech"

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Shifted Chunk Transformer.