The transformer architecture describes an encoding phase and decoding phase.This has been used to create three different classes of encoder models: encoder only models, encoder-decoder models, and decoder-only models.
Encoder models are popular for learning embeddings used in classification tasks
Examples includes Google’s BERT and Meta’s RoBERTa
Encoder-decoder models were originally designed for generative tasks like translation or summarization, where input and output are strongly connected.
Google’s Flat-T5 is one example of a encoder-decoder model
Decoder-only models are used for generative tasks, particurly conversational AI and text generation
GPT-x are all examples of decoder-only models
Modern LLMs are predominantly based on Transformer Architecture or a derivitave
The main advantage of Transformer Architecture (over others like recurrrent neural networks (RNNs)), is that it doesn’t have recurring units. This means it doesn’t use the output of one neuron as the input to another. This makes it highly parallelizable during training.
After we break the input down into tokens, we are ready for the embedding phase
Embedding is a process that generates a vector representation of the input, capturing its semantic meaning
This means the distance between two vectors is smaller if they represent semantically similar inputs, and larger if the inputs are not strongly related
As an example, consider the words dog and puppy. They are related to each other, so their embedding representations produce vectors with a smaller distance compared to the embeddings dog and car.
From a high level, the end-to-end inference pipeline has two steps: prefill and decode.
The prefill phase tokenizes the input, applies embedding, and generates the first token.
The decode phase generates the tokens one by one and computes the output text.
Both phases use the model in the same way to produce a token. However, the decoding phase produces on token at a time, while the prefill phase is done in parallel. This makes the prefill workload compute-bound, while the decode phase is memory-bound.
After prefill, the user’s prompt is parsed, loaded, and the first token is produced with a signle forward pass of the neural net.
The decode phase is in charge of the generation of the rest of the tokens until the end-of-stream is encountered.
The decode phase cannot be parallelized and it has to proceed one token at a time because of the autoregressive nature of generation. Autoregressive means that each generated token is based on the previous sequence and becomes part of th eprevious state used to generate the next one.