Giter Site home page Giter Site logo

Comments (2)

whatchang avatar whatchang commented on August 23, 2024 3

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.

rungjoo avatar rungjoo commented on August 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.