@@ -109,7 +109,7 @@ def training_step(self, *args, **kwargs):
109
109
"""return loss, dict with metrics for tqdm
110
110
111
111
:param batch: The output of your dataloader. A tensor, tuple or list
112
- :param int batch_nb : Integer displaying which batch this is
112
+ :param int batch_idx : Integer displaying which batch this is
113
113
:return: dict with loss key and optional log, progress keys
114
114
if implementing training_step, return whatever you need in that step:
115
115
- loss -> tensor scalar [REQUIRED]
@@ -124,7 +124,7 @@ def training_step(self, *args, **kwargs):
124
124
125
125
.. code-block:: python
126
126
127
- def training_step(self, batch, batch_nb ):
127
+ def training_step(self, batch, batch_idx ):
128
128
x, y, z = batch
129
129
130
130
# implement your own
@@ -150,7 +150,7 @@ def training_step(self, batch, batch_nb):
150
150
.. code-block:: python
151
151
152
152
# Multiple optimizers (ie: GANs)
153
- def training_step(self, batch, batch_nb , optimizer_idx):
153
+ def training_step(self, batch, batch_idx , optimizer_idx):
154
154
if optimizer_idx == 0:
155
155
# do training_step with encoder
156
156
if optimizer_idx == 1:
@@ -163,7 +163,7 @@ def training_step(self, batch, batch_nb, optimizer_idx):
163
163
.. code-block:: python
164
164
165
165
# Truncated back-propagation through time
166
- def training_step(self, batch, batch_nb , hiddens):
166
+ def training_step(self, batch, batch_idx , hiddens):
167
167
# hiddens are the hiddens from the previous truncated backprop step
168
168
169
169
You can also return a -1 instead of a dict to stop the current loop. This is useful
@@ -192,9 +192,9 @@ def training_end(self, *args, **kwargs):
192
192
.. code-block:: python
193
193
194
194
# WITHOUT training_end
195
- # if used in DP or DDP2, this batch is 1/nb_gpus large
196
- def training_step(self, batch, batch_nb ):
197
- # batch is 1/nb_gpus big
195
+ # if used in DP or DDP2, this batch is 1/num_gpus large
196
+ def training_step(self, batch, batch_idx ):
197
+ # batch is 1/num_gpus big
198
198
x, y = batch
199
199
200
200
out = self.forward(x)
@@ -204,8 +204,8 @@ def training_step(self, batch, batch_nb):
204
204
205
205
# --------------
206
206
# with training_end to do softmax over the full batch
207
- def training_step(self, batch, batch_nb ):
208
- # batch is 1/nb_gpus big
207
+ def training_step(self, batch, batch_idx ):
208
+ # batch is 1/num_gpus big
209
209
x, y = batch
210
210
211
211
out = self.forward(x)
@@ -225,7 +225,7 @@ def training_end(self, outputs):
225
225
.. code-block:: python
226
226
227
227
# Multiple optimizers (ie: GANs)
228
- def training_step(self, batch, batch_nb , optimizer_idx):
228
+ def training_step(self, batch, batch_idx , optimizer_idx):
229
229
if optimizer_idx == 0:
230
230
# do training_step with encoder
231
231
if optimizer_idx == 1:
@@ -237,7 +237,7 @@ def training_step(self, batch, batch_nb, optimizer_idx):
237
237
.. code-block:: python
238
238
239
239
# Truncated back-propagation through time
240
- def training_step(self, batch, batch_nb , hiddens):
240
+ def training_step(self, batch, batch_idx , hiddens):
241
241
# hiddens are the hiddens from the previous truncated backprop step
242
242
243
243
You can also return a -1 instead of a dict to stop the current loop. This is useful if you want to
@@ -249,17 +249,17 @@ def validation_step(self, *args, **kwargs):
249
249
"""return whatever outputs will need to be aggregated in validation_end
250
250
251
251
:param batch: The output of your dataloader. A tensor, tuple or list
252
- :param int batch_nb : Integer displaying which batch this is
252
+ :param int batch_idx : Integer displaying which batch this is
253
253
:param int dataloader_idx: Integer displaying which dataloader this is (only if multiple val datasets used)
254
254
:return dict: Dict or OrderedDict - passed to the validation_end step
255
255
256
256
.. code-block:: python
257
257
258
258
# if you have one val dataloader:
259
- def validation_step(self, batch, batch_nb )
259
+ def validation_step(self, batch, batch_idx )
260
260
261
261
# if you have multiple val dataloaders:
262
- def validation_step(self, batch, batch_nb , dataloader_idxdx)
262
+ def validation_step(self, batch, batch_idx , dataloader_idxdx)
263
263
264
264
If you don't need to validate you don't need to implement this method.
265
265
In this step you'd normally generate examples or calculate anything of interest such as accuracy.
@@ -275,7 +275,7 @@ def validation_step(self, batch, batch_nb, dataloader_idxdx)
275
275
.. code-block:: python
276
276
277
277
# CASE 1: A single validation dataset
278
- def validation_step(self, batch, batch_nb ):
278
+ def validation_step(self, batch, batch_idx ):
279
279
x, y = batch
280
280
281
281
# implement your own
@@ -307,7 +307,7 @@ def validation_step(self, batch, batch_nb):
307
307
.. code-block:: python
308
308
309
309
# CASE 2: multiple validation datasets
310
- def validation_step(self, batch, batch_nb , dataset_idx):
310
+ def validation_step(self, batch, batch_idx , dataset_idx):
311
311
# dataset_idx tells you which dataset this is.
312
312
313
313
The `dataset_idx` corresponds to the order of datasets returned in `val_dataloader`.
@@ -318,17 +318,17 @@ def test_step(self, *args, **kwargs):
318
318
"""return whatever outputs will need to be aggregated in test_end
319
319
320
320
:param batch: The output of your dataloader. A tensor, tuple or list
321
- :param int batch_nb : Integer displaying which batch this is
321
+ :param int batch_idx : Integer displaying which batch this is
322
322
:param int dataloader_idx: Integer displaying which dataloader this is (only if multiple test datasets used)
323
323
:return dict: Dict or OrderedDict with metrics to display in progress bar. All keys must be tensors.
324
324
325
325
.. code-block:: python
326
326
327
327
# if you have one test dataloader:
328
- def test_step(self, batch, batch_nb )
328
+ def test_step(self, batch, batch_idx )
329
329
330
330
# if you have multiple test dataloaders:
331
- def test_step(self, batch, batch_nb , dataloader_idxdx)
331
+ def test_step(self, batch, batch_idx , dataloader_idxdx)
332
332
333
333
334
334
**OPTIONAL**
@@ -348,7 +348,7 @@ def test_step(self, batch, batch_nb, dataloader_idxdx)
348
348
.. code-block:: python
349
349
350
350
# CASE 1: A single test dataset
351
- def test_step(self, batch, batch_nb ):
351
+ def test_step(self, batch, batch_idx ):
352
352
x, y = batch
353
353
354
354
# implement your own
@@ -375,7 +375,7 @@ def test_step(self, batch, batch_nb):
375
375
.. code-block:: python
376
376
377
377
# CASE 2: multiple test datasets
378
- def test_step(self, batch, batch_nb , dataset_idx):
378
+ def test_step(self, batch, batch_idx , dataset_idx):
379
379
# dataset_idx tells you which dataset this is.
380
380
381
381
@@ -694,13 +694,13 @@ def configure_optimizers(self):
694
694
"""
695
695
raise NotImplementedError
696
696
697
- def optimizer_step (self , epoch_nb , batch_nb , optimizer , optimizer_i , second_order_closure = None ):
697
+ def optimizer_step (self , epoch_idx , batch_idx , optimizer , optimizer_idx , second_order_closure = None ):
698
698
"""Do something instead of the standard optimizer behavior
699
699
700
- :param int epoch_nb :
701
- :param int batch_nb :
700
+ :param int epoch_idx :
701
+ :param int batch_idx :
702
702
:param optimizer:
703
- :param optimizer_i :
703
+ :param optimizer_idx :
704
704
:param second_order_closure: closure for second order methods
705
705
:return:
706
706
@@ -712,21 +712,21 @@ def optimizer_step(self, epoch_nb, batch_nb, optimizer, optimizer_i, second_orde
712
712
.. code-block:: python
713
713
714
714
# DEFAULT
715
- def optimizer_step(self, current_epoch, batch_nb , optimizer, optimizer_i , second_order_closure=None):
715
+ def optimizer_step(self, current_epoch, batch_idx , optimizer, optimizer_idx , second_order_closure=None):
716
716
optimizer.step()
717
717
optimizer.zero_grad()
718
718
719
719
# Alternating schedule for optimizer steps (ie: GANs)
720
- def optimizer_step(self, current_epoch, batch_nb , optimizer, optimizer_i , second_order_closure=None):
720
+ def optimizer_step(self, current_epoch, batch_idx , optimizer, optimizer_idx , second_order_closure=None):
721
721
# update generator opt every 2 steps
722
- if optimizer_i == 0:
723
- if batch_nb % 2 == 0 :
722
+ if optimizer_idx == 0:
723
+ if batch_idx % 2 == 0 :
724
724
optimizer.step()
725
725
optimizer.zero_grad()
726
726
727
727
# update discriminator opt every 4 steps
728
- if optimizer_i == 1:
729
- if batch_nb % 4 == 0 :
728
+ if optimizer_idx == 1:
729
+ if batch_idx % 4 == 0 :
730
730
optimizer.step()
731
731
optimizer.zero_grad()
732
732
@@ -739,7 +739,7 @@ def optimizer_step(self, current_epoch, batch_nb, optimizer, optimizer_i, second
739
739
.. code-block:: python
740
740
741
741
# learning rate warm-up
742
- def optimizer_step(self, current_epoch, batch_nb , optimizer, optimizer_i , second_order_closure=None):
742
+ def optimizer_step(self, current_epoch, batch_idx , optimizer, optimizer_idx , second_order_closure=None):
743
743
# warm up lr
744
744
if self.trainer.global_step < 500:
745
745
lr_scale = min(1., float(self.trainer.global_step + 1) / 500.)
0 commit comments