예제 #1
0
파일: test_session.py 프로젝트: marload/ray
def test_checkpoint():
    def train():
        for i in range(2):
            save_checkpoint(epoch=i)

    def validate_zero(expected):
        next = session.get_next()
        assert next is not None
        assert next.type == TrainingResultType.CHECKPOINT
        assert next.data["epoch"] == expected

    init_session(training_func=train, world_rank=0, local_rank=0)
    session = get_session()
    session.start()
    validate_zero(0)
    validate_zero(1)
    session.finish()
    shutdown_session()

    def validate_nonzero():
        next = session.get_next()
        assert next is not None
        assert next.type == TrainingResultType.CHECKPOINT
        assert next.data == {}

    init_session(training_func=train, world_rank=1, local_rank=1)
    session = get_session()
    session.start()
    validate_nonzero()
    validate_nonzero()
    session.finish()
    shutdown_session()

    with pytest.raises(ValueError):
        save_checkpoint(epoch=2)
예제 #2
0
파일: test_session.py 프로젝트: marload/ray
 def train():
     for i in range(2):
         save_checkpoint(epoch=i)
         checkpoint = load_checkpoint()
         assert checkpoint["epoch"] == i
예제 #3
0
파일: test_session.py 프로젝트: marload/ray
 def train():
     for i in range(2):
         save_checkpoint(epoch=i)