diff --git a/src/models.js b/src/models.js index 613a6317d..14e2aaee5 100644 --- a/src/models.js +++ b/src/models.js @@ -1726,7 +1726,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].dims[0]; + 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) {