Ejemplo n.º 1
0
def test_connect_subloops(tmpdir):
    """Test connecting individual subloops by calling `trainer.x.y.connect()`"""
    model = BoringModel()
    trainer = Trainer(default_root_dir=tmpdir, fast_dev_run=True)

    epoch_loop = trainer.fit_loop.epoch_loop
    new_batch_loop = TrainingBatchLoop()
    epoch_loop.connect(batch_loop=new_batch_loop)
    assert epoch_loop.batch_loop is new_batch_loop
    assert new_batch_loop.trainer is None

    trainer.fit(model)
    assert new_batch_loop.trainer is trainer
Ejemplo n.º 2
0
def test_connect_subloops(tmpdir):
    """Test connecting individual subloops by calling `trainer.x.y.connect()`"""
    model = BoringModel()
    trainer = Trainer(default_root_dir=tmpdir, fast_dev_run=True)

    epoch_loop = trainer.fit_loop.epoch_loop
    new_batch_loop = TrainingBatchLoop()
    epoch_loop.connect(batch_loop=new_batch_loop)
    assert epoch_loop.batch_loop is new_batch_loop

    with pytest.raises(RuntimeError, match="The loop is not attached to a Trainer"):
        _ = new_batch_loop.trainer

    trainer.fit(model)
    assert new_batch_loop.trainer is trainer