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

Function computeSingle

plugins/wasi_nn/GGML/compute/compute_engine.cpp:91–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91Expect<ErrNo> computeSingle(WasiNNEnvironment &Env,
92 uint32_t ContextId) noexcept {
93 auto &CxtRef = Env.NNContext[ContextId].get<Context>();
94 auto &GraphRef = Env.NNGraph[CxtRef.GraphId].get<Graph>();
95 LOG_DEBUG(GraphRef.EnableDebugLog, "computeSingle"sv)
96
97 // New compute single token context.
98 auto ReturnCode = ErrNo::Success;
99 if (!CxtRef.ComputeSingleStarted) {
100 CxtRef.ComputeSingleStarted = true;
101
102 // Clear the context and reset the sampler.
103 clearContext(GraphRef, CxtRef);
104
105 // Evaluate the input tokens.
106 if (GraphRef.VisionContext == nullptr) {
107 // Text only prompt.
108 ReturnCode = evaluateInput(GraphRef, CxtRef, "compute"sv);
109 if (ReturnCode != ErrNo::Success) {
110 return ReturnCode;
111 }
112 } else {
113 // Multimodal prompt.
114 llama_pos NewNPos;
115 int32_t Res = mtmd_helper_eval_chunks(
116 GraphRef.VisionContext.get(), GraphRef.LlamaContext.get(),
117 GraphRef.VisionInputChunks.get(), CxtRef.NPos,
118 /* seq_id */ 0, static_cast<int32_t>(CxtRef.CurrentBatchSize),
119 /* logits_last */ true, &NewNPos);
120 CxtRef.NPos = NewNPos;
121 if (Res != 0) {
122 RET_ERROR(ErrNo::InvalidArgument,
123 "compute: unable to eval the mtmd prompt."sv)
124 }
125 }
126 }
127
128 // Main prediction process.
129 LOG_DEBUG(GraphRef.EnableDebugLog,
130 "computeSingle: enter main prediction process"sv)
131 ReturnCode = sampleOutput(GraphRef, CxtRef, true);
132 if (ReturnCode != ErrNo::Success) {
133 CxtRef.ComputeSingleStarted = false;
134 }
135 LOG_DEBUG(GraphRef.EnableDebugLog,
136 "computeSingle: enter main prediction process...Done"sv)
137 // End of main predict process.
138
139 LOG_DEBUG(GraphRef.EnableDebugLog, "computeSingle...Done"sv)
140 return ReturnCode;
141}
142
143#endif
144} // namespace WasmEdge::Host::WASINN::GGML

Callers

nothing calls this directly

Calls 4

clearContextFunction · 0.70
evaluateInputFunction · 0.70
sampleOutputFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected