Source code

Revision control

Copy as Markdown

Other Tools

/* Any copyright is dedicated to the Public Domain.
import { _lazyForTestMocking } from "chrome://global/content/ml/MLEngine.worker.mjs";
_lazyForTestMocking.getBackend = async function () {
const { InferenceSession, Tensor } = globalThis;
const response = await fetch(
);
const model = new Uint8Array(await response.arrayBuffer());
return {
async run({ cycles }) {
const input = new Tensor(
"int64",
new BigInt64Array(256).fill(1n),
[1, 256]
);
let logits;
try {
for (let cycle = 0; cycle < cycles; cycle++) {
const session = await InferenceSession.create(model, {
intraOpNumThreads: 1,
interOpNumThreads: 1,
});
let outputs;
try {
outputs = await session.run({
input_ids: input,
attention_mask: input,
token_type_ids: input,
});
logits = Array.from(outputs.logits.data);
} finally {
for (const output of Object.values(outputs ?? {})) {
output.dispose();
}
await session.release();
}
}
} finally {
input.dispose();
}
return { logits, metrics: {} };
},
};
};