Skip to content

fix(networks): VAEGen.forward must unpack encode tuple (+3 more) - #83

Open
andrewwhitecdw wants to merge 2 commits into
NVlabs:masterfrom
andrewwhitecdw:bugfix/networks-assorted-da0a8d02
Open

fix(networks): VAEGen.forward must unpack encode tuple (+3 more)#83
andrewwhitecdw wants to merge 2 commits into
NVlabs:masterfrom
andrewwhitecdw:bugfix/networks-assorted-da0a8d02

Conversation

@andrewwhitecdw

@andrewwhitecdw andrewwhitecdw commented Jul 27, 2026

Copy link
Copy Markdown

Small fixes in networks.py:

fix: VAEGen.forward must unpack encode tuple

Fix: Replace:

        hiddens = self.encode(images)
        if self.training == True:
            noise = Variable(torch.randn(hiddens.size()).cuda(hiddens.data.get_device()))

with:

        hiddens, _ = self.encode(images)
        if self.training == True:
            noise = Variable(torch.randn(hiddens.size()).cuda(hiddens.data.get_device()))

fix: LayerNorm fp16 branch normalizes across batch

Fix: Replace:

        if x.type() == 'torch.cuda.HalfTensor': # For Safety
            mean = x.view(-1).float().mean().view(*shape)
            std = x.view(-1).float().std().view(*shape)
            mean = mean.half()
            std = std.half()

with:

        if x.type() == 'torch.cuda.HalfTensor': # For Safety
            mean = x.view(x.size(0), -1).float().mean(1).view(*shape).half()
            std = x.view(x.size(0), -1).float().std(1).view(*shape).half()

fix: replace removed F.sigmoid with torch.sigmoid

Fix: Replace:

                loss += torch.mean(F.binary_cross_entropy(F.sigmoid(out0), all0) +
                                   F.binary_cross_entropy(F.sigmoid(out1), all1))
                reg += LAMBDA* self.compute_grad2(F.sigmoid(out1), input_real).mean()

with:

                loss += torch.mean(F.binary_cross_entropy(torch.sigmoid(out0), all0) +
                                   F.binary_cross_entropy(torch.sigmoid(out1), all1))
                reg += LAMBDA* self.compute_grad2(torch.sigmoid(out1), input_real).mean()

fix: WGAN squeeze removes batch dim when batch=1

Fix: Replace:

        else:
             outputs = self.cnn(x)
             outputs = torch.squeeze(outputs)
        return outputs

with:

        else:
             outputs = self.cnn(x)
             outputs = outputs.view(outputs.size(0), -1).squeeze(-1)
        return outputs

Files changed

  • networks.py

andrewwhitecdw and others added 2 commits July 27, 2026 07:24
Auditor: The diff contains two extra, unrelated changes not described in the stated problem: (1) altering the CNN output squeezing logic with a potentially behavior-changing `outputs.view(outputs.size(0), -1).squeeze(-1)`, and (2) replacing `F.sigmoid` with `torch.sigmoid`. Only the VAEGen tuple unpack and LayerNorm fp16 batch-normalization fixes were stated. A PR should be focused; these unrelated changes make it off-scope and risky.
@andrewwhitecdw
andrewwhitecdw marked this pull request as ready for review August 3, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant