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

[BUG] Code for real-world cvrplib instance inference. #223

Closed
Elon-Lau opened this issue Oct 8, 2024 · 5 comments
Closed

[BUG] Code for real-world cvrplib instance inference. #223

Elon-Lau opened this issue Oct 8, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@Elon-Lau
Copy link

Elon-Lau commented Oct 8, 2024

Hello, I can't solve the instances in cvrplib with the trained model.

Traceback (most recent call last):
File "/NCO/RL4CO/examples/test_cvrplib_demo.py", line 91, in
out = policy(td.clone(), decode_type='greedy', return_actions=True)
File "/miniconda3/envs/rl4co/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/miniconda3/envs/rl4co/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
File "/miniconda3/envs/rl4co/lib/python3.9/site-packages/rl4co/models/common/constructive/base.py", line 237, in forward
td = env.step(td)["next"]
File "/miniconda3/envs/rl4co/lib/python3.9/site-packages/rl4co/envs/common/base.py", line 129, in step
td = self._step(td)
File "/miniconda3/envs/rl4co/lib/python3.9/site-packages/rl4co/envs/routing/cvrp/env.py", line 89, in _step
visited = td["visited"].scatter(-1, current_node, 1)
RuntimeError: Index tensor must have the same number of dimensions as self tensor

@Elon-Lau Elon-Lau added the bug Something isn't working label Oct 8, 2024
@fedebotu
Copy link
Member

fedebotu commented Oct 8, 2024

Have you checked out this notebook?

https://github.com/ai4co/rl4co/blob/main/examples/datasets/2-test-on-cvrplib.ipynb

There was some small problem with squeezing dimensions for evaluating with batch size of 1, so we made some monkey patching (that should be solved in 0.5.1)

Also, here is an example of a recent project based on RL4CO in which we evaluate CVRPLIB (with some extra utilities):

https://github.com/ai4co/routefinder/blob/main/examples/2.eval-cvrplib.ipynb

@Elon-Lau
Copy link
Author

Elon-Lau commented Oct 8, 2024

Follow the https://github.com/ai4co/rl4co/blob/main/examples/datasets/2-test-on-cvrplib.ipynb, i set batch_size=2. However, I still have this problem. If the current version can be used for CVRPlib instance inference?

@Elon-Lau
Copy link
Author

Elon-Lau commented Oct 8, 2024

I use the same code in https://github.com/ai4co/rl4co/blob/main/examples/2d-meta_train.py for training and the same code in https://github.com/ai4co/rl4co/blob/main/examples/datasets/2-test-on-cvrplib.ipynb for cvrplib instance inference. But the following bug still occur.

Traceback (most recent call last):
File "/NCO/RL4CO/examples/test_cvrplib_demo.py", line 91, in
out = policy(td.clone(), decode_type='greedy', return_actions=True)
File "/miniconda3/envs/rl4co/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/miniconda3/envs/rl4co/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
File "/miniconda3/envs/rl4co/lib/python3.9/site-packages/rl4co/models/common/constructive/base.py", line 237, in forward
td = env.step(td)["next"]
File "/miniconda3/envs/rl4co/lib/python3.9/site-packages/rl4co/envs/common/base.py", line 129, in step
td = self._step(td)
File "/miniconda3/envs/rl4co/lib/python3.9/site-packages/rl4co/envs/routing/cvrp/env.py", line 89, in _step
visited = td["visited"].scatter(-1, current_node, 1)
RuntimeError: Index tensor must have the same number of dimensions as self tensor

fedebotu added a commit that referenced this issue Oct 10, 2024
@fedebotu
Copy link
Member

Thanks for reporting the bug - you may check the most recent improvements!
Please let us know if now it works well on your end ~

@Elon-Lau
Copy link
Author

Thanks for the update, it looks like the patch will fix the current bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants