Comments (2)
rungjoo님의 코드덕분에 잘 공부하고 있는 학부생입니다.
좋은 코드를 공개해주시고 공유해주셔서 감사합니다~!😆
본론으로 들어가서 저도 위와 같은 에러가 발생하였습니다.
제 버전은 아래와 같습니다.
python : 3.7.11
pytorch : 1.10.0
저는 다음과 같은 코드에서
aed_trainer.zero_grad()
recon_loss.backward(retain_graph=True) # retain_graph=True
grad_norm = torch.nn.utils.clip_grad_norm_(genmodel.aed_params, max_grad_norm)
aed_trainer.step()
"""decoder classification loss & training"""
## calculation loss
gen_cls_out = dismodel.gen_discriminator(vocab_out)
## calculation loss
gen_cls_loss = genmodel.cls_loss(attribute, gen_cls_out)
summary.add_scalar('generated sentence loss', gen_cls_loss.item(), start)
gen_trainer.zero_grad()
# torch.autograd.set_detect_anomaly(True)
gen_cls_loss.backward() # retain_graph=True
grad_norm = torch.nn.utils.clip_grad_norm_(genmodel.aed_params, max_grad_norm)
gen_trainer.step()
aed_trainer.step() 함수를 gen_cls_loss.backward() 실행한 후 동작하도록 해줬더니 위의 에러가 잘 해결되었습니다.
아래는 수정후 코드입니다.
aed_trainer.zero_grad()
recon_loss.backward(retain_graph=True) # retain_graph=True
grad_norm = torch.nn.utils.clip_grad_norm_(genmodel.aed_params, max_grad_norm)
"""decoder classification loss & training"""
## calculation loss
gen_cls_out = dismodel.gen_discriminator(vocab_out)
## calculation loss
gen_cls_loss = genmodel.cls_loss(attribute, gen_cls_out)
summary.add_scalar('generated sentence loss', gen_cls_loss.item(), start)
gen_trainer.zero_grad()
gen_cls_loss.backward() # retain_graph=True
grad_norm = torch.nn.utils.clip_grad_norm_(genmodel.aed_params, max_grad_norm)
aed_trainer.step()
gen_trainer.step()
이 코드를 참고하고 활용하시는 사람들에게 도움이 되었으면 하는 바램에서 해당 내용을 공유하였습니다.
감사합니다~!!!😄
이 에러를 해결하기 위해서 참고한 링크입니다.
https://discuss.pytorch.org/t/solved-pytorch1-5-runtimeerror-one-of-the-variables-needed-for-gradient-computation-has-been-modified-by-an-inplace-operation/90256/2
from stable-style-transformer.
I think the error you mentioned may be related to the version and environment setting of the libraries. We recommend that you try lowering the version.
There seems to be a problem in calculating the gradient, so it seems that you need debugging for that part.
Sorry for not giving the correct answer. I hope this is resolved.
from stable-style-transformer.
Related Issues (8)
- 학습된 모델 요청 HOT 9
- the byte pair encoding HOT 1
- OSError: Couldn't reach server at '{}' to download vocabulary files. HOT 1
- ModuleNotFoundError: No module named 'dis_model' HOT 1
- Please provide Outputs HOT 1
- 해당 모델을 한국어 데이터로 학습하고 싶은데 궁금증이 생겨 문의드립니다. HOT 3
- RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [256, 50259]], which is output 0 of AsStridedBackward0, is at version 2; expected version 1 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True). HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stable-style-transformer.