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

Snapshot extension's autoloading raises AttributeError #3

Open
msakai opened this issue Jan 16, 2020 · 2 comments
Open

Snapshot extension's autoloading raises AttributeError #3

msakai opened this issue Jan 16, 2020 · 2 comments
Assignees

Comments

@msakai
Copy link
Contributor

msakai commented Jan 16, 2020

If I run following script multiple times, it raises a AttributeError: 'ExtensionTrainerAdapter' object has no attribute 'torch_snapshot'.

import numpy as np
import torch
import torch.nn.functional as F
import ignite

from chainer.training import extensions
import chainer_pytorch_migration as cpm
import chainer_pytorch_migration.ignite

device = torch.device('cpu')

model = torch.nn.Linear(3,1).to(device)

X = torch.randn(10, 3)
y = torch.rand(10).to(torch.int64)
dataset = torch.utils.data.TensorDataset(X, y)
train_loader = torch.utils.data.DataLoader(dataset, shuffle=True, batch_size=2)

optimizer = torch.optim.Adam(model.parameters())
trainer = ignite.engine.create_supervised_trainer(
    model, optimizer, F.nll_loss, device=device)

optimizer.target = model
trainer.out = "result"
snapshot = extensions.snapshot(filename='snapshot_iteration-{.updater.iteration}', autoload=True)
cpm.ignite.add_trainer_extension(trainer, optimizer, snapshot, trigger=(1, 'iteration'))

trainer.run(train_loader, max_epochs=2)
$ python test.py 
$ python test.py 
Traceback (most recent call last):
  File "test.py", line 28, in <module>
    trainer.run(train_loader, max_epochs=2)
  File "/Users/sakai/.pyenv/versions/miniconda3-4.3.30/lib/python3.6/site-packages/chainer_pytorch_migration/ignite/extensions.py", line 293, in pre_run
    Engine.run(self.engine, data, max_epochs)
  File "/Users/sakai/.pyenv/versions/miniconda3-4.3.30/lib/python3.6/site-packages/ignite/engine/engine.py", line 446, in run
    self._handle_exception(e)
  File "/Users/sakai/.pyenv/versions/miniconda3-4.3.30/lib/python3.6/site-packages/ignite/engine/engine.py", line 410, in _handle_exception
    raise e
  File "/Users/sakai/.pyenv/versions/miniconda3-4.3.30/lib/python3.6/site-packages/ignite/engine/engine.py", line 429, in run
    self._fire_event(Events.STARTED)
  File "/Users/sakai/.pyenv/versions/miniconda3-4.3.30/lib/python3.6/site-packages/ignite/engine/engine.py", line 345, in _fire_event
    func(self, *(event_args + args), **kwargs)
  File "/Users/sakai/.pyenv/versions/miniconda3-4.3.30/lib/python3.6/site-packages/chainer_pytorch_migration/ignite/extensions.py", line 241, in set_training_started
    self.start_extensions()
  File "/Users/sakai/.pyenv/versions/miniconda3-4.3.30/lib/python3.6/site-packages/chainer_pytorch_migration/ignite/extensions.py", line 266, in start_extensions
    initializer(self)
  File "/Users/sakai/.pyenv/versions/miniconda3-4.3.30/lib/python3.6/site-packages/chainer/training/extensions/_snapshot.py", line 379, in initialize
    npz.load_npz(snapshot_file, target)
  File "/Users/sakai/.pyenv/versions/miniconda3-4.3.30/lib/python3.6/site-packages/chainer/serializers/npz.py", line 243, in load_npz
    d.load(obj)
  File "/Users/sakai/.pyenv/versions/miniconda3-4.3.30/lib/python3.6/site-packages/chainer/serializer.py", line 83, in load
    obj.serialize(self)
  File "/Users/sakai/.pyenv/versions/miniconda3-4.3.30/lib/python3.6/site-packages/chainer_pytorch_migration/ignite/extensions.py", line 307, in serialize
    state = torch.load(self.torch_snapshot)
AttributeError: 'ExtensionTrainerAdapter' object has no attribute 'torch_snapshot'

Maybe following description in Framework Migration GuideFramework Migration Guide implies that autoload is unsupported, but I create this issue just in case.

The correct way to restore a snapshot is by using cpm.ignite.load_chainer_snapshot(engine, optimizer, snapshot_path) with the Chainer snapshot path.

@emcastillo emcastillo self-assigned this Jan 17, 2020
@emcastillo
Copy link
Member

Exactly, autoload is currently not supported.
We will update the migration guide to reflect this.

@msakai
Copy link
Contributor Author

msakai commented Jan 22, 2020

I see. Thanks!

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