# How do you calculate max steps

**URL:** <https://discuss.huggingface.co/t/how-do-you-calculate-max-steps/40177>\
**Category:** Beginners\
**Created:** [May 17, 2023, 3:35pm UTC](https://discuss.huggingface.co/t/how-do-you-calculate-max-steps/40177 "2023-05-17T15:35:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![imeese8](https://avatars.discourse-cdn.com/v4/letter/i/8797f3/32.png) [@imeese8](https://discuss.huggingface.co/u/imeese8)\
**Post date:** [May 17, 2023, 3:35pm UTC](https://discuss.huggingface.co/t/how-do-you-calculate-max-steps/40177/1 "2023-05-17T15:35:49Z")

</div>

I am looking to understand the math behind how max steps is calculated when left alone, I’ve tried to work backwards from making changes to epoch, batch, and micro-batch to see if I could figure out the formula but I haven’t had any luck. I have also looked at the documentation for the transformers trainer but I haven’t been able to find it, I’m looking to be able to predict the max steps using the knowledge of epochs, batch, micro-batch, and how many samples are in the dataset.  
hopefully I’m just missing something simple thanks for your help!

---

<div class="post-metadata">

**Author:** ![bozden](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/bozden/32/29992_2.png) [@bozden](https://discuss.huggingface.co/u/bozden)\
**Post date:** [May 19, 2023, 4:42am UTC](https://discuss.huggingface.co/t/how-do-you-calculate-max-steps/40177/2 "2023-05-19T04:42:12Z")

</div>

As a newbie, I was just trying to figure out these relations. I don’t know about micro-batching, but I wanted epoch-based calculations.

```auto
    evaluation_strategy = "epoch",
    save_strategy = "epoch",

    per_device_train_batch_size = 64,
    gradient_accumulation_steps = 4,
    per_device_eval_batch_size = 64,

```

My train set was 31,091 these were giving me 605 steps. So I “back-propagated”…

```py
epochs = 5
train_size = 31091
train_batch_size = 64
ga_steps = 4
virtual_batch_size = train_batch_size * ga_steps # "invented name" => 256
per_epoch_steps = int(train_size / virtual_batch_size + 0.5) # round => 121
total_steps = epochs * per_epoch_steps # => 605

```

If I’m not mistaken…

---

<div class="post-metadata">

**Author:** ![jasicarose75](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/jasicarose75/32/18050_2.png) [@jasicarose75](https://discuss.huggingface.co/u/jasicarose75)\
**Post date:** [July 28, 2023, 7:22pm UTC](https://discuss.huggingface.co/t/how-do-you-calculate-max-steps/40177/3 "2023-07-28T19:22:46Z")

</div>

I need to try
