Added a way to save gradient across multiple passes, and ignore unobserved outputs.