From 8bd4ccc32234561e66ad14ec696a9d9629826a47 Mon Sep 17 00:00:00 2001 From: Hermann Rolfes Date: Sun, 19 Nov 2023 16:33:53 +0100 Subject: [PATCH 1/2] Update src/models.js - Use conditional operator Co-authored-by: Joshua Lochner --- src/models.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/models.js b/src/models.js index 59a4b4723..59674a86c 100644 --- a/src/models.js +++ b/src/models.js @@ -158,13 +158,10 @@ async function validateInputs(session, inputs) { if (!tensor) { missingInputs.push(inputName); } else { - if (env.wasm.proxy) { - // Moving the tensor across Worker boundary moves ownership to the worker, - // which invalidates the tensor. So we simply sacrifize the clone for it. - checkedInputs[inputName] = tensor.clone(); - } else { - checkedInputs[inputName] = tensor; - } + // NOTE: When `env.wasm.proxy is true`, when the tensor is moved across the Worker + // boundary, the ownership is transferred to the worker, invalidating the tensor. + // So, in this case, we simply sacrifice a clone for it. + checkedInputs[inputName] = env.wasm.proxy ? tensor.clone() : tensor; } } if (missingInputs.length > 0) { From 1fe628814db82e9354b0ff6a0edd78296ee534d5 Mon Sep 17 00:00:00 2001 From: Hermann Rolfes Date: Sun, 19 Nov 2023 16:34:11 +0100 Subject: [PATCH 2/2] Update src/models.js - Object.create(null) Co-authored-by: Joshua Lochner --- src/models.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models.js b/src/models.js index 59674a86c..62eadb2c2 100644 --- a/src/models.js +++ b/src/models.js @@ -151,7 +151,7 @@ async function constructSession(pretrained_model_name_or_path, fileName, options */ async function validateInputs(session, inputs) { // NOTE: Create either a shallow or deep copy based on `onnx.wasm.proxy` - const checkedInputs = {}; + const checkedInputs = Object.create(null); const missingInputs = []; for (const inputName of session.inputNames) { const tensor = inputs[inputName];