code: def trace_df_dz(f, z):
      """Calculates the trace of the Jacobian df/dz.
      Stolen from: https://github.com/rtqichen/ffjord/blob/master/lib/layers/odefunc.py#L13
      """
      sum_diag = 0.0
      for i in range(z.shape[1]):
          sum_diag += (
              torch.autograd.grad(f[:, i].sum(), z, create_graph=True)[
                  0
              ]
              .contiguous()[:, i]
              .contiguous()
          )
  
      return sum_diag.contiguous()
  
imports: import os
  import argparse
  import glob
  from PIL import Image
  import numpy
  import matplotlib
  import matplotlib.pyplot
  from sklearn.datasets import make_circles
  import torch
  import torch.nn
  import torch.optim
label_desc: Use image node_id 1 for calling a global function with example usage: trace_df_dz(f, z) and returns: sum_diag