Truncated Backprop-Through-Time (TBPTT) via tvboptim
Why the exact FC-loss gradient breaks past the chaos onset, and how a single integration.differentiation window fixes it. Everything below — the diagnostics swept over the global coupling \(G\) (loss, autodiff gradient, finite-difference ground truth, top Lyapunov exponent) and both optimization legs — is derived from one experiment YAML via exp.run; only the plotting is hand-written.
import osdevice_count = os.environ.get("TVBO_XLA_DEVICE_COUNT", "8")os.environ["XLA_FLAGS"] =f"--xla_force_host_platform_device_count={device_count}"import jaxjax.config.update("jax_enable_x64", True)from tvbo import SimulationExperimentfrom tvbo.datamodel.schema import Differentiationexp = SimulationExperiment.from_db("TBPTT_JansenRit_FC_Optimization")# Trim the long production rollout so the page builds in reasonable time. These are# plain config values on the same YAML — no per-point driver: the diagnostics sweep# and both descent legs are still computed entirely by exp.run.exp.integration.duration =6000.0exp.integration.transient_time =1000.0exp.observations["fc"].pipeline[0].arguments["skip_t"].value =4# BOLD samples skipped before FCexp.optimizations["fit_G"].stages[0].max_iterations =40# TBPTT leg: the YAML declares differentiation = {truncation_window: 100, mode: reverse},# so this run uses Heun(grad_horizon=100) + reverse-mode == truncated BPTT. It also# computes the motivation sweep (the diagnostics vs G).tbptt = exp.run("tvboptim", n_G=48)# Full-AD leg: identical YAML, forward-mode, no truncation window (forward-mode AD# equals full reverse-mode BPTT for the scalar G — the exact, untruncated gradient).exp.integration.differentiation = Differentiation(mode="forward")ad = exp.run("tvboptim", mode="optimization")
Figure 1: TBPTT for whole-brain gradient fitting. (L) FC-RMSE loss (blue) and top Lyapunov exponent (red) vs global coupling G; λ_max crosses zero at the chaos onset. (R) The exact reverse-mode AD gradient (symlog) tracks the seed-averaged finite-difference ground truth until chaos, where it blows up by orders of magnitude. (T) Fitting G by gradient descent: full AD (red) is thrown off by the corrupted gradient, while the windowed TBPTT run (green) descends cleanly; the grey profile is the RMSE(G) landscape. (S) grad_horizon tiles the rollout — every window contributes ∂L_k/∂G but the carried-state gradient is cut at each boundary. (A–C) Simulated FC at the fitted G vs the empirical target.