suragnair / seqGAN

A simplified PyTorch implementation of "SeqGAN: Sequence Generative Adversarial Nets with Policy Gradient." (Yu, Lantao, et al.)
642 stars 149 forks source link

RuntimeError in training #7

Closed fuzihaofzh closed 6 years ago

fuzihaofzh commented 6 years ago

The following error happens when training.

python main.py
Starting Generator MLE Training...
epoch 1 : /home/maple/work/seqGAN-pytorch/generator.py:49: UserWarning: Implicit dimension choice for log_softmax has been deprecated. Change the call to include dim=X as an argument.
  out = F.log_softmax(out)
main.py:55: UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number
  total_loss += loss.data[0]
..........Traceback (most recent call last):
  File "main.py", line 159, in <module>
    train_generator_MLE(gen, gen_optimizer, oracle, oracle_samples, MLE_TRAIN_EPOCHS)
  File "main.py", line 67, in train_generator_MLE
    start_letter=START_LETTER, gpu=CUDA)
  File "/home/maple/work/seqGAN-pytorch/helpers.py", line 80, in batchwise_oracle_nll
    s = batchwise_sample(gen, num_samples, batch_size)
  File "/home/maple/work/seqGAN-pytorch/helpers.py", line 74, in batchwise_sample
    samples.append(gen.sample(batch_size))
  File "/home/maple/work/seqGAN-pytorch/generator.py", line 72, in sample
    samples[:, i] = out.data
RuntimeError: expand(torch.LongTensor{[32, 1]}, size=[32]): the number of sizes provided (1) must be greater or equal to the number of dimensions in the tensor (2)
suragnair commented 6 years ago

PyTorch 0.4 compatibility added in ae8ffcd54977bd9ee177994c751f86d34f5f7aa3. Please check and let me know if it works now. Thanks!