pub struct LossContext<'a> {
pub output: &'a Variable,
pub batch: &'a Batch,
pub tags: &'a HashMap<String, Variable>,
pub traces: &'a HashMap<String, Vec<Variable>>,
}Expand description
Context passed to the per-batch loss closure during El Che distributed training. All fields carry live autograd graphs, so the returned loss scalar can be backpropagated immediately.
ⓘ
model.set_loss_fn(|ctx: &LossContext| {
let cls = cross_entropy_loss(&ctx.tags["head"], &ctx.batch["label"])?;
let rec = mse_loss(&ctx.tags["recon"], &ctx.batch["image"])?;
Ok(cls + rec)
});Fields§
§output: &'a VariableForward output (live autograd).
batch: &'a BatchThe per-device batch with all named fields (inputs + targets).
Tagged outputs from this forward pass (live autograd).
traces: &'a HashMap<String, Vec<Variable>>Loop traces keyed by tag name (live autograd).
Auto Trait Implementations§
impl<'a> Freeze for LossContext<'a>
impl<'a> !RefUnwindSafe for LossContext<'a>
impl<'a> !Send for LossContext<'a>
impl<'a> !Sync for LossContext<'a>
impl<'a> Unpin for LossContext<'a>
impl<'a> UnsafeUnpin for LossContext<'a>
impl<'a> !UnwindSafe for LossContext<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more