# Ignore\_derivatives of entire module with ChainRules.jl

**URL:** https://discourse.julialang.org/t/ignore-derivatives-of-entire-module-with-chainrules-jl/95341
**Category:** Performance
**Created:** [February 28, 2023, 3:30pm UTC](https://discourse.julialang.org/t/ignore-derivatives-of-entire-module-with-chainrules-jl/95341 "2023-02-28T15:30:32Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hshackle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hshackle/32/47114_2.png) [@hshackle](https://discourse.julialang.org/u/hshackle)
#### Post date: [February 28, 2023, 3:30pm UTC](https://discourse.julialang.org/t/ignore-derivatives-of-entire-module-with-chainrules-jl/95341/1 "2023-02-28T15:30:32Z")

</div>

I’m trying to get reverse differentiation up and running on some simulations. Central to the code is a module that does a lot of array manipulation and bit shifting, which are things that Zygote.jl will complain about. None of this is relevant for actually computing the gradients that I want, so I’m trying to figure out how to just wrap the entire module with an `ignore_derivatives` command. Is there a concise way of doing this without having to add it inside every function? I’ve tried a few different ways but I can’t seem to get the syntax right.

---

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [February 28, 2023, 4:06pm UTC](https://discourse.julialang.org/t/ignore-derivatives-of-entire-module-with-chainrules-jl/95341/2 "2023-02-28T16:06:33Z")

</div>

The hacky “lets not think about this” way is to do some code generation.  
You can use something like

```julia
for name in names(MyModule; all=true)
    func = getfield(MyModule, name)
    !isempty(methods(func)) && continue # not actually a function
    
    println("@non_differentiable $name(args...; kwargs...)")
end

```

to create a nice file with them all filled in.  
Though probably you just need to define it for some of the functions.

* * *

`@ignore_derivatives` can only be applied to function calls. Not to modules or function definitions.  
You could use MacroTools or MLStyle.jl to recursively match your code AST looking for calls.  
But it is definately not trivial.  
Could be good excuse to use the 2 argument form of `include` though.
