Skip to content

Backward pass not working #2

@Pibborn

Description

@Pibborn

Hi,

Running train.py runs into the following issue below:

/VAEs/Tabular/DCEVAE_ours/venv/lib64/python3.8/site-packages/torch/autograd/__init__.py:173: UserWarning: Error detected in AddmmBackward0. Traceback of forward call that caused the error: File "main.py", line 292, in <module> main(args) File "main.py", line 218, in main train(model, train_loader, valid_loader, args, logger_1, which=args.opt_method) File "/VAEs/Tabular/DCEVAE_ours/train.py", line 56, in train D_tc_loss_val, fair_loss_val = model.calculate_loss(r.to(device), d.to(device), a.to(device), \ File "/VAEs/Tabular/DCEVAE_ours/model.py", line 220, in calculate_loss D_u = self.D(ua) File "/VAEs/Tabular/DCEVAE_ours/model.py", line 85, in D return self.discriminator(z).squeeze() File "/VAEs/Tabular/DCEVAE_ours/venv/lib64/python3.8/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, **kwargs) File "/VAEs/Tabular/DCEVAE_ours/venv/lib64/python3.8/site-packages/torch/nn/modules/container.py", line 141, in forward input = module(input) File "/VAEs/Tabular/DCEVAE_ours/venv/lib64/python3.8/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, **kwargs) File "/VAEs/Tabular/DCEVAE_ours/venv/lib64/python3.8/site-packages/torch/nn/modules/linear.py", line 103, in forward return F.linear(input, self.weight, self.bias) (Triggered internally at ../torch/csrc/autograd/python_anomaly_mode.cpp:104.) Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass 0%| | 0/500 [00:04<?, ?it/s] Traceback (most recent call last): File "main.py", line 292, in <module> main(args) File "main.py", line 218, in main train(model, train_loader, valid_loader, args, logger_1, which=args.opt_method) File "/VAEs/Tabular/DCEVAE_ours/train.py", line 69, in train loss_val.backward(retain_graph=True) File "/VAEs/Tabular/DCEVAE_ours/venv/lib64/python3.8/site-packages/torch/_tensor.py", line 363, in backward torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs) File "/VAEs/Tabular/DCEVAE_ours/venv/lib64/python3.8/site-packages/torch/autograd/__init__.py", line 173, in backward Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [100, 2]], which is output 0 of AsStridedBackward0, is at version 2; expected version 1 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient. The variable in question was changed in there or anywhere later. Good luck!

Looking at the code in question,

`
opt_delta.zero_grad()
loss_max = D_tc_loss_val
loss_max.backward(retain_graph=True)
opt_delta.step()

opt_without_delta.zero_grad()
loss_val.backward(retain_graph=True)
opt_without_delta.step()
`

This does seem to be a double backward pass and I am not sure how this can work at all :-) could you provide any guidance? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions