From 4f08a3dffe575b3c729f3f399a9ee75c22ad104d Mon Sep 17 00:00:00 2001 From: chenyuankun Date: Mon, 2 Dec 2024 19:01:07 +0800 Subject: [PATCH] Fix optional chaining for batch size calculation in PreTrainedModel --- src/models.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models.js b/src/models.js index 7133e64d5..760993641 100644 --- a/src/models.js +++ b/src/models.js @@ -1757,7 +1757,7 @@ export class PreTrainedModel extends Callable { const dtype = session?.config?.kv_cache_dtype ?? 'float32'; const empty = (dtype === 'float16') ? new Uint16Array() : []; - const batch_size = (decoderFeeds[this.main_input_name] ?? decoderFeeds.attention_mask).dims?.[0] ?? 1; + const batch_size = (decoderFeeds[this.main_input_name] ?? decoderFeeds.attention_mask)?.dims?.[0] ?? 1; const shapes = getKeyValueShapes(this.config, { batch_size }); for (const name in shapes) {