How does AI inference work?
AI inference is the part of the ML process where ML models ideally start delivering useful output to users. At a high level, the process of applying inference to a model input works through a three-step process. The first step is normalization, the second is execution, and the third is output.
1. Normalization
Before a model is ready to process an input, the model or the code that supports it needs to normalize the input into a format that it knows how to process. For instance, if the ML model is a LLM, then the data is converted into tokens via a tokenizer.
For an image-processing model, the size of the image may be converted to a standard size that is identical to what the model was provided with during the training process.
The normalization process prepares data so that the ML model can process it cleanly, quickly, and efficiently. By getting the data as close as possible to the format the model expects, the software maximizes the likelihood of returning high-quality, useful output for the user.
2. Execution
Once the data has been normalized into a format that is similar to what the model was trained on, the second step of the process is model execution.
The simplest way to describe this step of the process is that it is an extremely complicated game of pattern matching across a very high number of parameters. Parameters are decision nodes that are developed during the model training process.
Modern ML models can have trillions of these parameters. As the model executes, the data is passed to these parameters and evaluated to identify whether the input matches the pattern that led to that parameter during the training process.
It is important to note that at this phase, the model does not “learn” from any particular message. ML models primarily learn during the training phase.
Models can be improved during the inference phase by improving the context provided to the model or by updating model weights in the running model. But if neither the model nor a human changes the weights of the model based on responses to the outputs, the model’s output will not change substantially.
3. Output
This is the part of the AI inference process that is helpful to the user. After the model has gone through the execution phase by fully processing the input, the model now offers output to the user. Output can appear in several different formats.
LLMs often return text, familiar to many users through tools like ChatGPT. Other tools like Stable Diffusion instead offer an image in response to the user’s input. More traditional ML models offer more technical responses.
For instance, an insurance company may take dozens of inputs related to a customer requesting a quote and run those through a ML model to answer the question of how much lifetime profit selling a policy to that customer will return to the company.
As noted in the previous section, just because the training phase is over doesn’t mean that performance of the model can’t be improved during this phase. Model providers will often ask for feedback on the output of a model in order to further tune behaviors of the running model.