1. Mathematical Formulation of the Forward Pass
A decoder-only transformer model defines a parameterized mapping fθ: 𝒳 → 𝒴, where 𝒳 is the input token space and 𝒴 is the output probability distribution over the vocabulary. Given an input sequence represented as token embeddings X ∈ ℝn × dmodel, the forward pass executes an ordered composition of linear projections, non-linear activations, and tensor contractions across L transformer blocks.
Within each block l, the scaled dot-product attention mechanism computes relational dependencies across the sequence length n.
Here M ∈ ℝn × n denotes the causal mask enforcing autoregressive constraints, setting upper-triangle values to negative infinity to prevent attending to future tokens [1]. Following multi-head projection and residual addition, the representation passes through a position-wise multilayer perceptron (MLP) or feed-forward network (FFN):
where σ represents a non-linear activation function such as SiLU or GELU. The final hidden state hn at the terminal sequence position is projected onto the vocabulary dimension to generate raw logits z:
These logits are mapped to a probability simplex via the softmax operator:
2. Numerical Execution and IEEE 754 Non-Associativity
At the physical hardware level, these tensor operations execute on accelerator architectures (GPUs/TPUs) utilizing finite-precision floating-point representations such as FP16, BF16, or FP32 governed by the IEEE 754 standard [2, 3].
A critical mechanical reality of floating-point arithmetic is the failure of associativity:
Because intermediate summation steps incur rounding errors, parallel reduction schedules,
thread-block scheduling variations in CUDA kernels, compiler-level operation reassociation,
and atomic accumulation (such as atomicAdd
in parallel matrix multiplications) can alter the precise numerical values of intermediate activation tensors [2, 4].
Consequently, while the algorithmic graph may remain deterministic, exact bitwise reproducibility across heterogeneous hardware nodes or disparate runtime configurations is not guaranteed without strict environmental locking [2].
3. Causal Mechanics and Interventional Validation
To establish that internal vector representations causally mediate model outputs rather than serving merely as epiphenomena, mechanistic interpretability employs interventional frameworks such as activation patching [5].
Given a baseline clean run generating output distribution M(x) and a corrupted or counterfactual run, an internal activation ai at a specified layer and token position is substituted:
The resulting change in output behavior can then be measured as an intervention-dependent divergence:
The measured divergence provides evidence about the causal contribution of the intervened component. Empirical findings from activation-patching research demonstrate that model behavior can shift predictably under targeted internal-vector manipulation, providing a mechanistic route for studying how information is represented and transformed throughout high-dimensional computational spaces [5].
↓
EMBEDDING SPACE
↓
ATTENTION + CAUSAL MASKING
↓
RESIDUAL TRANSFORMATIONS
↓
NON-LINEAR REPRESENTATION
↓
VOCABULARY LOGITS
↓
SOFTMAX DISTRIBUTION
↓
NEXT-TOKEN INFERENCE
Sources
- Vaswani, A. et al., Attention Is All You Need, Advances in Neural Information Processing Systems (NeurIPS 2017).
- IEEE, IEEE Standard for Floating-Point Arithmetic, IEEE Std 754-2019.
- NVIDIA, Floating Point and IEEE 754, NVIDIA CUDA Documentation.
- PyTorch Foundation, Reproducibility Documentation, PyTorch Developer Documentation.
- Zhang, M. et al., How to Use and Interpret Activation Patching, arXiv:2404.15255.
No comments:
Post a Comment