(
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,
)
| 94 | |
| 95 | |
| 96 | def 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 | |
| 131 | def join( |
no test coverage detected