Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

/* Any copyright is dedicated to the Public Domain.
"use strict";
const { sinon } = ChromeUtils.importESModule(
);
add_task(async function test_inference_session_memory_is_released() {
const { cleanup } = await setup();
const workerConfigStub = sinon
.stub(MLEngineParent, "getWorkerConfig")
.returns({
options: { type: "module" },
});
try {
const engine = await createEngine({
taskName: "text-classification",
modelId: "acme/bert",
backend: "onnx-native",
timeoutMS: -1,
});
const warmup = await engine.run({ cycles: 8 });
const before = await getInferenceProcessInfo("inference");
const result = await engine.run({ cycles: 32 });
const after = await getInferenceProcessInfo("inference");
Assert.equal(result.logits.length, 2, "The model produces two logits");
Assert.deepEqual(
result.logits,
warmup.logits,
"Repeated sessions produce the same output"
);
Assert.greater(before.memory, 0, "Measured inference process memory");
Assert.equal(after.pid, before.pid, "Sessions reuse the same process");
const growth = after.memory - before.memory;
info(
`Memory before: ${before.memory}; after: ${after.memory}; growth: ${growth}`
);
Assert.less(
growth,
2 * 1024 * 1024,
"Memory stays bounded when native inference sessions are cycled"
);
} finally {
workerConfigStub.restore();
await EngineProcess.destroyMLEngine();
await cleanup();
}
});