Cross Zamirski Model Training#26
Open
MattsonCam wants to merge 8 commits into
Open
Conversation
added 8 commits
June 8, 2026 13:21
wasserstein GAN GP models
Wrap the discriminator-step generator forward in torch.no_grad() and remove the now-redundant detach on the fake samples passed to the critic loss. This preserves the two-step WGAN-GP training behavior while avoiding construction of an unnecessary generator autograd graph during the critic update, reducing memory and compute overhead.
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
gwaybio
approved these changes
Jun 8, 2026
wli51
approved these changes
Jun 8, 2026
wli51
left a comment
There was a problem hiding this comment.
LGTM! Maybe the trainer should support differential stepping frequency between discriminator and generator?
Comment on lines
+90
to
+122
| with torch.no_grad(): | ||
| fake_targets_for_discriminator = self.image_postprocessor( | ||
| self.generator(inputs) | ||
| ) | ||
| discriminator_outputs = self.discriminator_loss( | ||
| critic=self.discriminator, | ||
| real_samples=targets, | ||
| fake_samples=fake_targets_for_discriminator, | ||
| ) | ||
| discriminator_loss, discriminator_components = self._detach_components( | ||
| discriminator_outputs | ||
| ) | ||
|
|
||
| self.discriminator_optimizer.zero_grad() | ||
| discriminator_loss.backward() | ||
| self.discriminator_optimizer.step() | ||
|
|
||
| generated_predictions = self.image_postprocessor(self.generator(inputs)) | ||
| fake_classification_outputs = self.discriminator(generated_predictions) | ||
| generator_outputs = self.generator_loss( | ||
| fake_classification_outputs=fake_classification_outputs, | ||
| generated_predictions=generated_predictions, | ||
| targets=targets, | ||
| epoch=epoch, | ||
| loss_mask=batch_data.get("loss_mask"), | ||
| ) | ||
| generator_loss, generator_components = self._detach_components( | ||
| generator_outputs | ||
| ) | ||
|
|
||
| self.generator_optimizer.zero_grad() | ||
| generator_loss.backward() | ||
| self.generator_optimizer.step() |
There was a problem hiding this comment.
I don't remember the Cross-Zamirski trainer implementation that well, is equal number of update frequencies what they decided on. I believe in classical wGAN training the discriminator gets updated more frequently than the generator for stability.
Member
Author
There was a problem hiding this comment.
I think you're right, I will update this. I know if degrades the loss contribution by normalize by the epoch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pr includes the cross zamirski model and the structure needed for training. It also include per-batch logging and removes irrelevant code. This code may change in the future to allow for training on Alpine due to the cuda memory constraint. As a result batch size has been reduced.