๋ฅ๋ฌ๋ ๋ชจ๋ธ์ ํ์ต์ํค๋ ์ค ๋ค์๊ณผ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [CUDAComplexFloatType [1, 256, 232]], which is output 0 of SubBackward0, is at version 10; expected version 9 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).
์น์ ํ๊ฒ๋ Hint๋ฅผ ์ค๋ค..
๊ฐ์ด ๋ฐ๋๋ inplace operation์ผ๋ก ์ธํด gradient computation ๊ณผ์ ์์ Runtime error๊ฐ ๋ฐ์ํ๋ค๊ณ ํ๋ค. torch.autograd.set_detect_anomaly(True)
๋ฅผ ํตํด anomaly detection์ ์ฌ์ฉํ๋ฉด ์ด๋์ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋์ง ์ ์ ์๋ค๊ณ ํ๋ค.
PyTorch Anomaly Detection ์ฌ์ฉ๋ฐฉ๋ฒ
PyTorch์ anomaly detection์ ๋ค์๊ณผ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ์ฌ์ฉํ ์ ์๋ค.
with torch.autograd.detect_anomaly():
y_pred = model(x)
loss = loss_f(y_pred, y)
loss.backward()
์ฐธ๊ณ ๋ก torch.autograd.detect_anomaly()
์ torch.autograd.set_detect_anomaly(True)
๋ ๊ฐ์ ์๋ฏธ์ด๋ค.
์ด๋ ๊ฒ ํ๋ฉด gradient ๊ณ์ฐ ๊ฐ ๊ณผ์ ์์ anomaly detection์ ์ถ๊ฐ๋ก ์งํํ์ฌ ์ด๋์์ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋์ง ์๋ ค์ค๋ค.
๋จ ์คํ์๊ฐ์ด ๊ธธ์ด์ง๋ค.
์คํ ๊ฒฐ๊ณผ ์์
๐ anomaly detection ์ถ๊ฐ ์ :
Traceback (most recent call last):
File "train.py", line 169, in <module>
main(args)
File "train.py", line 112, in main
loss.backward()
File "/home/user/anaconda3/lib/python3.8/site-packages/torch/tensor.py", line 245, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)
File "/home/user/anaconda3/lib/python3.8/site-packages/torch/autograd/__init__.py", line 145, in backward
Variable._execution_engine.run_backward(
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [CUDAComplexFloatType [1, 256, 232]], which is output 0 of SubBackward0, is at version 10; expected version 9 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).
๐ anomaly detection ์ถ๊ฐ ํ:
File "train.py", line 170, in <module>
main(args)
File "train.py", line 108, in main
y_pred = model(x)
File "/home/user/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/user/model.py", line 197, in forward
x = self.dc(z)
File "/home/user/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/user/model.py", line 115, in forward
rTr = torch.sum(r.conj()*r).real
(function _print_stack)
0%| | 0/100 [00:00<?, ?it/s]
Traceback (most recent call last):
File "train.py", line 170, in <module>
main(args)
File "train.py", line 113, in main
loss.backward()
File "/home/user/anaconda3/lib/python3.8/site-packages/torch/tensor.py", line 245, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)
File "/home/user/anaconda3/lib/python3.8/site-packages/torch/autograd/__init__.py", line 145, in backward
Variable._execution_engine.run_backward(
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [CUDAComplexFloatType [1, 256, 232]], which is output 0 of SubBackward0, is at version 10; expected version 9 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!
๋ง์ง๋ง์ Good luck! ๊น์ง ๋น์ด์ค๋ค.
์ฝ๋๋ฅผ ์๋ชป ์ง ์ฌ์ฉ์๋ฅผ ์ํด ์ด๋ฐ ๊ธฐ๋ฅ๊น์ง ์ ๊ณตํด์ฃผ๋ ํ์ดํ ์น..
์ ๋ง ์น์ ํ๋ค. ๐๐
์ฐธ๊ณ ๋ก ๋๋ model.py์ line 114~115๊ฐ ๋ค์๊ณผ ๊ฐ์๋๋ฐ
r -= alpha * Ap
rTr = torch.sum(r.conj()*r).real
๋ค์๊ณผ ๊ฐ์ด ์์ ํ๋๋ ์ ๋์ํ๋ค.
r = r - alpha * Ap
rTr = torch.sum(r.conj()*r).real
์์ธ์ง ๋ชจ๋ฆ.. ^_^
'๐ Python & library > PyTorch' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[PyTorch] nn.Conv์ padding๊ณผ padding_mode (2) | 2022.03.24 |
---|---|
[PyTorch] Weight clipping (0) | 2022.01.29 |
[PyTorch] ๋ชจ๋ธ ์๊ฐํ ํด ์ธ๊ฐ์ง - Torchviz, HiddenLayer, Netron (Model visualization) (2) | 2022.01.13 |
[PyTorch/Tensorflow v1, v2] Gradient Clipping ์ถ๊ฐํ๊ธฐ (0) | 2022.01.12 |
[PyTorch] Scheduler ์๊ฐํํ๊ธฐ (Visualize scheduler) (2) | 2021.11.24 |