Repository: Lightning-AI/pytorch-lightning
File: tests/trainer/test_trainer.py (Python)

Code before:
    assert (
        trainer.global_step >= num_train_samples and trainer.current_epoch > 0
    ), "Model did not train for at least min_epochs"

    # define less epochs than min_steps
    trainer_options["min_steps"] = math.floor(num_train_samples * 1.5)

    # fit model
    trainer = Trainer(**trainer_options)
    result = trainer.fit(model)
    assert result == 1, "Training did not complete"

    # check model ran for at least num_train_samples*1.5
    assert (
        trainer.global_step >= math.floor(num_train_samples * 1.5) and trainer.current_epoch > 0
    ), "Model did not train for at least min_steps"


def test_trainer_max_steps_accumulate_batches(tmpdir):
    """Verify model trains according to specified max steps with grad accumulated batches"""
    model, trainer_options, num_train_samples = _init_steps_model()

    # define less train steps than epochs
    trainer_options.update(
        default_root_dir=tmpdir,
        max_steps=num_train_samples + 10,
        accumulate_grad_batches=10,
    )

    # fit model
    trainer = Trainer(**trainer_options)
    result = trainer.fit(model)
    assert result == 1, "Training did not complete"

    # check training stopped at max_steps
    assert trainer.global_step == trainer.max_steps, "Model did not stop at max_steps"


def test_benchmark_option(tmpdir):
    """Verify benchmark option."""

    model = EvalModelTemplate()
    model.val_dataloader = model.val_dataloader__multiple

    # verify torch.backends.cudnn.benchmark is not turned on
    assert not torch.backends.cudnn.benchmark

    # fit model
    trainer = Trainer(
        default_root_dir=tmpdir,
        max_epochs=1,

Review comment (suggestion):
```suggestion
        max_steps=(num_train_samples + 10),
```
for visual clarity

Code after:
    assert (
        trainer.global_step >= num_train_samples and trainer.current_epoch > 0
    ), "Model did not train for at least min_epochs"

    # define less epochs than min_steps
    trainer_options["min_steps"] = math.floor(num_train_samples * 1.5)

    # fit model
    trainer = Trainer(**trainer_options)
    result = trainer.fit(model)
    assert result == 1, "Training did not complete"

    # check model ran for at least num_train_samples*1.5
    assert (
        trainer.global_step >= math.floor(num_train_samples * 1.5) and trainer.current_epoch > 0
    ), "Model did not train for at least min_steps"


def test_trainer_max_steps_accumulate_batches(tmpdir):
    """Verify model trains according to specified max steps with grad accumulated batches"""
    model, trainer_options, num_train_samples = _init_steps_model()

    # define less train steps than epochs
    trainer_options.update(
        default_root_dir=tmpdir,
        max_steps=(num_train_samples + 10),
        accumulate_grad_batches=10,
    )

    # fit model
    trainer = Trainer(**trainer_options)
    result = trainer.fit(model)
    assert result == 1, "Training did not complete"

    # check training stopped at max_steps
    assert trainer.global_step == trainer.max_steps, "Model did not stop at max_steps"


def test_benchmark_option(tmpdir):
    """Verify benchmark option."""

    model = EvalModelTemplate()
    model.val_dataloader = model.val_dataloader__multiple

    # verify torch.backends.cudnn.benchmark is not turned on
    assert not torch.backends.cudnn.benchmark

    # fit model
    trainer = Trainer(
        default_root_dir=tmpdir,
        max_epochs=1,