Causal vs. Bidirectional Architectures in Generative Modeling
If a model is trained to be fully bidirectional during the training phase, it risks "cheating" by seeing the ground truth it is meant to predict. This raises a critical question for developer experience: how do we bridge the gap between the deep contextual nuance of bidirectional encoders and the fluid, sequential requirements of autoregressive decoders? The industry has largely optimized for the latter because the computational efficiency during inference is highly predictable for token-by-token generation.
I attempted to validate this by modifying a standard decoder-only setup to incorporate a bidirectional attention mask, aiming to see if increased coherence could be achieved in local fine-tuning. My hypothesis was that richer context windows would mitigate certain coherence failures. However, the implementation triggered a tensor mismatch during the forward pass:
RuntimeError: The size of tensor a (1024) must match the size of tensor b (1024) at non-singleton dimension 1
This error suggests a deep structural friction between the mask application and the positional embeddings. It seems that forcing non-causal attention into a decoder-based framework isn't just a matter of adjusting the mask; it potentially disrupts the way the model interprets sequence positionality. We are effectively trying to force a generative architecture to behave like an encoder, which may be why we see such a performance gap between NLU and NLG tasks.
For those working on custom transformer implementations, I recommend reviewing the original attention mechanism specifications to see how masking interacts with the scaling factors in the softmax layer.
https://arxiv.org/abs/1706.03762