# How to only load model weights for the evalaution script?

**URL:** <https://discuss.huggingface.co/t/how-to-only-load-model-weights-for-the-evalaution-script/31591>\
**Category:** 🤗Accelerate\
**Created:** [February 13, 2023, 8:11am UTC](https://discuss.huggingface.co/t/how-to-only-load-model-weights-for-the-evalaution-script/31591 "2023-02-13T08:11:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HashmatShadab](https://avatars.discourse-cdn.com/v4/letter/h/c37758/32.png) [@HashmatShadab](https://discuss.huggingface.co/u/HashmatShadab)\
**Post date:** [February 13, 2023, 8:12am UTC](https://discuss.huggingface.co/t/how-to-only-load-model-weights-for-the-evalaution-script/31591/1 "2023-02-13T08:12:00Z")

</div>

````auto
from accelerate import Accelerator
import torch

accelerator = Accelerator(project_dir="my/save/path")

my_scheduler = torch.optim.lr_scheduler.StepLR(my_optimizer, step_size=1, gamma=0.99)
my_model, my_optimizer, my_training_dataloader = accelerator.prepare(my_model, my_optimizer, my_training_dataloader)

# Register the LR scheduler
accelerator.register_for_checkpointing(my_scheduler)

# Save the starting state
accelerator.save_state()

device = accelerator.device
my_model.to(device)

# Perform training
for epoch in range(num_epochs):
    for batch in my_training_dataloader:
        my_optimizer.zero_grad()
        inputs, targets = batch
        inputs = inputs.to(device)
        targets = targets.to(device)
        outputs = my_model(inputs)
        loss = my_loss_function(outputs, targets)
        accelerator.backward(loss)
        my_optimizer.step()
    my_scheduler.step()

# Restore previous state
accelerator.load_state("my/save/path/checkpointing/checkpoint_0")```

> If I need to just load the model weights in the evaluation script or load 
the weights in training framework which does not use accelerate, how can i do that?
````

---

<div class="post-metadata">

**Author:** ![HashmatShadab](https://avatars.discourse-cdn.com/v4/letter/h/c37758/32.png) [@HashmatShadab](https://discuss.huggingface.co/u/HashmatShadab)\
**Post date:** [March 13, 2023, 7:22pm UTC](https://discuss.huggingface.co/t/how-to-only-load-model-weights-for-the-evalaution-script/31591/2 "2023-03-13T19:22:14Z")

</div>

Can anyone provide suggestions?
