Comments (8)
Thanks!
We use two different optimizers for the autoencoder part and the discriminator part, respectively. Furthermore, both optimizers have different optimiziation steps specified by the optimizer_idx
(see taming.modules.losses.vqperceptual
), so the discriminator should only receive updates when optimizer_idx = 1
.
from taming-transformers.
I was asking myself the same thing. From what I understand from the lightning docs, they are called sequentially one after another in turn. At least unless users choose to overwrite this behaviour which I did not find in this repo.
from taming-transformers.
thanks for getting back to me on this one.
I understand the procedure you described, the optimizer index being owed to the fact that you use Lightning and all.
However, I am still convinced that the critic is receiving gradients in the backward pass before performing the step of the first optimizer since there is no disabling of its gradients anywhere before. That would mean that when its the critics turn to get its weights updated it would do this with gradients from both the backward pass through it all the way down to the VQVAE and from its own backward pass in the second stage of optimizing.
Unless I am missing sth. here (maybe lightning does something behind the curtain) I would find this rather peculiar since usually the critics weights are frozen when it is just judging the generators outcome...
from taming-transformers.
That is not correct, since the reconstructions are detached from the computation graph before passing them to the discriminator:
if cond is None:
logits_real = self.discriminator(inputs.contiguous().detach())
logits_fake = self.discriminator(reconstructions.contiguous().detach())
else:
logits_real = self.discriminator(torch.cat((inputs.contiguous().detach(), cond), dim=1))
logits_fake = self.discriminator(torch.cat((reconstructions.contiguous().detach(), cond), dim=1))
So the gradients just flow through the discriminator and then stop at the point where the inputs were detached, and no need to freeze the model.
(And of course, when training the vqVAE you cannot freeze the discriminator since you want the gradients to flow up to the model)
from taming-transformers.
@rromb Simple question,
I've understood that different optimizer steps are applied via "optimizer_idx". But, since I'm not used to PyTorch lightening, I am having trouble finding when the "optimization steps" are toggled. Can you tell me where the value of the "optimizer_idx" changes?
from taming-transformers.
@CDitzel Umm, I see. Thank you for your answer :)
from taming-transformers.
The code defining the two optimizers is in the VQGAN pl module. Just in case somone has the same issue.
taming-transformers/taming/models/vqgan.py
Line 121 in 2426893
from taming-transformers.
Pytorch-lighting dotoggle_optimizer
and untoggle_optimizer
to control which parameters to update. https://github.com/Lightning-AI/lightning/blob/1.8.0/src/pytorch_lightning/core/module.py#L1408-L1453
from taming-transformers.
Related Issues (20)
- Simply concatenating the source indices and condition indices even when they are from different codebooks? HOT 2
- How to do image inpainting with vqgan?
- How to train the transformer after training the vqgan model? HOT 9
- If my condition is class label, how to set config file
- Cannot use gpu to fine-tune on custom-data HOT 2
- gpu training hangs HOT 2
- Where is the model trained on my custom data? HOT 1
- When I train, the code is getting slower and slower, is it normal? HOT 1
- README Error -- yaml path
- Dockerfile/environment.yaml for CUDA Version 12.3? HOT 5
- 'VQModel' object has no attribute 'transformer'
- How to train your own Transformer
- How to distinguish sos token(default = 0) and quantified image token zero ?
- How to use the sliding attention window mechanism? HOT 3
- Is there a plan to upgrade this repo to Pytorch 2.0
- ModuleNotFoundError: No module named 'cutlit'
- ncc HOT 1
- Confusion about the dimension of latent vectors
- generate white images during training HOT 1
- : Parameter indices which did not receive grad for rank 0: 338 339 340 341 342 343 344 345 346 347 348 349 350 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from taming-transformers.