Skip to content

Commit f5a4bc7

Browse files
Merge remote-tracking branch 'origin/main' into audio-features
2 parents 74b8c34 + 7f80870 commit f5a4bc7

4 files changed

Lines changed: 61 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
All notable changes to `transformers-php` will be documented in this file.
44

5+
## v0.4.1 - 2024-05-24
6+
7+
### What's Changed
8+
9+
* configuration.md: fix indentation of Transformers::setup() by @k00ni in https://github.com/CodeWithKyrian/transformers-php/pull/35
10+
* PretrainedTokenizer::truncateHelper: prevent array_slice() error for flawed text input (summarization) by @k00ni in https://github.com/CodeWithKyrian/transformers-php/pull/36
11+
* Fix bug with Download CLI - use named parameters for model construct by @CodeWithKyrian in https://github.com/CodeWithKyrian/transformers-php/pull/39
12+
13+
### New Contributors
14+
15+
* @k00ni made their first contribution in https://github.com/CodeWithKyrian/transformers-php/pull/35
16+
17+
**Full Changelog**: https://github.com/CodeWithKyrian/transformers-php/compare/0.4.0...0.4.1
18+
519
## v0.3.1 - 2024-04-22
620

721
### What's Changed
@@ -95,6 +109,7 @@ composer require codewithkyrian/transformers
95109

96110

97111

112+
98113
```
99114
And you must initialize the library to download neccesary libraries for ONNX
100115

@@ -106,6 +121,7 @@ And you must initialize the library to download neccesary libraries for ONNX
106121

107122

108123

124+
109125
```
110126
#### Checkout the Documentation
111127

@@ -123,6 +139,7 @@ To ensure a smooth user experience, especially with larger models, we recommend
123139

124140

125141

142+
126143
```
127144
#### What's Next?
128145

docs/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ models, and the remote path template. These settings allow you to tailor how and
1616
use Codewithkyrian\Transformers\Transformers;
1717
use Codewithkyrian\Transformers\Utils\ImageDriver;
1818

19-
Transformers::setup()
19+
Transformers::setup()
2020
->setCacheDir('/path/to/models')
2121
->setImageDriver(ImageDriver::IMAGICK)
2222
->setRemoteHost('https://yourmodelshost.com')
@@ -198,4 +198,4 @@ public function boot()
198198

199199
Now that you've learned how to configure TransformersPHP, you can start using the library to download and use
200200
pre-trained ONNX models. For more information on how to use the library, check out
201-
the [Getting Started](getting-started.md) guide.
201+
the [Getting Started](getting-started.md) guide.

src/Models/Pretrained/PretrainedModel.php

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static function fromPretrained(
8585
string $revision = 'main',
8686
?string $modelFilename = null,
8787
ModelArchitecture $modelArchitecture = ModelArchitecture::EncoderOnly,
88-
?callable $onProgress = null
88+
?callable $onProgress = null
8989
): self
9090
{
9191
if (is_array($config)) {
@@ -116,7 +116,12 @@ public static function fromPretrained(
116116

117117
$generatorConfig = new GenerationConfig($generatorConfigArr);
118118

119-
return new static($config, $session, $modelArchitecture, $generatorConfig);
119+
return new static(
120+
config: $config,
121+
session: $session,
122+
modelArchitecture: $modelArchitecture,
123+
generationConfig: $generatorConfig
124+
);
120125
}
121126

122127
case ModelArchitecture::Seq2SeqLM:
@@ -149,8 +154,13 @@ public static function fromPretrained(
149154

150155
$generatorConfig = new GenerationConfig($generatorConfigArr);
151156

152-
153-
return new static($config, $encoderSession, $decoderSession, $modelArchitecture, $generatorConfig);
157+
return new static(
158+
config: $config,
159+
session: $encoderSession,
160+
modelArchitecture: $modelArchitecture,
161+
generationConfig: $generatorConfig,
162+
decoderMergedSession: $decoderSession
163+
);
154164
}
155165

156166
case ModelArchitecture::MaskGeneration:
@@ -171,7 +181,12 @@ public static function fromPretrained(
171181
onProgress: $onProgress
172182
);
173183

174-
return new static($config, $visionEncoder, $promptMaskEncoder, $modelArchitecture);
184+
return new static(
185+
config: $config,
186+
session: $visionEncoder,
187+
promptMaskEncoderSession: $promptMaskEncoder,
188+
modelArchitecture: $modelArchitecture
189+
);
175190
}
176191

177192
case ModelArchitecture::EncoderDecoder:
@@ -192,7 +207,12 @@ public static function fromPretrained(
192207
onProgress: $onProgress
193208
);
194209

195-
return new static($config, $encoderSession, $decoderSession, $modelArchitecture);
210+
return new static(
211+
config: $config,
212+
session: $encoderSession,
213+
decoderMergedSession: $decoderSession,
214+
modelArchitecture: $modelArchitecture
215+
);
196216
}
197217

198218
default:
@@ -211,7 +231,11 @@ public static function fromPretrained(
211231
);
212232

213233

214-
return new static($config, $session, $modelArchitecture);
234+
return new static(
235+
config: $config,
236+
session: $session,
237+
modelArchitecture: $modelArchitecture
238+
);
215239
}
216240
}
217241
}
@@ -233,14 +257,14 @@ public static function fromPretrained(
233257
*/
234258

235259
public static function constructSession(
236-
string $modelNameOrPath,
237-
string $fileName,
238-
?string $cacheDir = null,
239-
string $revision = 'main',
240-
string $subFolder = 'onnx',
241-
bool $fatal = true,
260+
string $modelNameOrPath,
261+
string $fileName,
262+
?string $cacheDir = null,
263+
string $revision = 'main',
264+
string $subFolder = 'onnx',
265+
bool $fatal = true,
242266
?callable $onProgress = null,
243-
...$sessionOptions
267+
...$sessionOptions
244268
): ?InferenceSession
245269
{
246270
$modelFileName = "$fileName.onnx";

src/PretrainedTokenizers/PretrainedTokenizer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ function truncateHelper(array &$item, int $length): void
468468
// Setting .length to a lower value truncates the array in-place.
469469
// Note: In PHP, arrays automatically adjust their size, so we don't need to explicitly set the length.
470470
foreach (array_keys($item) as $key) {
471+
if (false == $item[$key]) {
472+
continue;
473+
}
474+
471475
$item[$key] = array_slice($item[$key], 0, $length);
472476
}
473477
}

0 commit comments

Comments
 (0)