昇腾社区首页
中文
注册

建链

功能介绍

调用LinkLlmClusters接口在PD节点之间建立通信链路,链路主要用于KV Cache的传输。

使用场景

建链操作是节点之间进行数据传输的前提,在D2D模式中,建链接口采用类TCP建链流程,P侧初始化时提供侦听信息,由D侧发起建链。

根据业务繁忙情况,在需要调整集群PD节点配比时,通过建链扩容节点。

功能示例

初始化LLM-DataDist。其中P侧需要设置侦听的device ip和port。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// P侧
LlmDataDist llmDataDist(PROMPT_CLUSTER_ID, LlmRole::kPrompt);
std::map<AscendString, AscendString> options;
options[OPTION_DEVICE_ID] = deviceId.c_str();
options[OPTION_LISTEN_IP_INFO] = (localIp + ":" + std::to_string(PROMPT_LISTEN_PORT)).c_str();
options[OPTION_BUF_POOL_CFG] = R"({
"buf_cfg":[{"total_size":2097152,"blk_size":256,"max_buf_size":8192}],
"buf_pool_size": 2147483648
})";
auto ret = llmDataDist.Initialize(options);
if (ret != LLM_SUCCESS) {
    printf("[ERROR] Initialize failed, ret = %u\n", ret);
    return -1;
}
// D侧
LlmDataDist llmDataDist(DECODER_CLUSTER_ID, LlmRole::kDecoder);
std::map<AscendString, AscendString> options;
options[OPTION_DEVICE_ID] = deviceId.c_str();
options[OPTION_BUF_POOL_CFG] = R"({
"buf_pool_size": 2147483648
})";
auto ret = llmDataDist.Initialize(options);
if (ret != LLM_SUCCESS) {
    printf("[ERROR] Initialize failed, ret = %u\n", ret);
    return -1;
}

在D侧调用LinkLlmClusters发起建链操作。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
std::vector<Status> rets;
std::vector<ClusterInfo> clusters;
ClusterInfo clusterInfo;
IpInfo localIpInfo;
localIpInfo.ip = localIp;
IpInfo remoteIpInfo;
remoteIpInfo.ip = remoteIp;
remoteIpInfo.port = PROMPT_LISTEN_PORT;
clusterInfo.remote_cluster_id = PROMPT_CLUSTER_ID;
clusterInfo.local_ip_infos.emplace_back(std::move(localIpInfo));
clusterInfo.remote_ip_infos.emplace_back(std::move(remoteIpInfo));
clusters.emplace_back(std::move(clusterInfo));
auto ret = llmDataDist.LinkLlmClusters(clusters, rets);
if (ret != LLM_SUCCESS) {
    printf("[ERROR] LinkLlmClusters failed, ret = %u\n", ret);
    return -1;
}

异常处理

当调用LinkLlmClusters失败时,需排查两台机器网络是否连通,device ip是否正确,port是否被占用。

更多异常处理请参考错误码