I guess the simplest way is to implement a custom autograd function here:
class CheapF(autograd.Function):
  @staticmethod
  def forward(ctx, *args):
    return g(*args)

  @staticmethod
  def backward(ctx, *grad_outs):
    return f_backward(*grad_outs)

# Use it as
outputs = CheapF.apply(inputs)

Note that you will need to implement the backward of f yourself. You cannot rely on the autograd to do it for you as you never computed the forward operation.