wiseodd / controlled-text-generation

Reproducing Hu, et. al., ICML 2017's "Toward Controlled Generation of Text"
BSD 3-Clause "New" or "Revised" License
242 stars 63 forks source link

when running train_discriminator.py ,occuring cudnn RNN backward can only be called in training mode #24

Open zide05 opened 5 years ago

zide05 commented 5 years ago

Traceback (most recent call last): File "train_discriminator.py", line 172, in main() File "train_discriminator.py", line 140, in main loss_G.backward() File "/remote-home/yrchen/anaconda3/envs/py37_cuda8/lib/python3.7/site-packages/torch/tensor.py", line 102, in backward torch.autograd.backward(self, gradient, retain_graph, create_graph) File "/remote-home/yrchen/anaconda3/envs/py37_cuda8/lib/python3.7/site-packages/torch/autograd/init.py", line 90, in backward allow_unreachable=True) # allow_unreachable flag RuntimeError: cudnn RNN backward can only be called in training mode

pelovett commented 5 years ago

Hey, you can solve this problem by adding: model.train() to line 152 in file train_discriminator.py

The problem is caused by the function call model.sample_sentence(z, c) calling model.eval() but not calling model.train() afterwards.

zide05 commented 5 years ago

oh,i get this,thank you!

---Original--- From: "Peter Lovett"notifications@github.com Date: Mon, Apr 22, 2019 10:59 AM To: "wiseodd/controlled-text-generation"controlled-text-generation@noreply.github.com; Cc: "zide05"845465009@qq.com;"Author"author@noreply.github.com; Subject: Re: [wiseodd/controlled-text-generation] when running train_discriminator.py ,occuring cudnn RNN backward can only be called in training mode (#24)

Hey, you can solve this problem by adding: model.train() to line 152 in file train_discriminator.py

The problem is caused by the function call model.sample_sentence(z, c) calling model.eval() but not calling model.train() afterwards.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

mahimanzum commented 5 years ago

Hey, you can solve this problem by adding: model.train() to line 152 in file train_discriminator.py

The problem is caused by the function call model.sample_sentence(z, c) calling model.eval() but not calling model.train() afterwards.

this does not solve the issue. same error stays. Any solution??

Akhila-Yerukola commented 4 years ago

Replace x_gen_attr with x_gen_attr.detach() in train_discriminator.py. i.e in model.forward_encoder_embed and model.forward_discriminator_embed

shizhediao commented 4 years ago

Replace x_gen_attr with x_gen_attr.detach() in train_discriminator.py. i.e in model.forward_encoder_embed and model.forward_discriminator_embed

It works, thanks very much!