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

Learning rate is given as tensor, cannot serialize TrainerState in order to save checkpoint. #18860

Closed
2 of 4 tasks
kmckiern opened this issue Sep 2, 2022 · 0 comments · Fixed by #18861
Closed
2 of 4 tasks
Labels

Comments

@kmckiern
Copy link
Contributor

kmckiern commented Sep 2, 2022

System Info

  • transformers version: 4.21.1
  • Platform: Linux-5.15.0-46-generic-x86_64-with-glibc2.35
  • Python version: 3.10.5
  • Huggingface_hub version: 0.8.1
  • PyTorch version (GPU?): 1.12.1.post200 (True)
  • Tensorflow version (GPU?): not installed (NA)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Using GPU in script?: yes
  • Using distributed or parallel set-up in script?: no

Who can help?

@sgugger

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

  1. use Adafactor optimizer and schedule
optimizer = Adafactor(
    model.parameters(),
    relative_step=True,
    warmup_init=True,
)
lr_scheduler = AdafactorSchedule(optimizer)
  1. save a checkpoint

Expected behavior

When using an AdafactorSchedule I can't use the Trainer class to save a checkpoint.

It breaks here since the learning rate attached to the TrainerState is given by a tensor and tensors are not JSON serializable.

I dropped a breakpoint at this line and took a look at my TrainerState:

In [4]: self.log_history[0]['learning_rate']
Out[4]: tensor(0.0001, device='cuda:0')

Expected behavior is that the learning rate attached to the log history would be given by a float and would therefore be JSON serializable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant