mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-12 12:40:20 +08:00
rename variables nb -> num (#567)
* rename nb -> num * flake8 * batch_nb, epoch_nb, gpu_nb, split_nb * add _num deprecations
This commit is contained in:
committed by
William Falcon
parent
63717e8fda
commit
3a58937d8b
+2
-2
@@ -24,12 +24,12 @@ class CoolModel(pl.LightningModule):
|
||||
def my_loss(self, y_hat, y):
|
||||
return F.cross_entropy(y_hat, y)
|
||||
|
||||
def training_step(self, batch, batch_nb):
|
||||
def training_step(self, batch, batch_idx):
|
||||
x, y = batch
|
||||
y_hat = self.forward(x)
|
||||
return {'training_loss': self.my_loss(y_hat, y)}
|
||||
|
||||
def validation_step(self, batch, batch_nb):
|
||||
def validation_step(self, batch, batch_idx):
|
||||
x, y = batch
|
||||
y_hat = self.forward(x)
|
||||
return {'val_loss': self.my_loss(y_hat, y)}
|
||||
|
||||
+6
-6
@@ -23,7 +23,7 @@ def test_amp_single_gpu(tmpdir):
|
||||
trainer_options = dict(
|
||||
default_save_path=tmpdir,
|
||||
show_progress_bar=True,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
gpus=1,
|
||||
distributed_backend='ddp',
|
||||
use_amp=True
|
||||
@@ -45,7 +45,7 @@ def test_no_amp_single_gpu(tmpdir):
|
||||
trainer_options = dict(
|
||||
default_save_path=tmpdir,
|
||||
show_progress_bar=True,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
gpus=1,
|
||||
distributed_backend='dp',
|
||||
use_amp=True
|
||||
@@ -69,7 +69,7 @@ def test_amp_gpu_ddp(tmpdir):
|
||||
trainer_options = dict(
|
||||
default_save_path=tmpdir,
|
||||
show_progress_bar=True,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
gpus=2,
|
||||
distributed_backend='ddp',
|
||||
use_amp=True
|
||||
@@ -94,7 +94,7 @@ def test_amp_gpu_ddp_slurm_managed(tmpdir):
|
||||
|
||||
trainer_options = dict(
|
||||
show_progress_bar=True,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
gpus=[0],
|
||||
distributed_backend='ddp',
|
||||
use_amp=True
|
||||
@@ -153,7 +153,7 @@ def test_cpu_model_with_amp(tmpdir):
|
||||
default_save_path=tmpdir,
|
||||
show_progress_bar=False,
|
||||
logger=tutils.get_test_tube_logger(tmpdir),
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.4,
|
||||
use_amp=True
|
||||
@@ -175,7 +175,7 @@ def test_amp_gpu_dp(tmpdir):
|
||||
model, hparams = tutils.get_model()
|
||||
trainer_options = dict(
|
||||
default_save_path=tmpdir,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
gpus='0, 1', # test init with gpu string
|
||||
distributed_backend='dp',
|
||||
use_amp=True
|
||||
|
||||
@@ -46,7 +46,7 @@ def test_lbfgs_cpu_model(tmpdir):
|
||||
|
||||
trainer_options = dict(
|
||||
default_save_path=tmpdir,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
print_nan_grads=True,
|
||||
show_progress_bar=False,
|
||||
weights_summary='top',
|
||||
@@ -64,7 +64,7 @@ def test_default_logger_callbacks_cpu_model(tmpdir):
|
||||
|
||||
trainer_options = dict(
|
||||
default_save_path=tmpdir,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
gradient_clip_val=1.0,
|
||||
overfit_pct=0.20,
|
||||
print_nan_grads=True,
|
||||
@@ -97,7 +97,7 @@ def test_running_test_after_fitting(tmpdir):
|
||||
trainer_options = dict(
|
||||
default_save_path=tmpdir,
|
||||
show_progress_bar=False,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.2,
|
||||
test_percent_check=0.2,
|
||||
@@ -135,7 +135,7 @@ def test_running_test_without_val(tmpdir):
|
||||
|
||||
trainer_options = dict(
|
||||
show_progress_bar=False,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.2,
|
||||
test_percent_check=0.2,
|
||||
@@ -209,7 +209,7 @@ def test_simple_cpu(tmpdir):
|
||||
# logger file to get meta
|
||||
trainer_options = dict(
|
||||
default_save_path=tmpdir,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
val_percent_check=0.1,
|
||||
train_percent_check=0.1,
|
||||
)
|
||||
@@ -230,7 +230,7 @@ def test_cpu_model(tmpdir):
|
||||
default_save_path=tmpdir,
|
||||
show_progress_bar=False,
|
||||
logger=tutils.get_test_tube_logger(tmpdir),
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.4
|
||||
)
|
||||
@@ -253,7 +253,7 @@ def test_all_features_cpu_model(tmpdir):
|
||||
show_progress_bar=False,
|
||||
logger=tutils.get_test_tube_logger(tmpdir),
|
||||
accumulate_grad_batches=2,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.4
|
||||
)
|
||||
@@ -314,7 +314,7 @@ def test_tbptt_cpu_model(tmpdir):
|
||||
|
||||
trainer_options = dict(
|
||||
default_save_path=tmpdir,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
truncated_bptt_steps=truncated_bptt_steps,
|
||||
val_percent_check=0,
|
||||
weights_summary=None,
|
||||
@@ -348,7 +348,7 @@ def test_single_gpu_model(tmpdir):
|
||||
trainer_options = dict(
|
||||
default_save_path=tmpdir,
|
||||
show_progress_bar=False,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.1,
|
||||
val_percent_check=0.1,
|
||||
gpus=1
|
||||
|
||||
@@ -33,7 +33,7 @@ def test_multi_gpu_model_ddp2(tmpdir):
|
||||
trainer_options = dict(
|
||||
default_save_path=tmpdir,
|
||||
show_progress_bar=True,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.2,
|
||||
gpus=2,
|
||||
@@ -56,7 +56,7 @@ def test_multi_gpu_model_ddp(tmpdir):
|
||||
trainer_options = dict(
|
||||
default_save_path=tmpdir,
|
||||
show_progress_bar=False,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.2,
|
||||
gpus=[0, 1],
|
||||
@@ -109,7 +109,7 @@ def test_cpu_slurm_save_load(tmpdir):
|
||||
version = logger.version
|
||||
|
||||
trainer_options = dict(
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
logger=logger,
|
||||
checkpoint_callback=ModelCheckpoint(tmpdir)
|
||||
)
|
||||
@@ -143,7 +143,7 @@ def test_cpu_slurm_save_load(tmpdir):
|
||||
logger = tutils.get_test_tube_logger(tmpdir, False, version=version)
|
||||
|
||||
trainer_options = dict(
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
logger=logger,
|
||||
checkpoint_callback=ModelCheckpoint(tmpdir),
|
||||
)
|
||||
@@ -177,7 +177,7 @@ def test_multi_gpu_none_backend(tmpdir):
|
||||
trainer_options = dict(
|
||||
default_save_path=tmpdir,
|
||||
show_progress_bar=False,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.1,
|
||||
val_percent_check=0.1,
|
||||
gpus='-1'
|
||||
@@ -199,7 +199,7 @@ def test_multi_gpu_model_dp(tmpdir):
|
||||
default_save_path=tmpdir,
|
||||
show_progress_bar=False,
|
||||
distributed_backend='dp',
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.1,
|
||||
val_percent_check=0.1,
|
||||
gpus='-1'
|
||||
@@ -227,7 +227,7 @@ def test_ddp_sampler_error(tmpdir):
|
||||
trainer = Trainer(
|
||||
logger=logger,
|
||||
show_progress_bar=False,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
gpus=[0, 1],
|
||||
distributed_backend='ddp',
|
||||
use_amp=True
|
||||
|
||||
@@ -16,7 +16,7 @@ def test_testtube_logger(tmpdir):
|
||||
logger = tutils.get_test_tube_logger(tmpdir, False)
|
||||
|
||||
trainer_options = dict(
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.01,
|
||||
logger=logger
|
||||
)
|
||||
@@ -39,7 +39,7 @@ def test_testtube_pickle(tmpdir):
|
||||
logger.save()
|
||||
|
||||
trainer_options = dict(
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.01,
|
||||
logger=logger
|
||||
)
|
||||
@@ -67,7 +67,7 @@ def test_mlflow_logger(tmpdir):
|
||||
logger = MLFlowLogger("test", f"file://{mlflow_dir}")
|
||||
|
||||
trainer_options = dict(
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.01,
|
||||
logger=logger
|
||||
)
|
||||
@@ -96,7 +96,7 @@ def test_mlflow_pickle(tmpdir):
|
||||
logger = MLFlowLogger("test", f"file://{mlflow_dir}")
|
||||
|
||||
trainer_options = dict(
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
logger=logger
|
||||
)
|
||||
|
||||
@@ -128,7 +128,7 @@ def test_comet_logger(tmpdir):
|
||||
)
|
||||
|
||||
trainer_options = dict(
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.01,
|
||||
logger=logger
|
||||
)
|
||||
@@ -162,7 +162,7 @@ def test_comet_pickle(tmpdir):
|
||||
)
|
||||
|
||||
trainer_options = dict(
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
logger=logger
|
||||
)
|
||||
|
||||
@@ -185,7 +185,7 @@ def test_custom_logger(tmpdir):
|
||||
self.hparams_logged = params
|
||||
|
||||
@rank_zero_only
|
||||
def log_metrics(self, metrics, step_num):
|
||||
def log_metrics(self, metrics, step_idx):
|
||||
self.metrics_logged = metrics
|
||||
|
||||
@rank_zero_only
|
||||
@@ -206,7 +206,7 @@ def test_custom_logger(tmpdir):
|
||||
logger = CustomLogger()
|
||||
|
||||
trainer_options = dict(
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.01,
|
||||
logger=logger,
|
||||
default_save_path=tmpdir
|
||||
|
||||
@@ -28,7 +28,7 @@ def test_running_test_pretrained_model_ddp(tmpdir):
|
||||
|
||||
trainer_options = dict(
|
||||
show_progress_bar=False,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.2,
|
||||
checkpoint_callback=checkpoint,
|
||||
@@ -73,7 +73,7 @@ def test_running_test_pretrained_model(tmpdir):
|
||||
|
||||
trainer_options = dict(
|
||||
show_progress_bar=False,
|
||||
max_nb_epochs=4,
|
||||
max_num_epochs=4,
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.2,
|
||||
checkpoint_callback=checkpoint,
|
||||
@@ -106,7 +106,7 @@ def test_load_model_from_checkpoint(tmpdir):
|
||||
|
||||
trainer_options = dict(
|
||||
show_progress_bar=False,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.2,
|
||||
checkpoint_callback=True,
|
||||
@@ -153,7 +153,7 @@ def test_running_test_pretrained_model_dp(tmpdir):
|
||||
|
||||
trainer_options = dict(
|
||||
show_progress_bar=True,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.2,
|
||||
checkpoint_callback=checkpoint,
|
||||
@@ -191,7 +191,7 @@ def test_dp_resume(tmpdir):
|
||||
|
||||
trainer_options = dict(
|
||||
show_progress_bar=True,
|
||||
max_nb_epochs=2,
|
||||
max_num_epochs=2,
|
||||
gpus=2,
|
||||
distributed_backend='dp',
|
||||
)
|
||||
@@ -230,7 +230,7 @@ def test_dp_resume(tmpdir):
|
||||
trainer_options['checkpoint_callback'] = ModelCheckpoint(tmpdir)
|
||||
trainer_options['train_percent_check'] = 0.2
|
||||
trainer_options['val_percent_check'] = 0.2
|
||||
trainer_options['max_nb_epochs'] = 1
|
||||
trainer_options['max_num_epochs'] = 1
|
||||
new_trainer = Trainer(**trainer_options)
|
||||
|
||||
# set the epoch start hook so we can predict before the model does the full training
|
||||
@@ -269,7 +269,7 @@ def test_cpu_restore_training(tmpdir):
|
||||
logger = tutils.get_test_tube_logger(tmpdir, False, version=test_logger_version)
|
||||
|
||||
trainer_options = dict(
|
||||
max_nb_epochs=2,
|
||||
max_num_epochs=2,
|
||||
val_check_interval=0.50,
|
||||
val_percent_check=0.2,
|
||||
train_percent_check=0.2,
|
||||
@@ -290,7 +290,7 @@ def test_cpu_restore_training(tmpdir):
|
||||
# we want to see if the weights come back correctly
|
||||
new_logger = tutils.get_test_tube_logger(tmpdir, False, version=test_logger_version)
|
||||
trainer_options = dict(
|
||||
max_nb_epochs=2,
|
||||
max_num_epochs=2,
|
||||
val_check_interval=0.50,
|
||||
val_percent_check=0.2,
|
||||
train_percent_check=0.2,
|
||||
@@ -329,7 +329,7 @@ def test_model_saving_loading(tmpdir):
|
||||
logger = tutils.get_test_tube_logger(tmpdir, False)
|
||||
|
||||
trainer_options = dict(
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
logger=logger,
|
||||
checkpoint_callback=ModelCheckpoint(tmpdir)
|
||||
)
|
||||
|
||||
+25
-25
@@ -34,7 +34,7 @@ def test_no_val_module(tmpdir):
|
||||
logger = tutils.get_test_tube_logger(tmpdir, False)
|
||||
|
||||
trainer_options = dict(
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
logger=logger,
|
||||
checkpoint_callback=ModelCheckpoint(tmpdir)
|
||||
)
|
||||
@@ -72,7 +72,7 @@ def test_no_val_end_module(tmpdir):
|
||||
logger = tutils.get_test_tube_logger(tmpdir, False)
|
||||
|
||||
trainer_options = dict(
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
logger=logger,
|
||||
checkpoint_callback=ModelCheckpoint(tmpdir)
|
||||
)
|
||||
@@ -114,40 +114,40 @@ def test_gradient_accumulation_scheduling(tmpdir):
|
||||
assert Trainer(accumulate_grad_batches={1: 2.5, 3: 5})
|
||||
|
||||
# test optimizer call freq matches scheduler
|
||||
def optimizer_step(self, epoch_nb, batch_nb, optimizer, optimizer_i, second_order_closure=None):
|
||||
def optimizer_step(self, epoch_idx, batch_idx, optimizer, optimizer_idx, second_order_closure=None):
|
||||
# only test the first 12 batches in epoch
|
||||
if batch_nb < 12:
|
||||
if epoch_nb == 0:
|
||||
if batch_idx < 12:
|
||||
if epoch_idx == 0:
|
||||
# reset counter when starting epoch
|
||||
if batch_nb == 0:
|
||||
self.prev_called_batch_nb = 0
|
||||
if batch_idx == 0:
|
||||
self.prev_called_batch_idx = 0
|
||||
|
||||
# use this opportunity to test once
|
||||
assert self.trainer.accumulate_grad_batches == 1
|
||||
|
||||
assert batch_nb == self.prev_called_batch_nb
|
||||
self.prev_called_batch_nb += 1
|
||||
assert batch_idx == self.prev_called_batch_idx
|
||||
self.prev_called_batch_idx += 1
|
||||
|
||||
elif 1 <= epoch_nb <= 2:
|
||||
elif 1 <= epoch_idx <= 2:
|
||||
# reset counter when starting epoch
|
||||
if batch_nb == 1:
|
||||
self.prev_called_batch_nb = 1
|
||||
if batch_idx == 1:
|
||||
self.prev_called_batch_idx = 1
|
||||
|
||||
# use this opportunity to test once
|
||||
assert self.trainer.accumulate_grad_batches == 2
|
||||
|
||||
assert batch_nb == self.prev_called_batch_nb
|
||||
self.prev_called_batch_nb += 2
|
||||
assert batch_idx == self.prev_called_batch_idx
|
||||
self.prev_called_batch_idx += 2
|
||||
|
||||
else:
|
||||
if batch_nb == 3:
|
||||
self.prev_called_batch_nb = 3
|
||||
if batch_idx == 3:
|
||||
self.prev_called_batch_idx = 3
|
||||
|
||||
# use this opportunity to test once
|
||||
assert self.trainer.accumulate_grad_batches == 4
|
||||
|
||||
assert batch_nb == self.prev_called_batch_nb
|
||||
self.prev_called_batch_nb += 3
|
||||
assert batch_idx == self.prev_called_batch_idx
|
||||
self.prev_called_batch_idx += 3
|
||||
|
||||
optimizer.step()
|
||||
|
||||
@@ -161,12 +161,12 @@ def test_gradient_accumulation_scheduling(tmpdir):
|
||||
trainer = Trainer(accumulate_grad_batches=schedule,
|
||||
train_percent_check=0.1,
|
||||
val_percent_check=0.1,
|
||||
max_nb_epochs=4,
|
||||
max_num_epochs=4,
|
||||
default_save_path=tmpdir)
|
||||
|
||||
# for the test
|
||||
trainer.optimizer_step = optimizer_step
|
||||
model.prev_called_batch_nb = 0
|
||||
model.prev_called_batch_idx = 0
|
||||
|
||||
trainer.fit(model)
|
||||
|
||||
@@ -198,10 +198,10 @@ def test_dp_output_reduce():
|
||||
|
||||
# test identity when we have a single gpu
|
||||
out = torch.rand(3, 1)
|
||||
assert mixin.reduce_distributed_output(out, nb_gpus=1) is out
|
||||
assert mixin.reduce_distributed_output(out, num_gpus=1) is out
|
||||
|
||||
# average when we have multiples
|
||||
assert mixin.reduce_distributed_output(out, nb_gpus=2) == out.mean()
|
||||
assert mixin.reduce_distributed_output(out, num_gpus=2) == out.mean()
|
||||
|
||||
# when we have a dict of vals
|
||||
out = {
|
||||
@@ -210,7 +210,7 @@ def test_dp_output_reduce():
|
||||
'c': out
|
||||
}
|
||||
}
|
||||
reduced = mixin.reduce_distributed_output(out, nb_gpus=3)
|
||||
reduced = mixin.reduce_distributed_output(out, num_gpus=3)
|
||||
assert reduced['a'] == out['a']
|
||||
assert reduced['b']['c'] == out['b']['c']
|
||||
|
||||
@@ -354,7 +354,7 @@ def test_multiple_val_dataloader(tmpdir):
|
||||
# logger file to get meta
|
||||
trainer_options = dict(
|
||||
default_save_path=tmpdir,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
val_percent_check=0.1,
|
||||
train_percent_check=1.0,
|
||||
)
|
||||
@@ -391,7 +391,7 @@ def test_multiple_test_dataloader(tmpdir):
|
||||
# logger file to get meta
|
||||
trainer_options = dict(
|
||||
default_save_path=tmpdir,
|
||||
max_nb_epochs=1,
|
||||
max_num_epochs=1,
|
||||
val_percent_check=0.1,
|
||||
train_percent_check=0.1,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user