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

Function checker_proc

tests/test_update.py:88–132  ·  view source on GitHub ↗
(rank: int, device_uuid: str, named_tensors: dict[str, torch.Tensor], queue: Queue)

Source from the content-addressed store, hash-verified

86
87
88def checker_proc(rank: int, device_uuid: str, named_tensors: dict[str, torch.Tensor], queue: Queue):
89 device_manager.device_module.set_device(rank)
90 named_tensors = {
91 name: tensor.to(device_manager.device_type) for name, tensor in named_tensors.items()
92 }
93 _zmq_ctx = zmq.Context()
94 mem_info = device_manager.device_module.mem_get_info()
95 memory_usage = mem_info[1] - mem_info[0]
96 memory_history: list[int] = [memory_usage]
97
98 def check(names_to_check: dict[str, bool], weights: list[tuple[str, torch.Tensor]]):
99 for name, weight in weights:
100 if name not in named_tensors:
101 continue
102 assert (weight == named_tensors[name]).all(), f"Tensor {name} does not match!"
103 names_to_check[name] = True
104
105 def check_weights(names_to_check: dict[str, bool], socket_paths: list[tuple[str, str]]):
106 socket_paths = dict(socket_paths)
107 update_weights_from_ipc(
108 _zmq_ctx,
109 socket_paths[device_uuid],
110 device_id=rank,
111 run=lambda weights: check(names_to_check, weights),
112 post_hook=lambda: device_manager.device_module.synchronize(),
113 )
114 device_manager.device_module.synchronize()
115 device_manager.device_module.empty_cache()
116 mem_info = device_manager.device_module.mem_get_info()
117 memory_usage = mem_info[1] - mem_info[0]
118 memory_history.append(memory_usage)
119 assert all(names_to_check.values())
120
121 while True:
122 socket_paths: list[tuple[str, str]] = queue.get()
123 if socket_paths is None:
124 break
125 names_to_check = dict.fromkeys(named_tensors.keys(), False)
126 check_weights(names_to_check, socket_paths)
127
128 mem_info = device_manager.device_module.mem_get_info()
129 memory_usage = mem_info[1] - mem_info[0]
130 memory_history.append(memory_usage)
131 for memory in memory_history[1:]:
132 print(f"[rank{rank}] Memory change: {memory - memory_history[0]}")
133
134
135def run(

Callers

nothing calls this directly

Calls 1

check_weightsFunction · 0.85

Tested by

no test coverage detected