Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 34 additions & 106 deletions demo/common/demo_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ bool ParseComputePlatform(const std::string& chip_str,
if (lower == "ax650") {
*out_type = ComputePlatform::kAx650;
return true;
} else if (lower == "ascend310p" || lower == "ascend_310p") {
} else if (lower == "ascend310p") {
*out_type = ComputePlatform::kAscend310P;
return true;
} else if (lower == "ascend910b" || lower == "ascend_910b") {
} else if (lower == "ascend910b") {
*out_type = ComputePlatform::kAscend910B;
return true;
} else if (lower == "rk3588") {
*out_type = ComputePlatform::kRk3588;
return true;
} else if (lower == "cuda" || lower == "nvidia_gpu" || lower == "nvidiagpu") {
} else if (lower == "cuda") {
*out_type = ComputePlatform::kCuda;
return true;
} else if (lower == "cpu" || lower == "cpu_generic") {
} else if (lower == "cpu") {
*out_type = ComputePlatform::kCpu;
Comment on lines +75 to 76

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update the kiteLLM guide for the removed CPU alias

After this branch accepts only cpu, the active doc/kitellm.md guidance at lines 54–55 still tells alg_demo users to use cpu_generic. A user following that documented setup in a Profile now fails LoadAndValidateProfilesDocument as unsupported instead of running the Kite demo, so migrate that remaining guide to the canonical cpu name as part of the alias removal.

Useful? React with 👍 / 👎.

return true;
}
Expand Down Expand Up @@ -152,68 +152,6 @@ int ParseCommandLine(int argc, char* argv[], DemoOptions* out_options,
return 2;
}
out_options->output_dir = argv[++i];
out_options->has_output_dir = true;
} else if (arg == "--batch-size") {
if (i + 1 >= argc) {
if (error_msg) *error_msg = "Missing value for argument: " + arg;
return 2;
}
int64_t val = 0;
if (!ParseStrictInt64(argv[++i], &val) || val <= 0 || val > 100000) {
if (error_msg) {
*error_msg = "Invalid integer for --batch-size: '" +
std::string(argv[i]) + "' (Must be integer 1..100000)";
}
return 2;
}
out_options->batch_size = static_cast<int>(val);
out_options->has_batch_size = true;
} else if (arg == "--device-id") {
if (i + 1 >= argc) {
if (error_msg) *error_msg = "Missing value for argument: " + arg;
return 2;
}
int64_t val = 0;
if (!ParseStrictInt64(argv[++i], &val) || val < 0 || val > 1024) {
if (error_msg) {
*error_msg = "Invalid integer for --device-id: '" +
std::string(argv[i]) + "' (Must be integer 0..1024)";
}
return 2;
}
out_options->device_id = static_cast<int>(val);
out_options->has_device_id = true;
} else if (arg == "--chip") {
if (i + 1 >= argc) {
if (error_msg) *error_msg = "Missing value for argument: " + arg;
return 2;
}
out_options->chip = argv[++i];
ComputePlatform dummy;
if (!ParseComputePlatform(out_options->chip, &dummy)) {
if (error_msg) {
*error_msg = "Unsupported chip type: '" + out_options->chip +
"'. Allowed: ax650, ascend310p, ascend910b, rk3588, "
"cuda, cpu";
}
return 2;
}
out_options->has_chip = true;
} else if (arg == "--depth") {
if (i + 1 >= argc) {
if (error_msg) *error_msg = "Missing value for argument: " + arg;
return 2;
}
int64_t val = 0;
if (!ParseStrictInt64(argv[++i], &val) || val <= 0 || val > 100000) {
if (error_msg) {
*error_msg = "Invalid integer for --depth: '" + std::string(argv[i]) +
"' (Must be integer 1..100000)";
}
return 2;
}
out_options->depth_num = static_cast<uint32_t>(val);
out_options->has_depth_num = true;
} else if (arg == "--control-cmd") {
int64_t value = 0;
if (i + 1 >= argc || !ParseStrictInt64(argv[++i], &value) || value <= 0 ||
Expand Down Expand Up @@ -440,32 +378,15 @@ int LoadAndValidateProfilesDocument(const std::string& profiles_path,
return 0;
}

int GetProfilesForSuite(const std::string& profiles_path,
const std::string& suite_name,
std::vector<std::string>* out_profiles,
std::string* error_msg) {
if (!out_profiles) {
if (error_msg) *error_msg = "Null out_profiles pointer";
return 3;
}
out_profiles->clear();

nlohmann::json root;
int ret = LoadAndValidateProfilesDocument(profiles_path, &root, error_msg);
if (ret != 0) {
return ret;
}

const auto& profiles = root["profiles"];
for (const auto& [name, p] : profiles.items()) {
std::string s =
p.contains("suite") ? p["suite"].get<std::string>() : "smoke";
if (suite_name == "all" || s == suite_name) {
out_profiles->push_back(name);
std::vector<std::string> SelectProfilesForSuite(const nlohmann::json& root,
const std::string& suite_name) {
std::vector<std::string> profiles;
for (const auto& [name, profile] : root["profiles"].items()) {
if (suite_name == "all" || profile.value("suite", "smoke") == suite_name) {
profiles.push_back(name);
}
}

return 0;
return profiles;
}

int LoadAndMergeProfiles(const std::string& profiles_path,
Expand All @@ -489,6 +410,17 @@ int LoadAndMergeProfiles(const std::string& profiles_path,
return ret;
}

return MergeProfileOptions(root, cli_options, out_options, error_msg);
}

int MergeProfileOptions(const nlohmann::json& root,
const DemoOptions& cli_options,
DemoOptions* out_options, std::string* error_msg) {
if (!out_options) {
if (error_msg) *error_msg = "Null out_options pointer";
return 3;
}
*out_options = cli_options;
const auto& profiles = root["profiles"];
if (!profiles.contains(cli_options.profile)) {
if (error_msg) {
Expand Down Expand Up @@ -523,16 +455,16 @@ int LoadAndMergeProfiles(const std::string& profiles_path,
if (p.contains("suite") && !cli_options.has_suite) {
out_options->suite = p["suite"].get<std::string>();
}
if (p.contains("batch_size") && !cli_options.has_batch_size) {
if (p.contains("batch_size")) {
out_options->batch_size = static_cast<int>(p["batch_size"].get<int64_t>());
}
if (p.contains("device_id") && !cli_options.has_device_id) {
if (p.contains("device_id")) {
out_options->device_id = static_cast<int>(p["device_id"].get<int64_t>());
}
if (p.contains("chip") && !cli_options.has_chip) {
if (p.contains("chip")) {
out_options->chip = p["chip"].get<std::string>();
}
if (p.contains("depth") && !cli_options.has_depth_num) {
if (p.contains("depth")) {
out_options->depth_num = static_cast<uint32_t>(p["depth"].get<int64_t>());
}
if (p.contains("control_file") && !cli_options.has_control_file) {
Expand All @@ -558,6 +490,8 @@ void PrintHelp(const char* program_name) {
std::cout
<< "Usage: " << program_name << " [options]\n\n"
<< "Profile & Suite Options:\n"
<< " --profiles-file <path> Profile document (default: "
"demo/profiles.json)\n"
<< " -p, --profile <name> Run with a pre-configured profile\n"
<< " --suite <smoke|real|all> Run an entire suite of profiles\n"
<< " -l, --list List all available biz cases and "
Expand All @@ -569,18 +503,7 @@ void PrintHelp(const char* program_name) {
<< " -d, --dataset <path> Business dataset path\n"
<< " -o, --output-dir <path> Results output directory (default: "
"./results)\n\n"
<< "Execution Tuning Options:\n"
<< " --batch-size <n> Max batch size for Operator execution "
"(default: 1)\n"
<< " --device-id <n> Target hardware device ID (default: 0)\n"
<< " --profiles-file <path> Profile document (default: "
"demo/profiles.json)\n"
<< " --chip <name> Compute platform name (ax650, "
"ascend310p, "
"ascend910b,\n"
<< " rk3588, cuda, cpu)\n"
<< " --depth <n> Output descriptor depth count (default: "
"1)\n"
<< "Runtime Control & Output Options:\n"
<< " --example-control Apply the built-in Demo example update "
"(keyword_match)\n"
<< " --control-file <path> Runtime control parameters JSON file\n"
Expand All @@ -590,6 +513,11 @@ void PrintHelp(const char* program_name) {
<< " --allow-fallback-sample Allow using fallback inline samples if "
"dataset is missing\n"
<< " -h, --help Display this help message\n\n"
<< "Execution settings are read only from Profile JSON: "
"chip, device_id, batch_size, depth.\n"
<< "Defaults without Profile values: " << alg_demo::kDemoChip << ", "
<< alg_demo::kDemoDeviceId << ", " << alg_demo::kDemoBatchSize << ", "
<< alg_demo::kDemoDepth << ".\n"
<< std::endl;
}

Expand Down
39 changes: 16 additions & 23 deletions demo/common/demo_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include <vector>

#include "demo/common/demo_profile_defaults.h"
#include "edgeflow/operator/interface.h"
#include "nlohmann/json.hpp"

Expand All @@ -30,10 +31,12 @@ struct DemoOptions {
std::string dataset_path; // 业务测试集文件路径
std::string output_dir = "./results"; // 结果输出根目录

int batch_size = 1; // 最大批大小 (支持按批分块分发)
int device_id = 0; // 设备 ID
std::string chip = "cpu"; // 计算平台芯片类型字符串 (受严格白名单校验)
uint32_t depth_num = 1; // 输出结构体预分配深度
// Execution settings are configured only by Profile JSON (or defaults).
int batch_size = alg_demo::kDemoBatchSize; // 最大批大小 (支持按批分块分发)
int device_id = alg_demo::kDemoDeviceId; // 设备 ID
std::string chip = alg_demo::kDemoChip; // 计算平台芯片类型字符串
// (受严格白名单校验)
uint32_t depth_num = alg_demo::kDemoDepth; // 输出结构体预分配深度

std::optional<std::string> control_file; // 运行时 Control JSON 文件路径
std::optional<int> control_cmd; // 节点命令 ID;必须配合 control_file
Expand All @@ -50,11 +53,6 @@ struct DemoOptions {
bool has_biz = false;
bool has_config_path = false;
bool has_dataset_path = false;
bool has_output_dir = false;
bool has_batch_size = false;
bool has_device_id = false;
bool has_chip = false;
bool has_depth_num = false;
bool has_control_file = false;
bool has_control_cmd = false;
bool has_suite = false;
Expand Down Expand Up @@ -94,9 +92,17 @@ int LoadAndValidateProfilesDocument(const std::string& profiles_path,
nlohmann::json* out_root,
std::string* error_msg);

// Select and merge only documents returned by LoadAndValidateProfilesDocument.
// These operations reuse the same validated snapshot without reopening files.
std::vector<std::string> SelectProfilesForSuite(const nlohmann::json& root,
const std::string& suite_name);
int MergeProfileOptions(const nlohmann::json& root,
const DemoOptions& cli_options,
DemoOptions* out_options, std::string* error_msg);

/**
* @brief 从 demo/profiles.json 读取并与 CLI 参数进行合并
* 优先级: 命令行显式参数 > Profile 配置 > 默认值
* 执行参数仅从 Profile 读取;其余参数优先级: CLI > Profile > 默认值
* @param profiles_path profiles.json 路径
* @param cli_options 命令行选项
* @param out_options 合并后的最终选项
Expand All @@ -107,19 +113,6 @@ int LoadAndMergeProfiles(const std::string& profiles_path,
const DemoOptions& cli_options,
DemoOptions* out_options, std::string* error_msg);

/**
* @brief 根据套件名称获取满足条件的 Profile 名称列表
* @param profiles_path profiles.json 路径
* @param suite_name 套件名 ("smoke", "real", "all")
* @param out_profiles 输出 Profile 标识列表
* @param error_msg 错误输出信息
* @return 0 成功, 非 0 错误码 (3: 格式或配置错误)
*/
int GetProfilesForSuite(const std::string& profiles_path,
const std::string& suite_name,
std::vector<std::string>* out_profiles,
std::string* error_msg);

/**
* @brief 打印 Demo CLI 帮助信息
* @param program_name 应用程序名称
Expand Down
13 changes: 13 additions & 0 deletions demo/common/demo_profile_defaults.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <cstdint>

namespace alg_demo {

// Shared Demo/Profile defaults for the executable and tooling projections.
inline constexpr int kDemoBatchSize = 1;
inline constexpr int kDemoDeviceId = 0;
inline constexpr char kDemoChip[] = "cpu";
inline constexpr uint32_t kDemoDepth = 1;

} // namespace alg_demo
1 change: 0 additions & 1 deletion demo/json_prompt_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def _run_demo_impl(requests, config, biz, work_dir, executable):
command = [
str(executable), "--biz", biz, "--config", str(config),
"--dataset", str(dataset), "--output-dir", str(output_dir),
"--batch-size", "1", "--chip", "cpu_generic",
]
# Keep native diagnostic output out of the JSON string response stream.
with (work_dir / "demo.log").open("w", encoding="utf-8") as log:
Expand Down
10 changes: 5 additions & 5 deletions demo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ void ListProfilesAndBizs(const std::string& profiles_file) {
}

int RunSuite(const std::string& suite_name, const DemoOptions& base_cli_opts) {
std::vector<std::string> target_profiles;
nlohmann::json profiles;
std::string err;
int ret = GetProfilesForSuite(base_cli_opts.profiles_file, suite_name,
&target_profiles, &err);
int ret = LoadAndValidateProfilesDocument(base_cli_opts.profiles_file,
&profiles, &err);
if (ret != 0) {
std::cerr << "[Main ERROR] Failed to load suite '" << suite_name
<< "': " << err << std::endl;
return ret;
}

const auto target_profiles = SelectProfilesForSuite(profiles, suite_name);
if (target_profiles.empty()) {
std::cerr << "[Main WARN] No profiles found matching suite: " << suite_name
<< std::endl;
Expand All @@ -87,8 +88,7 @@ int RunSuite(const std::string& suite_name, const DemoOptions& base_cli_opts) {
cli_opt.has_profile = true;

DemoOptions merged_opt;
ret =
LoadAndMergeProfiles(cli_opt.profiles_file, cli_opt, &merged_opt, &err);
ret = MergeProfileOptions(profiles, cli_opt, &merged_opt, &err);
if (ret != 0) {
std::cerr << "[Main ERROR] Failed to load profile '" << prof
<< "': " << err << std::endl;
Expand Down
8 changes: 4 additions & 4 deletions demo/profiles.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"suite": "real",
"batch_size": 1,
"device_id": 0,
"chip": "cpu_generic",
"chip": "cpu",
"depth": 1
},
"keyword_match_rules": {
Expand Down Expand Up @@ -48,7 +48,7 @@
"suite": "real",
"batch_size": 1,
"device_id": 0,
"chip": "cpu_generic",
"chip": "cpu",
"depth": 1
},
"doc_qa_rerank_mock": {
Expand All @@ -68,7 +68,7 @@
"suite": "real",
"batch_size": 1,
"device_id": 0,
"chip": "cpu_generic",
"chip": "cpu",
"depth": 1
},
"dialogue_audit_mock": {
Expand Down Expand Up @@ -118,7 +118,7 @@
"suite": "real",
"batch_size": 1,
"device_id": 0,
"chip": "cpu_generic",
"chip": "cpu",
"depth": 1
},
"entity_extract_custom_mock": {
Expand Down
Loading
Loading