Repository: pytorch/ignite

Issue:
Raise friendly errors in case of `num_epochs` is less than `num_warmup_epochs` in CIFAR10 and Transformers examples
I was trying to benchmark `torch.inference_mode` vs `torch.no_grad` on CIFAR10 example, so I just wanted to run for 3 epochs and average the benchmarks, the default warmup epochs is 4, so the scheduler will raise this error, which is not very clear to new users 
```
f"Milestones should be increasing integers, but given {pair[0]} is smaller "
ValueError: Milestones should be increasing integers, but given 291 is smaller than the previous milestone 388
```
So I suggest to check `num_epochs` vs `num_warmup_epochs` inside `run` method and raise more clear error message for the users.


Discussion:
Hey , i would like to work on this issue. Can you guide me further?! on what needs to be done🙂
Hey @himanshu007-creator, thanks a lot for showing interest, we have these 2 examples:
- https://github.com/pytorch/ignite/tree/master/examples/contrib/cifar10
- https://github.com/pytorch/ignite/tree/master/examples/contrib/transformers

in both, if the num_epochs is less the num_warmup_epochs, the error in the description will be raised, 
we want to check inside the `run` method in both examples, if `num_epochs` is less than `num_warmupds_epochs` we should raise a friendly error message explaining what's the error and why, and what the user should do (either increase the `num_epochs` or decrease `num_warmup_epochs`)
Please brief me about the issue a little more. I'll work on this issue.
Hi @FarehaNousheen, please check the comment above https://github.com/pytorch/ignite/issues/2207#issuecomment-923125971, it explains what we need to do in depth. If you still can't get what we need to do, please ping me on discord.
Hey @KickItLikeShika, I think adding an assertion can solve this issue. Can you assign this to me?
Hey @KickItLikeShika, I think I've made the necessary changes in three of the files to raise an user friendly message when ``num_epochs`` is greater than ``num_warmup_epochs``. Am I free to create a Pull Request, since this hasn't been assigned to me...

Resolving patch:
diff --git a/examples/contrib/cifar10/main.py b/examples/contrib/cifar10/main.py
--- a/examples/contrib/cifar10/main.py
+++ b/examples/contrib/cifar10/main.py
@@ -187,6 +187,13 @@ def run(
         **spawn_kwargs: Other kwargs to spawn run in child processes: master_addr, master_port, node_rank, nnodes
 
     """
+    # check to see if the num_epochs is greater than or equal to num_warmup_epochs
+    if num_warmup_epochs >= num_epochs:
+        raise ValueError(
+            "num_epochs cannot be less than or equal to num_warmup_epochs, please increase num_epochs or decrease "
+            "num_warmup_epochs"
+        )
+
     # catch all local parameters
     config = locals()
     config.update(config["spawn_kwargs"])
diff --git a/examples/contrib/cifar10_qat/main.py b/examples/contrib/cifar10_qat/main.py
--- a/examples/contrib/cifar10_qat/main.py
+++ b/examples/contrib/cifar10_qat/main.py
@@ -174,6 +174,13 @@ def run(
         **spawn_kwargs: Other kwargs to spawn run in child processes: master_addr, master_port, node_rank, nnodes
 
     """
+    # check to see if the num_epochs is greater than or equal to num_warmup_epochs
+    if num_warmup_epochs >= num_epochs:
+        raise ValueError(
+            "num_epochs cannot be less than or equal to num_warmup_epochs, please increase num_epochs or decrease "
+            "num_warmup_epochs"
+        )
+
     # catch all local parameters
     config = locals()
     config.update(config["spawn_kwargs"])
diff --git a/examples/contrib/transformers/main.py b/examples/contrib/transformers/main.py
--- a/examples/contrib/transformers/main.py
+++ b/examples/contrib/transformers/main.py
@@ -192,6 +192,13 @@ def run(
         with_amp (bool): if True, enables native automatic mixed precision. Default, False.
         **spawn_kwargs: Other kwargs to spawn run in child processes: master_addr, master_port, node_rank, nnodes
     """
+    # check to see if the num_epochs is greater than or equal to num_warmup_epochs
+    if num_warmup_epochs >= num_epochs:
+        raise ValueError(
+            "num_epochs cannot be less than or equal to num_warmup_epochs, please increase num_epochs or decrease "
+            "num_warmup_epochs"
+        )
+
     # catch all local parameters
     config = locals()
     config.update(config["spawn_kwargs"])


Test patch: