Skip to content

Commit 8fda878

Browse files
bugfix: Autoload errors for PretrainedModel on case-sensitive operating systems.
- Renamed class "PreTrainedModel" to "PretrainedModel" for consistency. - Updated and renamed affected child classes.
1 parent deda6dc commit 8fda878

File tree

69 files changed

+117
-117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+117
-117
lines changed

src/Models/Auto/PretrainedMixin.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use Codewithkyrian\Transformers\Exceptions\UnsupportedModelTypeException;
99
use Codewithkyrian\Transformers\Models\ModelArchitecture;
10-
use Codewithkyrian\Transformers\Models\Pretrained\PreTrainedModel;
10+
use Codewithkyrian\Transformers\Models\Pretrained\PretrainedModel;
1111
use Codewithkyrian\Transformers\Utils\AutoConfig;
1212
use Symfony\Component\Console\Output\OutputInterface;
1313

@@ -38,7 +38,7 @@ abstract class PretrainedMixin
3838
* @param string|null $cacheDir The cache directory to save the model in.
3939
* @param string $revision The revision of the model.
4040
* @param string|null $modelFilename The filename of the model.
41-
* @return PreTrainedModel The instantiated pretrained model.
41+
* @return PretrainedModel The instantiated pretrained model.
4242
*/
4343
public static function fromPretrained(
4444
string $modelNameOrPath,
@@ -48,7 +48,7 @@ public static function fromPretrained(
4848
string $revision = 'main',
4949
?string $modelFilename = null,
5050
?OutputInterface $output = null
51-
): PreTrainedModel
51+
): PretrainedModel
5252
{
5353
$config = AutoConfig::fromPretrained($modelNameOrPath, $config, $cacheDir, $revision, $output);
5454

@@ -75,7 +75,7 @@ public static function fromPretrained(
7575
if (static::BASE_IF_FAIL) {
7676
echo "Unknown model class for model type {$config->modelType}. Using base class PreTrainedModel.\n";
7777

78-
return PreTrainedModel::fromPretrained(
78+
return PretrainedModel::fromPretrained(
7979
modelNameOrPath: $modelNameOrPath,
8080
quantized: $quantized,
8181
config: $config,

src/Models/ModelArchitecture.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Codewithkyrian\Transformers\Exceptions\MissingModelInputException;
88
use Codewithkyrian\Transformers\Exceptions\ModelExecutionException;
9-
use Codewithkyrian\Transformers\Models\Pretrained\PreTrainedModel;
9+
use Codewithkyrian\Transformers\Models\Pretrained\PretrainedModel;
1010
use Codewithkyrian\Transformers\Utils\GenerationConfig;
1111
use Codewithkyrian\Transformers\Utils\Tensor;
1212

@@ -30,7 +30,7 @@ public function canGenerate(): bool
3030
};
3131
}
3232

33-
public function runBeam(PreTrainedModel $model, array &$beam): array
33+
public function runBeam(PretrainedModel $model, array &$beam): array
3434
{
3535
return match ($this) {
3636
self::DecoderOnly => $this->decoderRunBeam($model, $beam),
@@ -40,7 +40,7 @@ public function runBeam(PreTrainedModel $model, array &$beam): array
4040
}
4141

4242
public function startBeams(
43-
PreTrainedModel $model,
43+
PretrainedModel $model,
4444
Tensor $inputTokenIds,
4545
GenerationConfig $generationConfig,
4646
int $numOutputTokens,
@@ -63,7 +63,7 @@ public function updateBeam(array &$beam, int $newTokenId): void
6363
};
6464
}
6565

66-
public function forward(PreTrainedModel $model, array $modelInputs): array
66+
public function forward(PretrainedModel $model, array $modelInputs): array
6767
{
6868
return match ($this) {
6969
self::EncoderOnly => $this->encoderForward($model, $modelInputs),
@@ -77,7 +77,7 @@ public function forward(PreTrainedModel $model, array $modelInputs): array
7777

7878
//<editor-fold desc="Encoder methods">
7979

80-
protected function encoderForward(PreTrainedModel $model, array $modelInputs): array
80+
protected function encoderForward(PretrainedModel $model, array $modelInputs): array
8181
{
8282
$encoderFeeds = [];
8383

@@ -102,11 +102,11 @@ protected function encoderForward(PreTrainedModel $model, array $modelInputs): a
102102

103103
/**
104104
* 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.
106106
* @param array $beam The beam to run the generation process for.
107107
* @return array The output of the generation process for the given beam.
108108
*/
109-
protected function decoderRunBeam(PreTrainedModel $model, array &$beam): array
109+
protected function decoderRunBeam(PretrainedModel $model, array &$beam): array
110110
{
111111
$attnMaskLength = count($beam['output_token_ids']);
112112
$attnMaskData = array_fill(0, $attnMaskLength, 1);
@@ -128,15 +128,15 @@ protected function decoderRunBeam(PreTrainedModel $model, array &$beam): array
128128
}
129129

130130
/** 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.
132132
* @param Tensor $inputTokenIds A tensor of input token IDs to generate text from.
133133
* @param GenerationConfig $generationConfig The generation config.
134134
* @param int $numOutputTokens The maximum number of tokens to generate for each beam.
135135
* @param Tensor|null $inputsAttentionMask The attention mask tensor for the input token IDs.
136136
* @return array An array of beams initialized with the given inputs and parameters.
137137
*/
138138
protected function decoderStartBeams(
139-
PreTrainedModel $model,
139+
PretrainedModel $model,
140140
Tensor $inputTokenIds,
141141
GenerationConfig $generationConfig,
142142
int $numOutputTokens,
@@ -195,12 +195,12 @@ protected function decoderUpdatebeam(array &$beam, int $newTokenId): void
195195

196196
/**
197197
* 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.
199199
* @param array $modelInputs The inputs to the model.
200200
* @return array The output of the forward pass.
201201
* @throws MissingModelInputException|ModelExecutionException
202202
*/
203-
protected function decoderForward(PreTrainedModel $model, array $modelInputs): array
203+
protected function decoderForward(PretrainedModel $model, array $modelInputs): array
204204
{
205205
['input_ids' => $inputIds, 'past_key_values' => $pastKeyValues, 'attention_mask' => $attentionMask]
206206
= $modelInputs;
@@ -234,7 +234,7 @@ protected function decoderForward(PreTrainedModel $model, array $modelInputs): a
234234

235235
//<editor-fold desc="Seq2Seq methods">
236236

237-
protected function seq2seqRunBeam(PreTrainedModel $model, array &$beam): array
237+
protected function seq2seqRunBeam(PretrainedModel $model, array &$beam): array
238238
{
239239
$inputName = $model->mainInputName;
240240

@@ -270,14 +270,14 @@ protected function seq2seqRunBeam(PreTrainedModel $model, array &$beam): array
270270
}
271271

272272
/** 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.
274274
* @param Tensor $inputTokenIds Array of input token ids for each input sequence.
275275
* @param GenerationConfig $generationConfig The generation configuration.
276276
* @param int $numOutputTokens The maximum number of output tokens for the model.
277277
* @return array Array of beam search objects.
278278
*/
279279
protected function seq2seqStartBeams(
280-
PreTrainedModel $model,
280+
PretrainedModel $model,
281281
Tensor $inputTokenIds,
282282
GenerationConfig $generationConfig,
283283
int $numOutputTokens,
@@ -330,7 +330,7 @@ protected function seq2seqUpdatebeam(array &$beam, int $newTokenId): void
330330
$beam['output_token_ids'][] = $newTokenId;
331331
}
332332

333-
protected function seq2seqForward(PreTrainedModel $model, array $modelInputs): array
333+
protected function seq2seqForward(PretrainedModel $model, array $modelInputs): array
334334
{
335335

336336
['encoder_outputs' => $encoderOutputs, 'past_key_values' => $pastKeyValues] = $modelInputs;

src/Models/Pretrained/AlbertForMaskedLM.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* AlbertForMaskedLM class for performing masked language modeling on albert models.
1111
*/
12-
class AlbertForMaskedLM extends BertPreTrainedModel
12+
class AlbertForMaskedLM extends BertPretrainedModel
1313
{
1414
public function __invoke(array $modelInputs): MaskedLMOutput
1515
{

src/Models/Pretrained/AlbertForQuestionAnswering.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* AlbertForQuestionAnswering is a class representing a Albert model for sequence classification.
1212
*/
13-
class AlbertForQuestionAnswering extends BertPreTrainedModel
13+
class AlbertForQuestionAnswering extends BertPretrainedModel
1414
{
1515
public function __invoke(array $modelInputs): SequenceClassifierOutput
1616
{

src/Models/Pretrained/AlbertForSequenceClassification.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* AlbertForSequenceClassification is a class representing a Albert model for sequence classification.
1212
*/
13-
class AlbertForSequenceClassification extends BertPreTrainedModel
13+
class AlbertForSequenceClassification extends BertPretrainedModel
1414
{
1515
public function __invoke(array $modelInputs): SequenceClassifierOutput
1616
{

src/Models/Pretrained/AlbertModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Codewithkyrian\Transformers\Models\Pretrained;
77

8-
class AlbertModel extends AlbertPreTrainedModel
8+
class AlbertModel extends AlbertPretrainedModel
99
{
1010

1111
}

src/Models/Pretrained/AlbertPreTrainedModel.php src/Models/Pretrained/AlbertPretrainedModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Codewithkyrian\Transformers\Models\Pretrained;
77

8-
class AlbertPreTrainedModel extends PreTrainedModel
8+
class AlbertPretrainedModel extends PretrainedModel
99
{
1010

1111
}

src/Models/Pretrained/BertForMaskedLM.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* BertForMaskedLM class for performing masked language modeling on BERT models.
1111
*/
12-
class BertForMaskedLM extends BertPreTrainedModel
12+
class BertForMaskedLM extends BertPretrainedModel
1313
{
1414
public function __invoke(array $modelInputs): MaskedLMOutput
1515
{

src/Models/Pretrained/BertForQuestionAnswering.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* BertForQuestionAnswering is a class representing a BERT model for question answering.
1212
*/
13-
class BertForQuestionAnswering extends BertPreTrainedModel
13+
class BertForQuestionAnswering extends BertPretrainedModel
1414
{
1515
public function __invoke(array $modelInputs): QuestionAnsweringModelOutput
1616
{

src/Models/Pretrained/BertForSequenceClassification.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* BertForSequenceClassification is a class representing a BERT model for sequence classification.
1212
*/
13-
class BertForSequenceClassification extends BertPreTrainedModel
13+
class BertForSequenceClassification extends BertPretrainedModel
1414
{
1515
public function __invoke(array $modelInputs): SequenceClassifierOutput
1616
{

src/Models/Pretrained/BertForTokenClassification.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* BertForTokenClassification is a class representing a BERT model for token classification.
1212
*/
13-
class BertForTokenClassification extends BertPreTrainedModel
13+
class BertForTokenClassification extends BertPretrainedModel
1414
{
1515
public function __invoke(array $modelInputs): TokenClassifierOutput
1616
{

src/Models/Pretrained/BertModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
namespace Codewithkyrian\Transformers\Models\Pretrained;
77

8-
class BertModel extends BertPreTrainedModel
8+
class BertModel extends BertPretrainedModel
99
{
1010
}

src/Models/Pretrained/BertPreTrainedModel.php src/Models/Pretrained/BertPretrainedModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Codewithkyrian\Transformers\Models\Pretrained;
77

8-
class BertPreTrainedModel extends PretrainedModel
8+
class BertPretrainedModel extends PretrainedModel
99
{
1010

1111
}

src/Models/Pretrained/CodeGenForCausalLM.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* CodeGenForCausalLM is a class that represents a code generation model based on the GPT-2 architecture. It extends the `CodeGenPreTrainedModel` class.
1010
*/
11-
class CodeGenForCausalLM extends CodeGenPreTrainedModel
11+
class CodeGenForCausalLM extends CodeGenPretrainedModel
1212
{
1313

1414
}

src/Models/Pretrained/CodeGenModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* CodeGenModel is a class representing a code generation model without a language model head.
1010
*/
11-
class CodeGenModel extends CodeGenPreTrainedModel
11+
class CodeGenModel extends CodeGenPretrainedModel
1212
{
1313

1414
}

src/Models/Pretrained/CodeGenPreTrainedModel.php src/Models/Pretrained/CodeGenPretrainedModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Codewithkyrian\Transformers\Utils\AutoConfig;
1010
use OnnxRuntime\InferenceSession;
1111

12-
class CodeGenPreTrainedModel extends PretrainedModel
12+
class CodeGenPretrainedModel extends PretrainedModel
1313
{
1414
protected int $numHeads;
1515
protected int $numLayers;

src/Models/Pretrained/DebertaForMaskedLM.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* DebertaForMaskedLM class for performing masked language modeling on DeBERTa models.
1111
*/
12-
class DebertaForMaskedLM extends DebertaPreTrainedModel
12+
class DebertaForMaskedLM extends DebertaPretrainedModel
1313
{
1414
public function __invoke(array $modelInputs): MaskedLMOutput
1515
{

src/Models/Pretrained/DebertaForQuestionAnswering.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* DeBERTa Model with a span classification head on top for extractive question-answering tasks like SQuAD (a linear
1212
* layers on top of the hidden-states output to compute `span start logits` and `span end logits`).
1313
*/
14-
class DebertaForQuestionAnswering extends DebertaPreTrainedModel
14+
class DebertaForQuestionAnswering extends DebertaPretrainedModel
1515
{
1616
public function __invoke(array $modelInputs): QuestionAnsweringModelOutput
1717
{

src/Models/Pretrained/DebertaForSequenceClassification.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* DebertaForSequenceClassification is a class representing a DeBERTa model for sequence classification.
1212
*/
13-
class DebertaForSequenceClassification extends DebertaPreTrainedModel
13+
class DebertaForSequenceClassification extends DebertaPretrainedModel
1414
{
1515
public function __invoke(array $modelInputs): SequenceClassifierOutput
1616
{

src/Models/Pretrained/DebertaForTokenClassification.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* DebertaForTokenClassification is a class representing a DeBERTa model for token classification.
1212
*/
13-
class DebertaForTokenClassification extends DebertaPreTrainedModel
13+
class DebertaForTokenClassification extends DebertaPretrainedModel
1414
{
1515
public function __invoke(array $modelInputs): TokenClassifierOutput
1616
{

src/Models/Pretrained/DebertaModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* The bare DeBERTa Model transformer outputting raw hidden-states without any specific head on top.
1010
*/
11-
class DebertaModel extends DebertaPreTrainedModel
11+
class DebertaModel extends DebertaPretrainedModel
1212
{
1313

1414
}

src/Models/Pretrained/DebertaPreTrainedModel.php src/Models/Pretrained/DebertaPretrainedModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Codewithkyrian\Transformers\Models\Pretrained;
77

8-
class DebertaPreTrainedModel extends PreTrainedModel
8+
class DebertaPretrainedModel extends PretrainedModel
99
{
1010

1111
}

src/Models/Pretrained/DebertaV2ForMaskedLM.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* DeBERTa-V2 Model with a `language modeling` head on top.
1111
*/
12-
class DebertaV2ForMaskedLM extends DebertaV2PreTrainedModel
12+
class DebertaV2ForMaskedLM extends DebertaV2PretrainedModel
1313
{
1414
public function __invoke(array $modelInputs): MaskedLMOutput
1515
{

src/Models/Pretrained/DebertaV2ForQuestionAnswering.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* DeBERTa-V2 Model with a span classification head on top for extractive question-answering tasks like SQuAD (a linear
1212
* layers on top of the hidden-states output to compute `span start logits` and `span end logits`).
1313
*/
14-
class DebertaV2ForQuestionAnswering extends DebertaV2PreTrainedModel
14+
class DebertaV2ForQuestionAnswering extends DebertaV2PretrainedModel
1515
{
1616
public function __invoke(array $modelInputs): QuestionAnsweringModelOutput
1717
{

src/Models/Pretrained/DebertaV2ForSequenceClassification.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* DeBERTa-V2 Model transformer with a sequence classification/regression head on top (a linear layer on top of the pooled output)
1212
*/
13-
class DebertaV2ForSequenceClassification extends DebertaV2PreTrainedModel
13+
class DebertaV2ForSequenceClassification extends DebertaV2PretrainedModel
1414
{
1515
public function __invoke(array $modelInputs): SequenceClassifierOutput
1616
{

src/Models/Pretrained/DebertaV2ForTokenClassification.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* DeBERTa-V2 Model with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for Named-Entity-Recognition (NER) tasks.
1212
*/
13-
class DebertaV2ForTokenClassification extends DebertaV2PreTrainedModel
13+
class DebertaV2ForTokenClassification extends DebertaV2PretrainedModel
1414
{
1515
public function __invoke(array $modelInputs): TokenClassifierOutput
1616
{

src/Models/Pretrained/DebertaV2Model.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* The bare DeBERTa-V2 Model transformer outputting raw hidden-states without any specific head on top.
1010
*/
11-
class DebertaV2Model extends DebertaV2PreTrainedModel
11+
class DebertaV2Model extends DebertaV2PretrainedModel
1212
{
1313

1414
}

0 commit comments

Comments
 (0)