Tullio.jl icon indicating copy to clipboard operation
Tullio.jl copied to clipboard

Way to Disable Gradient Calculations "By Default"

Open ParadaCarleton opened this issue 4 years ago • 3 comments

My code won't require gradient calculations. Is there a way to disable gradient calculations for a large block of code, or to set the gradient calculations to be off unless I specifically request them?

ParadaCarleton avatar Jun 10 '21 15:06 ParadaCarleton

Yes, if you write @tullio grad=false with no expression to calculate, this should update a global setting, which will apply to all subsequent macro calls. (It isn't per-module or anything, perhaps a little fragile?)

mcabbott avatar Jun 10 '21 16:06 mcabbott

Yes, if you write @tullio grad=false with no expression to calculate, this should update a global setting, which will apply to all subsequent macro calls. (It isn't per-module or anything, perhaps a little fragile?)

Hmm -- yeah, if the setting is 100% global and not limited to a module or function, I'll make sure to avoid using that, since it could cause other people's code to break otherwise.

ParadaCarleton avatar Jun 10 '21 19:06 ParadaCarleton

It got written mostly as a way to run the same tests with different settings for gradients / threads / LoopVectorization etc. I agree it's not exactly an enterprise-grade mechanism, but sometimes handy for scripts etc. when you are in control. Or wish to temporarily disable something to debug.

Note that the gradient computation is just that, at macro expansion time, it generates a second set of functions by symbolically differentiating the right hand side of the given expression. These functions will never be called unless you take a derivative, never even compiled. That's why the default of always doing this makes some sense.

mcabbott avatar Jun 11 '21 14:06 mcabbott