Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: forward() missing 2 required positional arguments: 'attn' and 'src_map' #18

Open
ymym3412 opened this issue May 12, 2018 · 5 comments
Assignees

Comments

@ymym3412
Copy link

Hi, I get some error when I did python VisServer.py .
My enviroment is this.
Ubuntu 16.04
Anaconda
Python 3.6

I installed Seq2Seq-Vis with conda.

git clone https://github.com/HendrikStrobelt/Seq2Seq-Vis.git
cd Seq2Seq-Vis
source setup_cpu.sh
cd ..
source Seq2Seq-Vis/setup_onmt_custom.sh

And, I trained summarization model with my own data.
I trained following command.

python preprocess.py -train_src data/newspaper/train_source.txt -train_tgt data/newspaper/train_target.txt -valid_src data/newspaper/dev_source.txt -valid_tgt data/newspaper/dev_target.txt -save_data data/newspaper/newspaper -src_seq_length 6705 -tgt_seq_length 30 -src_seq_length_trunc 300 -tgt_seq_length_trunc 30 -dynamic_dict -share_vocab -max_shard_size 134217728
python train.py -save_model models/newspapre -data data/newspaper/newspaper -copy_attn -global_attention dot -coverage_attn -word_vec_size 128 -rnn_size 512 -layers 1 -encoder_type brnn -epochs 9 -max_grad_norm 2 -dropout 0.5 -batch_size 32 -optim adagrad -learning_rate 0.15 -adagrad_accumulator_init 0.1 -seed 777 -gpuid 0

After training, I create state.h5 , encoder.faiss , decoder.faiss , context.faiss.
Then I do python VisServer.py , but I got following error.

(s2sv) ymym@ymym:~/workspace/OpenNMT-py$ python VisServer.py 
/home/ymym/anaconda3/envs/s2sv/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
/home/ymym/anaconda3/envs/s2sv/lib/python3.6/site-packages/torch/nn/modules/rnn.py:38: UserWarning: dropout option adds dropout after all but last recurrent layer, so non-zero dropout expects num_layers greater than 1, but got dropout=0.5 and num_layers=1
  "num_layers={}".format(dropout, num_layers))
Loading model parameters.
partial: []
/home/ymym/anaconda3/envs/s2sv/lib/python3.6/site-packages/torchtext/data/field.py:321: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  return Variable(arr, volatile=not train), lengths
/home/ymym/anaconda3/envs/s2sv/lib/python3.6/site-packages/torchtext/data/field.py:322: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  return Variable(arr, volatile=not train)
/home/ymym/workspace/OpenNMT-py/onmt/translate/Translator.py:88: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  def var(a): return Variable(a, volatile=True)
/home/ymym/workspace/OpenNMT-py/onmt/Models.py:629: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  for e in self._all]
/home/ymym/workspace/OpenNMT-py/onmt/modules/GlobalAttention.py:178: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.
  align_vectors = self.sm(align.view(batch*targetL, sourceL))
/home/ymym/workspace/OpenNMT-py/onmt/modules/CopyGenerator.py:91: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.
  prob = F.softmax(logits)
Traceback (most recent call last):
  File "VisServer.py", line 401, in <module>
    main()
  File "VisServer.py", line 371, in main
    reply = model.translate(["This is a test ."], dump_data=True)
  File "VisServer.py", line 322, in translate
    partial=partial, attn_overwrite=attn_overwrite)
  File "/home/ymym/workspace/OpenNMT-py/onmt/translate/Translator.py", line 273, in translate_batch
    batch, resorted[0])
  File "/home/ymym/workspace/OpenNMT-py/onmt/translate/Translator.py", line 362, in _get_top_k
    out = self.model.generator.forward(dec)
TypeError: forward() missing 2 required positional arguments: 'attn' and 'src_map'

Thanks.

@HendrikStrobelt
Copy link
Owner

hi - thanks for reaching out. We will check what's wrong. Might take a little bit.. Just to double check, you only have the modified ONMT version in your conda environment ?

@ymym3412
Copy link
Author

I check my ONMT enviroment. And I remenber little modifying ONMT code!
First time when I tried python VisServer.py command, I got following error.

(s2sv) ymym@ymym:~/workspace/OpenNMT-py$ python VisServer.py 
/home/ymym/anaconda3/envs/s2sv/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
/home/ymym/anaconda3/envs/s2sv/lib/python3.6/site-packages/torch/nn/modules/rnn.py:38: UserWarning: dropout option adds dropout after all but last recurrent layer, so non-zero dropout expects num_layers greater than 1, but got dropout=0.5 and num_layers=1
  "num_layers={}".format(dropout, num_layers))
Loading model parameters.
partial: []
/home/ymym/anaconda3/envs/s2sv/lib/python3.6/site-packages/torchtext/data/field.py:321: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  return Variable(arr, volatile=not train), lengths
/home/ymym/anaconda3/envs/s2sv/lib/python3.6/site-packages/torchtext/data/field.py:322: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  return Variable(arr, volatile=not train)
/home/ymym/workspace/OpenNMT-py/onmt/translate/Translator.py:88: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  def var(a): return Variable(a, volatile=True)
/home/ymym/workspace/OpenNMT-py/onmt/Models.py:629: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  for e in self._all]
/home/ymym/workspace/OpenNMT-py/onmt/modules/GlobalAttention.py:178: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.
  align_vectors = self.sm(align.view(batch*targetL, sourceL))
Traceback (most recent call last):
  File "VisServer.py", line 402, in <module>
    main()
  File "VisServer.py", line 372, in main
    reply = model.translate(["This is a test ."], dump_data=True)
  File "VisServer.py", line 322, in translate
    partial=partial, attn_overwrite=attn_overwrite)
  File "/home/ymym/workspace/OpenNMT-py/onmt/translate/Translator.py", line 167, in translate_batch
    attn_overwrite=new_attn)
  File "/home/ymym/anaconda3/envs/s2sv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/ymym/workspace/OpenNMT-py/onmt/Models.py", line 261, in forward
    attn_overwrite=attn_overwrite)
  File "/home/ymym/workspace/OpenNMT-py/onmt/Models.py", line 490, in _run_forward_pass
    context.transpose(0, 1))
ValueError: too many values to unpack (expected 2)

So, I fixed onmt/Models.py L489-L490 as

_, copy_attn = self.copy_attn(output, context.transpose(0, 1))

-->

_, copy_attn, _ = self.copy_attn(output, context.transpose(0, 1))

After modifying, I try python VisServer.py, but I got error message described in my first message.

Thanks.

@tangxiangru
Copy link

tangxiangru commented Sep 26, 2018

I meet the same err!

 Traceback (most recent call last):
  File "translate.py", line 36, in <module>
    main(opt)

  File "translate.py", line 24, in main
    attn_debug=opt.attn_debug)

  File "/home1/txr/OpenNMT-py-cpu/onmt/translate/translator.py", line 219, in translate
    batch_data = self.translate_batch(batch, data, fast=self.fast)

  File "/home1/txr/OpenNMT-py-cpu/onmt/translate/translator.py", line 320, in translate_batch
    return self._translate_batch(batch, data)

  File "/home1/txr/OpenNMT-py-cpu/onmt/translate/translator.py", line 623, in _translate_batch
    ret["gold_score"] = self._run_target(batch, data)

  File "/home1/txr/OpenNMT-py-cpu/onmt/translate/translator.py", line 669, in _run_target
    out = self.model.generator.forward(dec)

TypeError: forward() missing 2 required positional arguments: 'attn' and 'src_map'

@tangxiangru
Copy link

So anyone solved it?

@dattatreya303
Copy link

I am facing the same issue. Did someone fix this somehow for seq2seq-vis to work with copy-attn as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants