MCPcopy
hub / github.com/huggingface/transformers.js / wrap

Function wrap

packages/transformers/src/ops/registry.js:15–32  ·  view source on GitHub ↗
(session_bytes, session_options, names)

Source from the content-addressed store, hash-verified

13 * The wrapper function for running the ONNX inference session.
14 */
15const wrap = async (session_bytes, session_options, names) => {
16 const session = await createInferenceSession(new Uint8Array(session_bytes), session_options);
17
18 return /** @type {any} */ (
19 async (/** @type {Record<string, Tensor>} */ inputs) => {
20 const proxied = isONNXProxy();
21 const ortFeed = Object.fromEntries(
22 Object.entries(inputs).map(([k, v]) => [k, (proxied ? v.clone() : v).ort_tensor]),
23 );
24 const outputs = await runInferenceSession(session, ortFeed);
25 if (Array.isArray(names)) {
26 return names.map((n) => new Tensor(outputs[n]));
27 } else {
28 return new Tensor(outputs[/** @type {string} */ (names)]);
29 }
30 }
31 );
32};
33
34// In-memory registry of initialized ONNX operators
35export class TensorOpRegistry {

Callers 8

matmulMethod · 0.85
stftMethod · 0.85
rfftMethod · 0.85
top_kMethod · 0.85
sliceMethod · 0.85

Calls 5

createInferenceSessionFunction · 0.90
isONNXProxyFunction · 0.90
runInferenceSessionFunction · 0.90
mapMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected