An MWE would be useful, but generally I would just add a wrapper that adds units, calls the relevant function, and then removes units, and AD that.