Skip to content

Commit

Permalink
Merge remote-tracking branch 'kfm/fix-nan-worker-ownership' into fix-…
Browse files Browse the repository at this point in the history
…nan-worker-ownership
  • Loading branch information
kungfooman committed Nov 19, 2023
2 parents 1413b6d + 1fe6288 commit 7ac748c
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,17 @@ 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];
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) {
Expand Down

0 comments on commit 7ac748c

Please sign in to comment.