MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / parse_lora_request

Function parse_lora_request

smallthinker/tools/server/utils.hpp:1025–1048  ·  view source on GitHub ↗

parse lora config from JSON request, returned a copy of lora_base with updated scale

Source from the content-addressed store, hash-verified

1023
1024// parse lora config from JSON request, returned a copy of lora_base with updated scale
1025static std::vector<common_adapter_lora_info> parse_lora_request(
1026 const std::vector<common_adapter_lora_info> & lora_base,
1027 const json & data) {
1028 std::vector<common_adapter_lora_info> lora(lora_base);
1029 int max_idx = lora.size();
1030
1031 // clear existing value
1032 for (auto & entry : lora) {
1033 entry.scale = 0.0f;
1034 }
1035
1036 // set value
1037 for (const auto & entry : data) {
1038 int id = json_value(entry, "id", -1);
1039 float scale = json_value(entry, "scale", 0.0f);
1040 if (0 <= id && id < max_idx) {
1041 lora[id].scale = scale;
1042 } else {
1043 throw std::runtime_error("invalid adapter id");
1044 }
1045 }
1046
1047 return lora;
1048}
1049
1050//
1051// utils for interacting with libmtmd

Callers 2

params_from_json_cmplMethod · 0.85
mainFunction · 0.85

Calls 2

json_valueFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected