move unnecessary dict trainer_options (#1469)

* move unnecessary dict trainer_options

* fix tests

* fix tests

* formatting

* missing
This commit is contained in:
Jirka Borovec
2020-05-01 10:43:58 -04:00
committed by GitHub
parent 97c7b6b314
commit 34bc149359
14 changed files with 161 additions and 301 deletions
+9 -15
View File
@@ -20,7 +20,7 @@ def test_amp_single_gpu(tmpdir, backend):
model, hparams = tutils.get_default_model()
trainer_options = dict(
trainer = Trainer(
default_root_dir=tmpdir,
max_epochs=1,
gpus=1,
@@ -29,8 +29,6 @@ def test_amp_single_gpu(tmpdir, backend):
)
# tutils.run_model_test(trainer_options, model)
trainer = Trainer(**trainer_options)
result = trainer.fit(model)
assert result == 1
@@ -74,25 +72,21 @@ def test_amp_gpu_ddp_slurm_managed(tmpdir):
hparams = tutils.get_default_hparams()
model = LightningTestModel(hparams)
trainer_options = dict(
max_epochs=1,
gpus=[0],
distributed_backend='ddp',
precision=16
)
# exp file to get meta
logger = tutils.get_default_logger(tmpdir)
# exp file to get weights
checkpoint = tutils.init_checkpoint_callback(logger)
# add these to the trainer options
trainer_options['checkpoint_callback'] = checkpoint
trainer_options['logger'] = logger
# fit model
trainer = Trainer(**trainer_options)
trainer = Trainer(
max_epochs=1,
gpus=[0],
distributed_backend='ddp',
precision=16,
checkpoint_callback=checkpoint,
logger=logger,
)
trainer.is_slurm_managing_tasks = True
result = trainer.fit(model)
+14 -23
View File
@@ -120,7 +120,8 @@ def test_running_test_after_fitting(tmpdir):
# logger file to get weights
checkpoint = tutils.init_checkpoint_callback(logger)
trainer_options = dict(
# fit model
trainer = Trainer(
default_root_dir=tmpdir,
progress_bar_refresh_rate=0,
max_epochs=8,
@@ -130,9 +131,6 @@ def test_running_test_after_fitting(tmpdir):
checkpoint_callback=checkpoint,
logger=logger
)
# fit model
trainer = Trainer(**trainer_options)
result = trainer.fit(model)
assert result == 1, 'training failed to complete'
@@ -159,7 +157,8 @@ def test_running_test_no_val(tmpdir):
# logger file to get weights
checkpoint = tutils.init_checkpoint_callback(logger)
trainer_options = dict(
# fit model
trainer = Trainer(
progress_bar_refresh_rate=0,
max_epochs=1,
train_percent_check=0.4,
@@ -169,9 +168,6 @@ def test_running_test_no_val(tmpdir):
logger=logger,
early_stop_callback=False
)
# fit model
trainer = Trainer(**trainer_options)
result = trainer.fit(model)
assert result == 1, 'training failed to complete'
@@ -238,16 +234,13 @@ def test_simple_cpu(tmpdir):
hparams = tutils.get_default_hparams()
model = LightningTestModel(hparams)
# logger file to get meta
trainer_options = dict(
# fit model
trainer = Trainer(
default_root_dir=tmpdir,
max_epochs=1,
val_percent_check=0.1,
train_percent_check=0.1,
)
# fit model
trainer = Trainer(**trainer_options)
result = trainer.fit(model)
# traning complete
@@ -340,15 +333,6 @@ def test_tbptt_cpu_model(tmpdir):
sampler=None,
)
trainer_options = dict(
default_root_dir=tmpdir,
max_epochs=1,
truncated_bptt_steps=truncated_bptt_steps,
val_percent_check=0,
weights_summary=None,
early_stop_callback=False
)
hparams = tutils.get_default_hparams()
hparams.batch_size = batch_size
hparams.in_features = truncated_bptt_steps
@@ -358,7 +342,14 @@ def test_tbptt_cpu_model(tmpdir):
model = BpttTestModel(hparams)
# fit model
trainer = Trainer(**trainer_options)
trainer = Trainer(
default_root_dir=tmpdir,
max_epochs=1,
truncated_bptt_steps=truncated_bptt_steps,
val_percent_check=0,
weights_summary=None,
early_stop_callback=False
)
result = trainer.fit(model)
assert result == 1, 'training failed to complete'
+15 -18
View File
@@ -50,19 +50,19 @@ def test_ddp_all_dataloaders_passed_to_fit(tmpdir):
tutils.set_random_master_port()
model, hparams = tutils.get_default_model()
trainer_options = dict(default_root_dir=tmpdir,
progress_bar_refresh_rate=0,
max_epochs=1,
train_percent_check=0.4,
val_percent_check=0.2,
gpus=[0, 1],
distributed_backend='ddp')
fit_options = dict(train_dataloader=model.train_dataloader(),
val_dataloaders=model.val_dataloader())
trainer = Trainer(**trainer_options)
result = trainer.fit(model, **fit_options)
trainer = Trainer(
default_root_dir=tmpdir,
progress_bar_refresh_rate=0,
max_epochs=1,
train_percent_check=0.4,
val_percent_check=0.2,
gpus=[0, 1],
distributed_backend='ddp'
)
result = trainer.fit(model,
train_dataloader=model.train_dataloader(),
val_dataloaders=model.val_dataloader())
assert result == 1, "DDP doesn't work with dataloaders passed to fit()."
@@ -77,14 +77,12 @@ def test_cpu_slurm_save_load(tmpdir):
logger = tutils.get_default_logger(tmpdir)
version = logger.version
trainer_options = dict(
# fit model
trainer = Trainer(
max_epochs=1,
logger=logger,
checkpoint_callback=ModelCheckpoint(tmpdir)
)
# fit model
trainer = Trainer(**trainer_options)
result = trainer.fit(model)
real_global_step = trainer.global_step
@@ -115,12 +113,11 @@ def test_cpu_slurm_save_load(tmpdir):
# new logger file to get meta
logger = tutils.get_default_logger(tmpdir, version=version)
trainer_options = dict(
trainer = Trainer(
max_epochs=1,
logger=logger,
checkpoint_callback=ModelCheckpoint(tmpdir),
)
trainer = Trainer(**trainer_options)
model = LightningTestModel(hparams)
# set the epoch start hook so we can predict before the model does the full training
+18 -22
View File
@@ -163,12 +163,6 @@ def test_dp_resume(tmpdir):
hparams = tutils.get_default_hparams()
model = LightningTestModel(hparams)
trainer_options = dict(
max_epochs=1,
gpus=2,
distributed_backend='dp',
)
# get logger
logger = tutils.get_default_logger(tmpdir)
@@ -176,9 +170,13 @@ def test_dp_resume(tmpdir):
# logger file to get weights
checkpoint = tutils.init_checkpoint_callback(logger)
# add these to the trainer options
trainer_options['logger'] = logger
trainer_options['checkpoint_callback'] = checkpoint
trainer_options = dict(
max_epochs=1,
gpus=2,
distributed_backend='dp',
logger=logger,
checkpoint_callback=checkpoint,
)
# fit model
trainer = Trainer(**trainer_options)
@@ -199,11 +197,13 @@ def test_dp_resume(tmpdir):
# init new trainer
new_logger = tutils.get_default_logger(tmpdir, version=logger.version)
trainer_options['logger'] = new_logger
trainer_options['checkpoint_callback'] = ModelCheckpoint(tmpdir)
trainer_options['train_percent_check'] = 0.5
trainer_options['val_percent_check'] = 0.2
trainer_options['max_epochs'] = 1
trainer_options.update(
logger=new_logger,
checkpoint_callback=ModelCheckpoint(tmpdir),
train_percent_check=0.5,
val_percent_check=0.2,
max_epochs=1,
)
new_trainer = Trainer(**trainer_options)
# set the epoch start hook so we can predict before the model does the full training
@@ -240,14 +240,12 @@ def test_model_saving_loading(tmpdir):
# logger file to get meta
logger = tutils.get_default_logger(tmpdir)
trainer_options = dict(
# fit model
trainer = Trainer(
max_epochs=1,
logger=logger,
checkpoint_callback=ModelCheckpoint(tmpdir)
)
# fit model
trainer = Trainer(**trainer_options)
result = trainer.fit(model)
# traning complete
@@ -289,7 +287,8 @@ def test_model_saving_loading(tmpdir):
def test_load_model_with_missing_hparams(tmpdir):
trainer_options = dict(
# fit model
trainer = Trainer(
progress_bar_refresh_rate=0,
max_epochs=1,
checkpoint_callback=ModelCheckpoint(tmpdir, save_top_k=-1),
@@ -297,9 +296,6 @@ def test_load_model_with_missing_hparams(tmpdir):
default_root_dir=tmpdir,
)
# fit model
trainer = Trainer(**trainer_options)
model = LightningTestModelWithoutHyperparametersArg()
trainer.fit(model)
last_checkpoint = sorted(glob.glob(os.path.join(trainer.checkpoint_callback.dirpath, "*.ckpt")))[-1]