liveBook · Manning

Model.stateless_call()

As explained in Deep Learning with R, Third Edition

stateless_call is a Keras model method that computes outputs from explicit inputs and weights while returning updated nontrainable weights.

model.stateless_call() performs a model forward pass from explicit trainable and nontrainable weights, inputs, and training arguments. It returns outputs together with updated nontrainable weights, making forward computation compatible with stateless programming. section 7.4.2

Using the method in a JAX loss function

A loss function can call model.stateless_call(), compute the loss, and return both the scalar loss and updated nontrainable variables. Passing this function to jax$value_and_grad(..., has_aux = TRUE) produces gradients while preserving those updates. section 7.4.2

How Deep Learning with R, Third Edition covers it

How deep it goes
Defines inputs and returned state, then demonstrates integration with value_and_grad; it stops short of explaining internal layer execution.
Examples
Demonstrates an R Keras MNIST model with sparse categorical cross-entropy inside compute_loss_and_updates().
What it assumes
Assumes familiarity with Keras models, trainable and nontrainable weights, losses, and JAX value-and-grad transformations.
What you can do after
Build a JAX-compatible loss function that returns model outputs, updated nontrainable weights, and differentiable loss values.
How it connects
Connects stateless programming, JAX, nontrainable weights, automatic differentiation, and custom training steps.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.