Skip to content

Fix runtime errors in vbgan.py#1

Open
lxt3 wants to merge 3 commits into
NCTUMLlab:masterfrom
lxt3:VBGAN_update
Open

Fix runtime errors in vbgan.py#1
lxt3 wants to merge 3 commits into
NCTUMLlab:masterfrom
lxt3:VBGAN_update

Conversation

@lxt3

@lxt3 lxt3 commented Nov 23, 2025

Copy link
Copy Markdown

Proposed fix for: RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [128]] is at version 3; expected version 2 instead

  1. Separate forward passes for the encoder and decoder updates
  2. Freeze encoder and use x.detach() for decoder pass: After stepping the encoder, its batch-norm statistics are updated. By freezing encoder parameters, detaching the input, and recomputing the forward pass, the decoder receives a fresh computation graph that ignores the encoder’s updated state. This avoids the “in-place modification” runtime error.
  3. No retain_graph: Because each backward now uses its own fresh forward pass, the graph is rebuilt every time. No shared graph means no need to retain it

Also, pass in empty list to parse_args(): args = parser.parse_args([])

lxt3 and others added 3 commits January 12, 2024 18:54
pass in empty list to parse_args()
…ent computation has been modified by an inplace operation: [torch.cuda.FloatTensor [128]] is at version 3; expected version 2 instead

1. Separate forward passes for the encoder and decoder updates

2. Freeze encoder and use x.detach() for decoder pass:
After stepping the encoder, its batch-norm statistics are updated. By freezing encoder parameters, detaching the input, and recomputing the forward pass, the decoder receives a fresh computation graph that ignores the encoder’s updated state. This avoids the “in-place modification” runtime error.

3. No retain_graph:
Because each backward now uses its own fresh forward pass, the graph is rebuilt every time. No shared graph means no need to retain it
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