Runs a model forward pass with explicit variables and inputs, instead of keeping parameters inside the module. It replaces older predict-style calls and can also return updated mutable state when the model has one. section 11.1.1 section 11.4 section 11.2.1
Typical use here is to swap in apply() at the places that need model outputs during training and evaluation.
- Call it on an instantiated Module with initialized variables and input data. section 11.1.1 section 11.4
- Use it in the loss function and accuracy calculation instead of predict(). section 11.1.1
- Pass mutable collections when layers like BatchNorm need state updates. section 11.2.1
MLP forward pass
An MLP is initialized from a dummy input, then model.apply(params, images) produces logits for the loss function and training update step. section 11.1.1 section 11.4
Model state update
With mutable state, apply_fn receives {'params': params, **model_state}, an input batch, mutable keys, and train=True, then returns output plus updated state. section 11.2.1
