MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / parseMetadata

Function parseMetadata

plugins/wasi_nn/wasinn_bitnet.cpp:87–1567  ·  view source on GitHub ↗

Parse metadata from JSON.

Source from the content-addressed store, hash-verified

85
86// Parse metadata from JSON.
87ErrNo parseMetadata(Graph &GraphRef, LocalConfig &ConfRef,
88 const std::string &Metadata, bool *IsModelUpdated = nullptr,
89 bool *IsContextUpdated = nullptr,
90 bool *IsSamplerUpdated = nullptr) noexcept {
91 // Parse metadata from the json.
92 simdjson::dom::parser Parser;
93 simdjson::dom::element Doc;
94 auto ParseError = Parser.parse(Metadata).get(Doc);
95 if (ParseError) {
96 RET_ERROR(ErrNo::InvalidEncoding, "parse metadata error."sv)
97 }
98
99 // Get the current llama parameters.
100 int64_t PrevNGPULayers = GraphRef.Params.n_gpu_layers;
101 int64_t PrevMainGpu = GraphRef.Params.main_gpu;
102 int64_t PrevThreads = GraphRef.Params.cpuparams.n_threads;
103 bool PrevFlashAttn = GraphRef.Params.flash_attn;
104 int64_t PrevCtxSize = GraphRef.Params.n_ctx;
105 bool PrevEmbedding = GraphRef.Params.embedding;
106 // Get the current sampler parameters.
107 double PrevTemp = GraphRef.Params.sparams.temp;
108 double PrevTopP = GraphRef.Params.sparams.top_p;
109 double PrevRepeatPenalty = GraphRef.Params.sparams.penalty_repeat;
110 double PrevPresencePenalty = GraphRef.Params.sparams.penalty_present;
111 double PrevFrequencyPenalty = GraphRef.Params.sparams.penalty_freq;
112 std::string PrevGrammar = GraphRef.Params.sparams.grammar;
113 uint64_t PrevSeed = GraphRef.Params.sparams.seed;
114
115 // The plugin parameters.
116 if (Doc.at_key("enable-log").error() == simdjson::SUCCESS) {
117 auto Err = Doc["enable-log"].get<bool>().get(GraphRef.EnableLog);
118 if (Err) {
119 RET_ERROR(ErrNo::InvalidArgument,
120 "Unable to retrieve the enable-log option."sv)
121 }
122 }
123 if (Doc.at_key("enable-debug-log").error() == simdjson::SUCCESS) {
124 auto Err = Doc["enable-debug-log"].get<bool>().get(GraphRef.EnableDebugLog);
125 if (Err) {
126 RET_ERROR(ErrNo::InvalidArgument,
127 "Unable to retrieve the enable-debug-log option."sv)
128 }
129 }
130
131 // The model parameters.
132 if (Doc.at_key("main-gpu").error() == simdjson::SUCCESS) {
133 int64_t MainGPU;
134 auto Err = Doc["main-gpu"].get<int64_t>().get(MainGPU);
135 if (Err) {
136 RET_ERROR(ErrNo::InvalidArgument,
137 "Unable to retrieve the main-gpu option."sv)
138 }
139 GraphRef.Params.main_gpu = static_cast<int32_t>(MainGPU);
140 }
141 if (Doc.at_key("n-gpu-layers").error() == simdjson::SUCCESS) {
142 int64_t NGPULayers;
143 auto Err = Doc["n-gpu-layers"].get<int64_t>().get(NGPULayers);
144 if (Err) {

Callers 2

loadFunction · 0.70
setInputFunction · 0.70

Calls 6

stringToListFunction · 0.85
goodMethod · 0.80
getMethod · 0.45
parseMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected