# How to use once Cycle LR properly

**URL:** <https://discuss.pytorch.org/t/how-to-use-once-cycle-lr-properly/128496>\
**Category:** Uncategorized\
**Created:** [August 4, 2021, 4:41am UTC](https://discuss.pytorch.org/t/how-to-use-once-cycle-lr-properly/128496 "2021-08-04T04:41:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![talhaanwarch](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/talhaanwarch/32/26568_2.png) [@talhaanwarch](https://discuss.pytorch.org/u/talhaanwarch)\
**Post date:** [August 4, 2021, 4:41am UTC](https://discuss.pytorch.org/t/how-to-use-once-cycle-lr-properly/128496/1 "2021-08-04T04:41:37Z")

</div>

I have 288 images, and i am using batch size of 4. So I think my steps\_per\_epoch is 288//4.

I have plotted LR as follow

```auto
import matplotlib.pyplot as plt
opt = torch.optim.Adam(model.parameters(), lr=1e-4,weight_decay=1e-4)
scheduler = torch.optim.lr_scheduler.OneCycleLR(optimizer,pct_start=0.33, max_lr=1e-3,steps_per_epoch=288//4, epochs=10,last_epoch =-1)
lrs = []
for i in range(10):
    optimizer.step()
    lrs.append(optimizer.param_groups[0]["lr"])
    scheduler.step()
plt.plot(lrs)

```

I am getting as follow

 ![image](https://discuss.pytorch.org/uploads/default/original/3X/8/d/8dd9613a4fd3c019ce6e977afb51d95dc2b7cbb9.png)  
but this graph is not showing the lowering of the learning rate

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [August 9, 2021, 5:58am UTC](https://discuss.pytorch.org/t/how-to-use-once-cycle-lr-properly/128496/2 "2021-08-09T05:58:57Z")

</div>

You could see the changing behavior by iterating the scheduler for 720 steps, since you’ve specified `steps_per_epoch=72` and `epochs=10`.  
From the docs:

> epochs (int): The number of epochs to train for. This is used along with steps\_per\_epoch in order to infer the total number of steps in the cycle if a value for total\_steps is not provided.
