# After adding Flux package, why is it necessary to also add Zygote

**URL:** https://discourse.julialang.org/t/after-adding-flux-package-why-is-it-necessary-to-also-add-zygote/36983
**Category:** Machine Learning
**Created:** [April 3, 2020, 8:35pm UTC](https://discourse.julialang.org/t/after-adding-flux-package-why-is-it-necessary-to-also-add-zygote/36983 "2020-04-03T20:35:13Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![jaynick](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jaynick](https://discourse.julialang.org/u/jaynick)
#### Post date: [April 3, 2020, 8:35pm UTC](https://discourse.julialang.org/t/after-adding-flux-package-why-is-it-necessary-to-also-add-zygote/36983/1 "2020-04-03T20:35:13Z")

</div>

This is a beginner/tooling question about packages, but if I post it there people will not know the particular packages.

The question: I want to use Zygote.@nograd, so I put  
`using Zygote`  
however this says that it is required to Pkg.add(“Zygote”) first.

I find this surprising, since Flux already depends on Zygote, so it must in some sense be added already - why does it need to be added “again”?

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [April 3, 2020, 8:42pm UTC](https://discourse.julialang.org/t/after-adding-flux-package-why-is-it-necessary-to-also-add-zygote/36983/2 "2020-04-03T20:42:41Z")

</div>

What version of Flux are you using? If it’s \<0.10, it doesn’t use zygote.

---

<div class="post-metadata">

### Author: ![jaynick](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jaynick](https://discourse.julialang.org/u/jaynick)
#### Post date: [April 4, 2020, 11:10pm UTC](https://discourse.julialang.org/t/after-adding-flux-package-why-is-it-necessary-to-also-add-zygote/36983/3 "2020-04-04T23:10:13Z")

</div>

This was on 0.10.3/Julia1.3.1

---

<div class="post-metadata">

### Author: ![jstrube](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jstrube/32/525_2.png) [@jstrube](https://discourse.julialang.org/u/jstrube)
#### Post date: [April 5, 2020, 12:00am UTC](https://discourse.julialang.org/t/after-adding-flux-package-why-is-it-necessary-to-also-add-zygote/36983/4 "2020-04-05T00:00:15Z")

</div>

I’m not exactly sure about the nomenclature here, so I hope what I’m saying isn’t too confusing (or inaccurate), but adding Flux downloads Zygote, but it doesn’t put it into your Project.toml.  
If you look at `] status`, you’ll see all of the packages that you immediately `add`ed. You don’t see all of the packages that were also downloaded as their dependencies, only the ones that you `add`ed yourself. Those are the ones available with `using`. If you do `add Zygote`, the package gets registered in your Project.toml, but if you already have it as a dependency for Flux, it doesn’t get downloaded again.

---

<div class="post-metadata">

### Author: ![jaynick](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jaynick](https://discourse.julialang.org/u/jaynick)
#### Post date: [April 5, 2020, 12:38am UTC](https://discourse.julialang.org/t/after-adding-flux-package-why-is-it-necessary-to-also-add-zygote/36983/5 "2020-04-05T00:38:20Z")

</div>

that is helpful, Thank you

---

<div class="post-metadata">

### Author: ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)
#### Post date: [April 5, 2020, 9:05am UTC](https://discourse.julialang.org/t/after-adding-flux-package-why-is-it-necessary-to-also-add-zygote/36983/6 "2020-04-05T09:05:47Z")

</div>

To add to @jstrube’s explanation: the idea is that your code doesn’t get to depend on transitive dependencies (i.e. dependencies of dependencies) without explicitly declaring it. After all, your dependencies’ dependencies are allowed to change without letting you know!

Therefore, if you also have a direct dependency on, in this case, `Zygote`, then you have to `]add` it. But that’s purely administrative; it doesn’t get downloaded or pre-compiled again, and it will be the same version as what `Flux` is using.

Edit/Afterthought: in this case, you can actually also do `using Flux.Zygote: @nograd` without adding `Zygote` as your own dependency. That’s a nice way of showing that you are using `Zygote` only because it is `Flux`’s dependency.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [April 5, 2020, 9:13am UTC](https://discourse.julialang.org/t/after-adding-flux-package-why-is-it-necessary-to-also-add-zygote/36983/7 "2020-04-05T09:13:04Z")

</div>

> [@tkluck](#):
>
> you can actually also do `using Flux.Zygote: @nograd` without adding `Zygote` as your own dependency

I would treat this as an implementation detail, and add and use Zygote explicitly.

---

<div class="post-metadata">

### Author: ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)
#### Post date: [April 5, 2020, 9:28am UTC](https://discourse.julialang.org/t/after-adding-flux-package-why-is-it-necessary-to-also-add-zygote/36983/8 "2020-04-05T09:28:43Z")

</div>

> [@Tamas\_Papp](#):
>
> I would treat this as an implementation detail, and add and use Zygote explicitly.

Technically, I disagree: If I’m using `Zygote` _because_ `Flux` uses it, then I should allow `Flux` to change to another AD backend as long as it keeps on making the same API available to me under `Flux.Zygote`. edit: because I’m already not treating it as an implementation detail if I’m relying on it!

But in practice I agree: it’s rather impractical to be backwards compatible with the full implementation of one of your dependencies _while_ switching dependencies, so `Flux` would just do a breaking release anyway (just like they did when introducing `Zygote`). So being technically correct probably has zero benefit in practice.

---

<div class="post-metadata">

### Author: ![jaynick](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jaynick](https://discourse.julialang.org/u/jaynick)
#### Post date: [April 7, 2020, 5:02am UTC](https://discourse.julialang.org/t/after-adding-flux-package-why-is-it-necessary-to-also-add-zygote/36983/9 "2020-04-07T05:02:16Z")

</div>

this makes sense (that it forces you to explicitly use transitive dependencies)
