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

Evaluation with the pretrained model for TSP problem asserts an error #34

Open
th-yoon opened this issue Mar 31, 2021 · 3 comments
Open

Comments

@th-yoon
Copy link

th-yoon commented Mar 31, 2021

Command: python3 eval.py data/tsp/tsp20_validation_seed4321.pkl --model pretrained/tsp_20 --decode_strategy greedy

Trace:

  [*] Loading model from pretrained/tsp_20/epoch-99.pt
  0%|                                                                                            | 0/10 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "eval.py", line 216, in <module>
    eval_dataset(dataset_path, width, opts.softmax_temperature, opts)
  File "eval.py", line 70, in eval_dataset
    results = _eval_dataset(model, dataset, width, softmax_temp, opts, device)
  File "eval.py", line 140, in _eval_dataset
    sequences, costs = model.sample_many(batch, batch_rep=batch_rep, iter_rep=iter_rep)
  File "/home/thyoon/attention-learn-to-route/nets/attention_model.py", line 288, in sample_many
    batch_rep, iter_rep
  File "/home/thyoon/attention-learn-to-route/utils/functions.py", line 189, in sample_many
    _log_p, pi = inner_func(input)
  File "/home/thyoon/attention-learn-to-route/nets/attention_model.py", line 285, in <lambda>
    lambda input: self._inner(*input),  # Need to unpack tuple into arguments
  File "/home/thyoon/attention-learn-to-route/nets/attention_model.py", line 234, in _inner
    batch_size = state.ids.size(0)
  File "/home/thyoon/attention-learn-to-route/problems/tsp/state_tsp.py", line 31, in __getitem__
    assert torch.is_tensor(key) or isinstance(key, slice)  # If tensor, idx all tensors by this tensor:
AssertionError
@th-yoon
Copy link
Author

th-yoon commented Mar 31, 2021

I fixed this issue by commenting out the __getitem__ overrides of the following classes:
attention_model/AttentionModelFixed and state_tsp/StateTSP

@wouterkool
Copy link
Owner

Which version of Python are you using? I think this is related to using <3.8. Please make sure you use 3.8. Commenting out __getitem__ probably works fine as long as you're not using beam search (which requires indexing into the state array).

@th-yoon
Copy link
Author

th-yoon commented Mar 31, 2021

@wouterkool Thanks for your quick reply. Current python version is 3.7.9. Will try with python >= 3.8.

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

2 participants