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

checkpointing not saving model weights if calling accelerator.prepare_model instead of accelerator.prepare #555

Closed
2 of 4 tasks
csarron opened this issue Jul 22, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@csarron
Copy link
Contributor

csarron commented Jul 22, 2022

System Info

- `Accelerate` version: 0.11.0
- Platform: Linux-4.15.0-161-generic-x86_64-with-glibc2.10
- Python version: 3.8.12
- Numpy version: 1.23.1
- PyTorch version (GPU?): 1.12.0+cu113 (True)
- `Accelerate` default config:
        - compute_environment: LOCAL_MACHINE
        - distributed_type: MULTI_GPU
        - mixed_precision: no
        - use_cpu: False
        - num_processes: 4
        - machine_rank: 0
        - num_machines: 1
        - main_process_ip: None
        - main_process_port: None
        - main_training_function: main
        - deepspeed_config: {}
        - fsdp_config: {}

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • One of the scripts in the examples/ folder of Accelerate or an officially supported no_trainer script in the examples folder of the transformers repo (such as run_no_trainer_glue.py)
  • My own task or dataset (give details below)

Reproduction

if we separately prepare the model (i.e. model = accelerator.prepare_model(model)) instead of preparing all at once (model, optimizer, train_dataloader, eval_dataloader, lr_scheduler = accelerator.prepare(model, optimizer, train_dataloader, eval_dataloader, lr_scheduler)), accelerator won't save model weights using the accelerator.save_states

possible problem: accelerator internally use _prepare_one in the prepare(self, *args) method to append the model to self._models, but the prepare_model(self, model) does not append the model, see here. However, accelerator.save_states depends on self._models to save model weights

Expected behavior

accelerator.save_states should also save model weights even if one separately calls `prepare_model` method, this is possibly a bug in `accelerator.prepare_model(model)`
@csarron csarron added the bug Something isn't working label Jul 22, 2022
@csarron csarron changed the title checkpointing not saving model states checkpointing not saving model weights if calling accelerator.prepare_model instead of accelerator.prepare Jul 22, 2022
sgugger pushed a commit that referenced this issue Jul 26, 2022
* fix: saving model weights

checkpointing not saving model weights if calling `accelerator.prepare_model` instead of `accelerator.prepare`
resolves issue: #555

* fix: saveing model weights for optimizer and scheduler
@csarron csarron closed this as completed Jul 26, 2022
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

1 participant