6
6
7
7
use Codewithkyrian \Transformers \Exceptions \MissingModelInputException ;
8
8
use Codewithkyrian \Transformers \Exceptions \ModelExecutionException ;
9
- use Codewithkyrian \Transformers \Models \Pretrained \PreTrainedModel ;
9
+ use Codewithkyrian \Transformers \Models \Pretrained \PretrainedModel ;
10
10
use Codewithkyrian \Transformers \Utils \GenerationConfig ;
11
11
use Codewithkyrian \Transformers \Utils \Tensor ;
12
12
@@ -30,7 +30,7 @@ public function canGenerate(): bool
30
30
};
31
31
}
32
32
33
- public function runBeam (PreTrainedModel $ model , array &$ beam ): array
33
+ public function runBeam (PretrainedModel $ model , array &$ beam ): array
34
34
{
35
35
return match ($ this ) {
36
36
self ::DecoderOnly => $ this ->decoderRunBeam ($ model , $ beam ),
@@ -40,7 +40,7 @@ public function runBeam(PreTrainedModel $model, array &$beam): array
40
40
}
41
41
42
42
public function startBeams (
43
- PreTrainedModel $ model ,
43
+ PretrainedModel $ model ,
44
44
Tensor $ inputTokenIds ,
45
45
GenerationConfig $ generationConfig ,
46
46
int $ numOutputTokens ,
@@ -63,7 +63,7 @@ public function updateBeam(array &$beam, int $newTokenId): void
63
63
};
64
64
}
65
65
66
- public function forward (PreTrainedModel $ model , array $ modelInputs ): array
66
+ public function forward (PretrainedModel $ model , array $ modelInputs ): array
67
67
{
68
68
return match ($ this ) {
69
69
self ::EncoderOnly => $ this ->encoderForward ($ model , $ modelInputs ),
@@ -77,7 +77,7 @@ public function forward(PreTrainedModel $model, array $modelInputs): array
77
77
78
78
//<editor-fold desc="Encoder methods">
79
79
80
- protected function encoderForward (PreTrainedModel $ model , array $ modelInputs ): array
80
+ protected function encoderForward (PretrainedModel $ model , array $ modelInputs ): array
81
81
{
82
82
$ encoderFeeds = [];
83
83
@@ -102,11 +102,11 @@ protected function encoderForward(PreTrainedModel $model, array $modelInputs): a
102
102
103
103
/**
104
104
* Runs a single step of the text generation process for a given beam.
105
- * @param PreTrainedModel $model The text generation model object.
105
+ * @param PretrainedModel $model The text generation model object.
106
106
* @param array $beam The beam to run the generation process for.
107
107
* @return array The output of the generation process for the given beam.
108
108
*/
109
- protected function decoderRunBeam (PreTrainedModel $ model , array &$ beam ): array
109
+ protected function decoderRunBeam (PretrainedModel $ model , array &$ beam ): array
110
110
{
111
111
$ attnMaskLength = count ($ beam ['output_token_ids ' ]);
112
112
$ attnMaskData = array_fill (0 , $ attnMaskLength , 1 );
@@ -128,15 +128,15 @@ protected function decoderRunBeam(PreTrainedModel $model, array &$beam): array
128
128
}
129
129
130
130
/** Starts the generation of text by initializing the beams for the given input token IDs.
131
- * @param PreTrainedModel $model The text generation model object.
131
+ * @param PretrainedModel $model The text generation model object.
132
132
* @param Tensor $inputTokenIds A tensor of input token IDs to generate text from.
133
133
* @param GenerationConfig $generationConfig The generation config.
134
134
* @param int $numOutputTokens The maximum number of tokens to generate for each beam.
135
135
* @param Tensor|null $inputsAttentionMask The attention mask tensor for the input token IDs.
136
136
* @return array An array of beams initialized with the given inputs and parameters.
137
137
*/
138
138
protected function decoderStartBeams (
139
- PreTrainedModel $ model ,
139
+ PretrainedModel $ model ,
140
140
Tensor $ inputTokenIds ,
141
141
GenerationConfig $ generationConfig ,
142
142
int $ numOutputTokens ,
@@ -195,12 +195,12 @@ protected function decoderUpdatebeam(array &$beam, int $newTokenId): void
195
195
196
196
/**
197
197
* Forward pass for the decoder model.
198
- * @param PreTrainedModel $model The model to use for the forward pass.
198
+ * @param PretrainedModel $model The model to use for the forward pass.
199
199
* @param array $modelInputs The inputs to the model.
200
200
* @return array The output of the forward pass.
201
201
* @throws MissingModelInputException|ModelExecutionException
202
202
*/
203
- protected function decoderForward (PreTrainedModel $ model , array $ modelInputs ): array
203
+ protected function decoderForward (PretrainedModel $ model , array $ modelInputs ): array
204
204
{
205
205
['input_ids ' => $ inputIds , 'past_key_values ' => $ pastKeyValues , 'attention_mask ' => $ attentionMask ]
206
206
= $ modelInputs ;
@@ -234,7 +234,7 @@ protected function decoderForward(PreTrainedModel $model, array $modelInputs): a
234
234
235
235
//<editor-fold desc="Seq2Seq methods">
236
236
237
- protected function seq2seqRunBeam (PreTrainedModel $ model , array &$ beam ): array
237
+ protected function seq2seqRunBeam (PretrainedModel $ model , array &$ beam ): array
238
238
{
239
239
$ inputName = $ model ->mainInputName ;
240
240
@@ -270,14 +270,14 @@ protected function seq2seqRunBeam(PreTrainedModel $model, array &$beam): array
270
270
}
271
271
272
272
/** Start the beam search process for the seq2seq model.
273
- * @param PreTrainedModel $model The model to use for the beam search.
273
+ * @param PretrainedModel $model The model to use for the beam search.
274
274
* @param Tensor $inputTokenIds Array of input token ids for each input sequence.
275
275
* @param GenerationConfig $generationConfig The generation configuration.
276
276
* @param int $numOutputTokens The maximum number of output tokens for the model.
277
277
* @return array Array of beam search objects.
278
278
*/
279
279
protected function seq2seqStartBeams (
280
- PreTrainedModel $ model ,
280
+ PretrainedModel $ model ,
281
281
Tensor $ inputTokenIds ,
282
282
GenerationConfig $ generationConfig ,
283
283
int $ numOutputTokens ,
@@ -330,7 +330,7 @@ protected function seq2seqUpdatebeam(array &$beam, int $newTokenId): void
330
330
$ beam ['output_token_ids ' ][] = $ newTokenId ;
331
331
}
332
332
333
- protected function seq2seqForward (PreTrainedModel $ model , array $ modelInputs ): array
333
+ protected function seq2seqForward (PretrainedModel $ model , array $ modelInputs ): array
334
334
{
335
335
336
336
['encoder_outputs ' => $ encoderOutputs , 'past_key_values ' => $ pastKeyValues ] = $ modelInputs ;
0 commit comments