Repository: pytorch/ignite

Issue:
tqdm_logger does not take epoch_length into account
## 🐛 `tqdm_logger` does not take `epoch_length` into account

When calling `Engine.run()` with a custom `epoch_length`,
the tqdm progress bar does not adapt and displays the full number of batches in the data.
Here is a minimal example:
```python
from ignite.contrib.handlers.tqdm_logger import ProgressBar
from ignite.engine import Engine
from torch import nn
from torch.utils.data import DataLoader

data = list(range(100))
model = nn.Identity()
engine = Engine(lambda engine, batch: model(batch))

ProgressBar(persist=True).attach(engine)
engine.run(data, epoch_length=50)
```
We have 100 items in `data` but the true end of the epoch is at 50 iterations, yet the progress is displayed over the range of 100 and just ends midway, when I expect it to be displayed over the range of 50, thus ending when the bar is full.
One can not overwrite tqdm's `total` argument by replacing
```python
ProgressBar(persist=True).attach(engine)
```
by
```python
ProgressBar(persist=True, total=50).attach(engine)
```
for it raises `TypeError: type object got multiple values for keyword argument 'total'`.

## Environment
 - PyTorch Version : 1.4.0 
 - Ignite Version : 0.3.0
 - OS : Ubuntu 19.04
 - Ignite installation method : `pip`
 - Python version: 3.7.3



Discussion:
@remisphere thanks for the feedback! We need to fix it here:  
https://github.com/pytorch/ignite/blob/0f97baff7f718f2917421774e2daf7819561c047/ignite/contrib/handlers/tqdm_logger.py#L220-L221
as 
```python
if event_name in (Events.ITERATION_STARTED, Events.ITERATION_COMPLETED): 
    return engine.state.epoch_length
```

Resolving patch:
diff --git a/ignite/contrib/handlers/tqdm_logger.py b/ignite/contrib/handlers/tqdm_logger.py
--- a/ignite/contrib/handlers/tqdm_logger.py
+++ b/ignite/contrib/handlers/tqdm_logger.py
@@ -218,7 +218,7 @@ def __init__(self, description, metric_names=None, output_transform=None,
     @staticmethod
     def get_max_number_events(event_name, engine):
         if event_name in (Events.ITERATION_STARTED, Events.ITERATION_COMPLETED):
-            return len(engine.state.dataloader)
+            return engine.state.epoch_length
         if event_name in (Events.EPOCH_STARTED, Events.EPOCH_COMPLETED):
             return engine.state.max_epochs
         return 1


Test patch:
diff --git a/tests/ignite/contrib/handlers/test_tqdm_logger.py b/tests/ignite/contrib/handlers/test_tqdm_logger.py
--- a/tests/ignite/contrib/handlers/test_tqdm_logger.py
+++ b/tests/ignite/contrib/handlers/test_tqdm_logger.py
@@ -424,3 +424,19 @@ def test_pbar_on_callable_events(capsys):
     actual = err[-1]
     expected = u'Epoch: [90/100]  90%|█████████  [00:00<00:00]'
     assert actual == expected
+
+
+def test_tqdm_logger_epoch_length(capsys):
+    loader = list(range(100))
+    engine = Engine(update_fn)
+    pbar = ProgressBar(persist=True)
+    pbar.attach(engine)
+    engine.run(loader, epoch_length=50)
+
+    captured = capsys.readouterr()
+    err = captured.err.split('\r')
+    err = list(map(lambda x: x.strip(), err))
+    err = list(filter(None, err))
+    actual = err[-1]
+    expected = u'Epoch: [50/50] 100%|██████████ [00:00<00:00]'
+    assert actual == expected