MCPcopy
hub / github.com/ray-project/ray / function_trainable

Function function_trainable

python/ray/tune/utils/release_test_util.py:76–103  ·  view source on GitHub ↗
(config)

Source from the content-addressed store, hash-verified

74
75
76def function_trainable(config):
77 num_iters = int(config["num_iters"])
78 sleep_time = config["sleep_time"]
79 score = config["score"]
80
81 checkpoint_iters = config["checkpoint_iters"]
82 checkpoint_size_b = config["checkpoint_size_b"]
83 checkpoint_num_items = checkpoint_size_b // 8 # np.float64
84 checkpoint_num_files = config["checkpoint_num_files"]
85
86 for i in range(num_iters):
87 metrics = {"score": i + score}
88 if (
89 checkpoint_iters >= 0
90 and checkpoint_size_b > 0
91 and i % checkpoint_iters == 0
92 ):
93 with tempfile.TemporaryDirectory() as tmpdir:
94 for i in range(checkpoint_num_files):
95 checkpoint_file = os.path.join(tmpdir, f"bogus_{i}.ckpt")
96 checkpoint_data = np.random.uniform(0, 1, size=checkpoint_num_items)
97 with open(checkpoint_file, "wb") as fp:
98 pickle.dump(checkpoint_data, fp)
99 tune.report(metrics, checkpoint=Checkpoint.from_directory(tmpdir))
100 else:
101 tune.report(metrics)
102
103 time.sleep(sleep_time)
104
105
106def timed_tune_run(

Callers

nothing calls this directly

Calls 8

openFunction · 0.85
rangeFunction · 0.50
joinMethod · 0.45
uniformMethod · 0.45
dumpMethod · 0.45
reportMethod · 0.45
from_directoryMethod · 0.45
sleepMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…