// Author: Simon-Pierre Boucher — contact@spboucher.ai #include "core/autograd.h" #include #include namespace forge { Tape& Tape::get() { static Tape tape; return tape; } void Tape::backward(const Var& loss) { if (loss.value().numel() != 1) { std::fprintf(stderr, "forge: backward() needs a scalar loss\n"); std::abort(); } loss.grad().fill_(1.0f); for (auto it = nodes_.rbegin(); it != nodes_.rend(); ++it) (*it)(); clear(); } } // namespace forge