@@ -467,50 +467,50 @@ public function addPastKeyValues(array &$decoderFeeds, ?array $pastKeyValues): v
467467 $ decoderFeeds = array_merge ($ decoderFeeds , $ pastKeyValues );
468468 } else {
469469 // TODO support batches (i.e., batch_size > 1)
470- $ batch_size = 1 ;
470+ $ batchSize = 1 ;
471471
472472 if ($ this ->config ->isEncoderDecoder && ($ this ->addEncoderPkv ?? true )) {
473- $ encoderShape = [$ batch_size , $ this ->numEncoderHeads , 1 , $ this ->encoderDimKv ];
474- $ decoderShape = [$ batch_size , $ this ->numDecoderHeads , 1 , $ this ->decoderDimKv ];
473+ $ encoderShape = [$ batchSize , $ this ->numEncoderHeads , 0 , $ this ->encoderDimKv ];
474+ $ decoderShape = [$ batchSize , $ this ->numDecoderHeads , 0 , $ this ->decoderDimKv ];
475475
476476
477477 for ($ i = 0 ; $ i < $ this ->numDecoderLayers ; ++$ i ) {
478478 $ decoderFeeds ["past_key_values. $ i.encoder.key " ]
479479 = $ decoderFeeds ["past_key_values. $ i.encoder.value " ]
480- = new Tensor (null , shape: $ encoderShape );
480+ = new Tensor ([] , shape: $ encoderShape );
481481 $ decoderFeeds ["past_key_values. $ i.decoder.key " ]
482482 = $ decoderFeeds ["past_key_values. $ i.decoder.value " ]
483- = new Tensor (null , shape: $ decoderShape );
483+ = new Tensor ([] , shape: $ decoderShape );
484484 }
485485 } else if ($ this ->config ->modelType === 'falcon ' ) {
486486 // NOTE: Custom implementation for Falcon
487- $ shape = [$ batch_size * $ this ->numHeads , 1 , $ this ->dimKv ];
487+ $ shape = [$ batchSize * $ this ->numHeads , 0 , $ this ->dimKv ];
488488
489489 for ($ i = 0 ; $ i < $ this ->numLayers ; ++$ i ) {
490- $ decoderFeeds ["past_key_values. $ i.key " ] = new Tensor (null , shape: $ shape );
491- $ decoderFeeds ["past_key_values. $ i.value " ] = new Tensor (null , shape: $ shape );
490+ $ decoderFeeds ["past_key_values. $ i.key " ] = new Tensor ([] , shape: $ shape );
491+ $ decoderFeeds ["past_key_values. $ i.value " ] = new Tensor ([] , shape: $ shape );
492492 }
493493 } else if ($ this ->config ['multi_query ' ] ?? null ) { // e.g., for `gpt_bigcode`
494- $ shape = [$ batch_size * $ this ->numHeads , 1 , 2 * $ this ->dimKv ];
494+ $ shape = [$ batchSize * $ this ->numHeads , 0 , 2 * $ this ->dimKv ];
495495
496496 for ($ i = 0 ; $ i < $ this ->numLayers ; ++$ i ) {
497- $ decoderFeeds ["past_key_values. $ i.key_value " ] = new Tensor (null , shape: $ shape );
497+ $ decoderFeeds ["past_key_values. $ i.key_value " ] = new Tensor ([] , shape: $ shape );
498498 }
499499 } else if ($ this ->config ['model_type ' ] === 'bloom ' ) {
500500 // NOTE: Custom implementation for Bloom
501- $ keyShape = [$ batch_size * $ this ->numHeads , $ this ->dimKv , 1 ];
502- $ valueShape = [$ batch_size * $ this ->numHeads , 1 , $ this ->dimKv ];
501+ $ keyShape = [$ batchSize * $ this ->numHeads , $ this ->dimKv , 0 ];
502+ $ valueShape = [$ batchSize * $ this ->numHeads , 0 , $ this ->dimKv ];
503503
504504 for ($ i = 0 ; $ i < $ this ->numLayers ; ++$ i ) {
505- $ decoderFeeds ["past_key_values. $ i.key " ] = new Tensor (null , shape: $ keyShape );
506- $ decoderFeeds ["past_key_values. $ i.value " ] = new Tensor (null , shape: $ valueShape );
505+ $ decoderFeeds ["past_key_values. $ i.key " ] = new Tensor ([] , shape: $ keyShape );
506+ $ decoderFeeds ["past_key_values. $ i.value " ] = new Tensor ([] , shape: $ valueShape );
507507 }
508508 } else { // Decoder-only
509- $ shape = [$ batch_size , $ this ->numHeads , 1 , $ this ->dimKv ];
509+ $ shape = [$ batchSize , $ this ->numHeads , 0 , $ this ->dimKv ];
510510
511511 for ($ i = 0 ; $ i < $ this ->numLayers ; ++$ i ) {
512- $ decoderFeeds ["past_key_values. $ i.key " ] = new Tensor (null , shape: $ shape );
513- $ decoderFeeds ["past_key_values. $ i.value " ] = new Tensor (null , shape: $ shape );
512+ $ decoderFeeds ["past_key_values. $ i.key " ] = new Tensor ([] , shape: $ shape );
513+ $ decoderFeeds ["past_key_values. $ i.value " ] = new Tensor ([] , shape: $ shape );
514514 }
515515 }
516516 }
0 commit comments