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 FIX] fixed load method for dqn in pytorch #1227

Merged
merged 1 commit into from
May 13, 2024

Conversation

Brunozml
Copy link
Contributor

Problem

the past implementation of this function did not follow the syntax indicated by torch.load() docs, but rather seemed to imitate what is required by torch.save() docs.

This resulted in the following error:

  File "../train/dqn_pytorch/block_dominoes_deep_cfr.py", line 77, in main
    agents[i].load(FLAGS.checkpoint_dir + f'{i}.pt')
  File "../.venv/lib/python3.10/site-packages/open_spiel/python/pytorch/dqn.py", line 431, in load
    torch.load(self._q_network, data_path)
  File "../.venv/lib/python3.10/site-packages/torch/serialization.py", line 997, in load
    with _open_file_like(f, 'rb') as opened_file:
  File "../.venv/lib/python3.10/site-packages/torch/serialization.py", line 449, in _open_file_like
    return _open_buffer_reader(name_or_buffer)
  File "../.venv/lib/python3.10/site-packages/torch/serialization.py", line 434, in __init__
    _check_seekable(buffer)
  File "../.venv/lib/python3.10/site-packages/torch/serialization.py", line 543, in _check_seekable
    raise_err_msg(["seek", "tell"], e)
  File "../.venv/lib/python3.10/site-packages/torch/serialization.py", line 536, in raise_err_msg
    raise type(e)(msg)
AttributeError: 'MLP' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.

Solution

use correct function calls when loading .pt objects, e. g.

self._q_network = torch.load(data_path)

instead of

torch.load(self._q_network, data_path)

@Brunozml Brunozml marked this pull request as ready for review May 13, 2024 06:30
@lanctot
Copy link
Collaborator

lanctot commented May 13, 2024

Thanks @Brunozml !

@lanctot lanctot added imported This PR has been imported and awaiting internal review. Please avoid any more local changes, thanks! merged internally The code is now submitted to our internal repo and will be merged in the next github sync. labels May 13, 2024
@lanctot lanctot merged commit 7d3a355 into google-deepmind:master May 13, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imported This PR has been imported and awaiting internal review. Please avoid any more local changes, thanks! merged internally The code is now submitted to our internal repo and will be merged in the next github sync.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants