def test_manual_optimization_and_return_tensor(tmp_path):
    """This test verify that in `manual_optimization` we don't add gradient when the user return loss in
    `training_step`"""

    model = ManualOptimizationExtendedModel()
    trainer = Trainer(
        max_epochs=1,
        default_root_dir=tmp_path,
        limit_train_batches=10,
        limit_test_batches=0,
        limit_val_batches=0,
        precision="16-mixed",
        strategy="ddp_spawn",
        accelerator="gpu",
        devices=2,
    )
    trainer.fit(model)
This test verify that in `manual_optimization` we don't add gradient when the user return loss in
    `training_step`
tests/tests_pytorch/trainer/optimization/test_manual_optimization.py