python/ray/tune/tests/test_sync.py
def testCloudSyncPeriod(self):
        """Tests that changing SYNC_PERIOD affects syncing frequency."""
        tmpdir = tempfile.mkdtemp()

        def trainable(config):
            for i in range(10):
                time.sleep(1)
                tune.report(score=i)

        def counter(local, remote):
            count_file = os.path.join(tmpdir, "count.txt")
            if not os.path.exists(count_file):
                count = 0
            else:
                with open(count_file, "rb") as fp:
                    count = pickle.load(fp)
            count += 1
            with open(count_file, "wb") as fp:
                pickle.dump(count, fp)

        sync_config = tune.SyncConfig(upload_dir="test", syncer=counter, sync_period=1)
        # This was originally set to 0.5
        os.environ["TUNE_GLOBAL_CHECKPOINT_S"] = "0"
        self.addCleanup(lambda: os.environ.pop("TUNE_GLOBAL_CHECKPOINT_S", None))
        [trial] = tune.run(
            trainable,
            name="foo",
            max_failures=0,
            local_dir=tmpdir,
            stop={"training_iteration": 10},
            sync_config=sync_config,
        ).trials

        count_file = os.path.join(tmpdir, "count.txt")
        with open(count_file, "rb") as fp:
            count = pickle.load(fp)

        self.assertEqual(count, 12)
        shutil.rmtree(tmpdir)
Tests that changing SYNC_PERIOD affects syncing frequency.
Tests that changing SYNC_PERIOD affects syncing frequency.
Tests that changing SYNC_PERIOD affects syncing frequency .
def testCloudSyncPeriod(self):
        tmpdir = tempfile.mkdtemp()
        def trainable(config):
            for i in range(10):
                time.sleep(1)
                tune.report(score=i)
        def counter(local, remote):
            count_file = os.path.join(tmpdir, "count.txt")
            if not os.path.exists(count_file):
                count = 0
            else:
                with open(count_file, "rb") as fp:
                    count = pickle.load(fp)
            count += 1
            with open(count_file, "wb") as fp:
                pickle.dump(count, fp)
        sync_config = tune.SyncConfig(upload_dir="test", syncer=counter, sync_period=1)
        os.environ["TUNE_GLOBAL_CHECKPOINT_S"] = "0"
        self.addCleanup(lambda: os.environ.pop("TUNE_GLOBAL_CHECKPOINT_S", None))
        [trial] = tune.run(
            trainable,
            name="foo",
            max_failures=0,
            local_dir=tmpdir,
            stop={"training_iteration": 10},
            sync_config=sync_config,
        ).trials
        count_file = os.path.join(tmpdir, "count.txt")
        with open(count_file, "rb") as fp:
            count = pickle.load(fp)
        self.assertEqual(count, 12)
        shutil.rmtree(tmpdir)
def testCloudSyncPeriod ( self ) : tmpdir = tempfile . mkdtemp ( ) def trainable ( config ) : for i in range ( 10 ) : time . sleep ( 1 ) tune . report ( score = i ) def counter ( local , remote ) : count_file = os . path . join ( tmpdir , "count.txt" ) if not os . path . exists ( count_file ) : count = 0 else : with open ( count_file , "rb" ) as fp : count = pickle . load ( fp ) count += 1 with open ( count_file , "wb" ) as fp : pickle . dump ( count , fp ) sync_config = tune . SyncConfig ( upload_dir = "test" , syncer = counter , sync_period = 1 ) os . environ [ "TUNE_GLOBAL_CHECKPOINT_S" ] = "0" self . addCleanup ( lambda : os . environ . pop ( "TUNE_GLOBAL_CHECKPOINT_S" , None ) ) [ trial ] = tune . run ( trainable , name = "foo" , max_failures = 0 , local_dir = tmpdir , stop = { "training_iteration" : 10 } , sync_config = sync_config , ) . trials count_file = os . path . join ( tmpdir , "count.txt" ) with open ( count_file , "rb" ) as fp : count = pickle . load ( fp ) self . assertEqual ( count , 12 ) shutil . rmtree ( tmpdir )
Tests that changing SYNC_PERIOD affects syncing frequency.
Tests that changing SYNC_PERIOD affects syncing frequency .
"""Tests that changing SYNC_PERIOD affects syncing frequency.""" # This was originally set to 0.5
self