parse lora config from JSON request, returned a copy of lora_base with updated scale
| 1023 | |
| 1024 | // parse lora config from JSON request, returned a copy of lora_base with updated scale |
| 1025 | static 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 |
no test coverage detected