MCPcopy Create free account
hub / github.com/MoonshotAI/checkpoint-engine / run

Function run

tests/test_update.py:135–177  ·  view source on GitHub ↗
(
    checker_func: callable,
    rank_list: list[list[int]],
    need_error: bool = False,
    expected_exception: Exception | None = None,
    exception_msg: str | None = None,
)

Source from the content-addressed store, hash-verified

133
134
135def run(
136 checker_func: callable,
137 rank_list: list[list[int]],
138 need_error: bool = False,
139 expected_exception: Exception | None = None,
140 exception_msg: str | None = None,
141):
142 if need_error:
143 assert expected_exception is not None, (
144 "expected_exception must be provided when need_error is True."
145 )
146 assert exception_msg is not None, "exception_msg must be provided when need_error is True."
147 else:
148 assert expected_exception is None, (
149 "expected_exception must be None when need_error is False."
150 )
151 assert exception_msg is None, "exception_msg must be None when need_error is False."
152
153 rank = int(os.getenv("RANK"))
154 ctx = get_context("spawn")
155 queue = ctx.Queue()
156 _device_uuid = _get_physical_gpu_id(device_manager, rank)
157 ps = ParameterServer(auto_pg=True)
158 _device_uuid = _get_physical_gpu_id(ps.device_manager, rank)
159 named_tensors = dict(gen_test_tensors(rank))
160 checkpoint_name = "test"
161 proc = ctx.Process(target=checker_func, args=(rank, _device_uuid, named_tensors, queue))
162 proc.start()
163 with pytest.raises(expected_exception) if need_error else nullcontext() as e:
164 ps.register_checkpoint(checkpoint_name, named_tensors=named_tensors)
165 ps.gather_metas(checkpoint_name)
166 for ranks in rank_list:
167 ps.update(checkpoint_name, queue.put, ranks=ranks)
168 # sleep 3s to wait process group is destroyed
169 time.sleep(3)
170 if need_error:
171 pytest.fail("Test failed: Expected RuntimeError was not raised. Should not reach here.")
172 if need_error:
173 assert exception_msg in str(e.value)
174 ps.unregister_checkpoint(checkpoint_name)
175 queue.put(None)
176 proc.join()
177 assert proc.exitcode == 0
178
179
180def run_with_files(

Callers 2

test_update.pyFile · 0.85
update_weights_from_ipcFunction · 0.85

Calls 7

register_checkpointMethod · 0.95
gather_metasMethod · 0.95
updateMethod · 0.95
unregister_checkpointMethod · 0.95
_get_physical_gpu_idFunction · 0.90
ParameterServerClass · 0.90
gen_test_tensorsFunction · 0.85

Tested by

no test coverage detected