pytensor_ml.model.Model.compile_train#
- Model.compile_train(rule, loss_fn=None, compile_kwargs=None, *, loss=None, inputs=None, extra_outputs=None)#
Compile a one-step training function, either against a supervised target or a prebuilt loss.
Given
loss_fn, builds a target placeholder from the model output withsupervised_loss()and the step is called with one batch per data input the graph reads, then the target – for the usual single-input model,step(X_batch, target_batch). Givenlossinstead, trains that graph directly, which is what an autoencoder or a language-model objective needs – neither has a target separate from its input. Either way the step applies every update in place.- Parameters:
- rule
Transform A configured optimizer, e.g.
adam(1e-3).- loss_fn
Loss, optional Callable
(target, prediction) -> scalar loss. Mutually exclusive withloss.- compile_kwargs
dict, optional Keyword arguments forwarded to the function compiler. Defaults to the model’s own compile kwargs.
- loss
TensorVariable, optional A scalar loss graph built over this model’s output. Mutually exclusive with
loss_fn.- inputssequence of
Variable, optional Data inputs of the step, in call order. Collected from
losswhen omitted. Belongs to the prebuilt path; the supervised path derives its own.- extra_outputssequence of
Variable, optional Diagnostics to return alongside the loss, as in
compile_train().
- rule
- Returns:
- step
Function The compiled one-step training function. Returns the loss alone, or
(loss, *extra_outputs)when diagnostics were requested.
- step