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

Function update_weights

examples/update.py:96–128  ·  view source on GitHub ↗
(
    ps: ParameterServer,
    checkpoint_name: str,
    checkpoint_files: list[str],
    named_tensors: dict[str, torch.Tensor],
    req_func: Callable[[list[tuple[str, str]]], None],
    inference_parallel_size: int,
    endpoint: str,
    save_metas_file: str | None = None,
    update_method: Literal["broadcast", "p2p", "all"] = "broadcast",
    uds: str | None = None,
)

Source from the content-addressed store, hash-verified

94
95
96def update_weights(
97 ps: ParameterServer,
98 checkpoint_name: str,
99 checkpoint_files: list[str],
100 named_tensors: dict[str, torch.Tensor],
101 req_func: Callable[[list[tuple[str, str]]], None],
102 inference_parallel_size: int,
103 endpoint: str,
104 save_metas_file: str | None = None,
105 update_method: Literal["broadcast", "p2p", "all"] = "broadcast",
106 uds: str | None = None,
107):
108 ps.init_process_group()
109 dist.barrier()
110 ps.register_checkpoint(checkpoint_name, files=checkpoint_files, named_tensors=named_tensors)
111 check_vllm_ready(endpoint, inference_parallel_size, uds)
112 dist.barrier()
113 with timer("Gather metas"):
114 ps.gather_metas(checkpoint_name)
115 if save_metas_file and int(os.getenv("RANK")) == 0:
116 with open(save_metas_file, "wb") as f:
117 f.write(_METAS_ADAPTER.dump_json(ps.get_metas()))
118
119 if update_method == "broadcast" or update_method == "all":
120 with timer("Update weights without setting ranks"):
121 ps.update(checkpoint_name, req_func)
122
123 if update_method == "p2p" or update_method == "all":
124 if update_method:
125 # sleep 2s to wait destroy process group
126 time.sleep(2)
127 with timer("Update weights with setting ranks"):
128 ps.update(checkpoint_name, req_func, ranks=list(range(inference_parallel_size)))
129
130
131def join(

Callers 1

update.pyFile · 0.85

Calls 8

check_vllm_readyFunction · 0.85
timerFunction · 0.85
register_checkpointMethod · 0.80
gather_metasMethod · 0.80
get_metasMethod · 0.80
updateMethod · 0.80
init_process_groupMethod · 0.45
barrierMethod · 0.45

Tested by

no test coverage detected