Skip to content

Commit 3f3db2b

Browse files
feat: Revamp library architecture and platform support
- Converted library to a platform-package with cross-platform native library support - Added platform-specific shared libraries for Linux, macOS, and Windows (x86_64 and ARM64) - Refactored FFI library loading mechanism to support dynamic library resolution - Updated composer configuration to support platform-specific package installation - Introduced new native library classes for OpenBLAS, RindowMatlib, and other dependencies - Simplified native library interaction and improved platform compatibility - Updated example configurations and test cases to reflect new architecture
1 parent cbfd6e1 commit 3f3db2b

103 files changed

Lines changed: 8711 additions & 753 deletions

File tree

Some content is hidden

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

composer.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
"php",
1212
"codewithkyrian"
1313
],
14-
"type": "library",
14+
"type": "platform-package",
1515
"require": {
1616
"php": "^8.1",
1717
"ext-ffi": "*",
1818
"codewithkyrian/jinja-php": "^1.0",
19-
"codewithkyrian/transformers-libsloader": "^2.0",
2019
"imagine/imagine": "^1.3",
2120
"rindow/rindow-math-matrix": "^2.0",
2221
"rindow/rindow-matlib-ffi": "^1.0",
2322
"rindow/rindow-openblas-ffi": "^1.0",
23+
"rokka/imagine-vips": "^0.31.0",
2424
"symfony/console": "^6.4|^7.0",
25-
"rokka/imagine-vips": "^0.31.0"
25+
"codewithkyrian/platform-package-installer": "^1.0"
2626
},
2727
"require-dev": {
2828
"pestphp/pest": "^2.31",
@@ -52,21 +52,28 @@
5252
"config": {
5353
"allow-plugins": {
5454
"pestphp/pest-plugin": true,
55-
"codewithkyrian/transformers-libsloader": true
55+
"codewithkyrian/platform-package-installer": true
5656
}
5757
},
5858
"bin": [
5959
"bin/transformers"
6060
],
6161
"scripts": {
6262
"test": "vendor/bin/pest",
63-
"test:coverage": "XDEBUG_MODE=coverage ./vendor/bin/pest --coverage",
64-
"post-install-cmd": "Codewithkyrian\\Transformers\\Utils\\LibsChecker::check",
65-
"post-update-cmd": "Codewithkyrian\\Transformers\\Utils\\LibsChecker::check"
63+
"test:coverage": "XDEBUG_MODE=coverage ./vendor/bin/pest --coverage"
6664
},
6765
"archive": {
6866
"exclude": [
6967
"/docs"
7068
]
69+
},
70+
"extra": {
71+
"platform-urls": {
72+
"linux-x86_64": "https://github.com/codewithkyrian/transformers-php/releases/download/{version}/dist-linux-x86_64.tar.gz",
73+
"linux-arm64": "https://github.com/codewithkyrian/transformers-php/releases/download/{version}/dist-linux-arm64.tar.gz",
74+
"darwin-x86_64": "https://github.com/codewithkyrian/transformers-php/releases/download/{version}/dist-darwin-x86_64.tar.gz",
75+
"darwin-arm64": "https://github.com/codewithkyrian/transformers-php/releases/download/{version}/dist-darwin-arm64.tar.gz",
76+
"windows-x86_64": "https://github.com/codewithkyrian/transformers-php/releases/download/{version}/dist-windows-x86_64.zip"
77+
}
7178
}
7279
}

examples/composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"require": {
1515
"php": "^8.1",
1616
"symfony/console": "^7.0",
17-
"codewithkyrian/transformers": "*",
18-
"codewithkyrian/transformers-libsloader": "^2.0"
17+
"codewithkyrian/transformers": "dev-model-revamp"
1918
},
2019
"require-dev": {
2120
"symfony/var-dumper": "^7.0"
@@ -29,9 +28,8 @@
2928
],
3029
"config": {
3130
"allow-plugins": {
32-
"codewithkyrian/transformers-libraries-downloader": true,
3331
"codewithkyrian/transformers-libsloader": true,
34-
"codewithkyrian/composer-platform-packages": true
32+
"codewithkyrian/platform-package-installer": true
3533
}
3634
}
3735
}

examples/misc/general-test.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
use Codewithkyrian\Transformers\FFI\OnnxRuntime;
66
use Codewithkyrian\Transformers\FFI\Samplerate;
77
use Codewithkyrian\Transformers\FFI\Sndfile;
8+
use Codewithkyrian\Transformers\Tensor\Tensor;
89

910
include __DIR__.'/../vendor/autoload.php';
1011

1112
OnnxRuntime::version();
1213
dd(\Codewithkyrian\Transformers\Utils\timeUsage(true));
1314

14-
dd(
15-
Libc::version(),
16-
Sndfile::version(),
17-
Samplerate::version(),
18-
OnnxRuntime::version(),
19-
TransformersUtils::version()
20-
);
15+
$x = Tensor::fromArray([
16+
[1, 2, 3],
17+
[4, 5, 6],
18+
[7, 8, 9],
19+
]);
20+
21+
dd($x->toArray());

examples/pipelines/asr.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
//$transcriber = pipeline('automatic-speech-recognition', 'Xenova/wav2vec2-large-xlsr-53-english');
1818

1919
//$audioUrl = __DIR__ . '/../sounds/kyrian-dev.wav';
20-
//$audioUrl = __DIR__ . '/../sounds/jfk.wav';
20+
$audioUrl = __DIR__ . '/../sounds/jfk.wav';
2121
//$audioUrl = __DIR__ . '/../sounds/preamble.wav';
2222
//$audioUrl = __DIR__ . '/../sounds/taunt.wav';
2323
//$audioUrl = __DIR__ . '/../sounds/gettysburg.wav';
2424
//$audioUrl = __DIR__ . '/../sounds/kyrian-speaking.wav';
25-
$audioUrl = __DIR__ . '/../sounds/ted_60.wav';
25+
//$audioUrl = __DIR__ . '/../sounds/ted_60.wav';
2626
//$audioUrl = __DIR__ . '/../sounds/sample-1.mp3';
2727

28-
$streamer = WhisperTextStreamer::make()
28+
$streamer = WhisperTextStreamer::make();
2929
//->onTimestampStart(fn($timestamp) => dump($timestamp));
30-
->onStream(fn($text) => print($text));
30+
//->onStream(fn($text) => print($text));
3131

3232
$output = $transcriber($audioUrl,
3333
maxNewTokens: 256,

index.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
require_once __DIR__ . '/vendor/autoload.php';
4+
5+
use Codewithkyrian\Transformers\FFI\OnnxRuntime;
6+
use Codewithkyrian\Transformers\FFI\Samplerate;
7+
use Codewithkyrian\Transformers\FFI\Sndfile;
8+
9+
$samplerate = new Samplerate();
10+
11+
echo $samplerate->version();

libs/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

platforms.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
linux-x86_64:
2+
exclude:
3+
- shared/linux-arm64
4+
- shared/darwin-*
5+
- shared/windows-*
6+
- "*.exe"
7+
- "*.dylib"
8+
- "**/*.windows.*"
9+
10+
linux-arm64:
11+
exclude:
12+
- shared/linux-x86_64
13+
- shared/windows-*
14+
- shared/darwin-*
15+
- "*.exe"
16+
- "*.dylib"
17+
- "**/*.windows.*"
18+
19+
darwin-x86_64:
20+
exclude:
21+
- shared/darwin-arm64
22+
- shared/windows-*
23+
- shared/linux-*
24+
- "*.exe"
25+
- "*.so"
26+
- "**/*.linux.*"
27+
28+
darwin-arm64:
29+
exclude:
30+
- shared/darwin-x86_64
31+
- shared/windows-*
32+
- shared/linux-*
33+
- "*.exe"
34+
- "*.so"
35+
- "**/*.linux.*"
36+
37+
windows-x86_64:
38+
exclude:
39+
- shared/linux-*
40+
- shared/darwin-*
41+
- "*.so"
42+
- "*.dylib"
43+
- "**/*.darwin.*"
44+
- "**/*.linux.*"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Third-party notices
2+
3+
TransformersPHP includes compiled binaries of third-party libraries as a convenience to users. These binaries are
4+
distributed to facilitate the functionality of TransformersPHP, but TransformersPHP does not claim ownership of the
5+
binaries or the underlying libraries. The original authors and contributors of these libraries retain all rights. It is
6+
the user's responsibility to ensure compliance with the respective licenses of these libraries when using or
7+
distributing the bundled binaries.
8+
9+
Below is a list of the third-party libraries included with TransformersPHP, along with their respective licenses and
10+
other relevant information.
11+
12+
| Library | Used under the terms of |
13+
|---------------|-----------------------------------------------------------------------------------------------------------|
14+
| OpenMP | MIT License |
15+
| OnnxRuntime | MIT License |
16+
| OpenBlas | BSD 3-Clause License |
17+
| Rindow Matlib | BSD 3-Clause License |
18+
| LibSamplerate | BSD 2-Clause License |
19+
| Libsndfile | LGPL 2.1 License |
20+
| aom | BSD 2-Clause + [Alliance for Open Media Patent License 1.0](https://aomedia.org/license/patent-license/) |
21+
| cairo | Mozilla Public License 2.0 |
22+
| cgif | MIT Licence |
23+
| expat | MIT Licence |
24+
| fontconfig | [fontconfig Licence](https://gitlab.freedesktop.org/fontconfig/fontconfig/blob/main/COPYING) (BSD-like) |
25+
| freetype | [freetype Licence](https://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/docs/FTL.TXT) (BSD-like) |
26+
| fribidi | LGPLv3 |
27+
| glib | LGPLv3 |
28+
| harfbuzz | MIT Licence |
29+
| highway | Apache-2.0 License, BSD 3-Clause |
30+
| lcms | MIT Licence |
31+
| libarchive | BSD 2-Clause |
32+
| libexif | LGPLv3 |
33+
| libffi | MIT Licence |
34+
| libheif | LGPLv3 |
35+
| libimagequant | [BSD 2-Clause](https://github.com/lovell/libimagequant/blob/main/COPYRIGHT) |
36+
| libnsgif | MIT Licence |
37+
| libpng | [libpng License](https://github.com/pnggroup/libpng/blob/master/LICENSE) |
38+
| librsvg | LGPLv3 |
39+
| libspng | [BSD 2-Clause, libpng License](https://github.com/randy408/libspng/blob/master/LICENSE) |
40+
| libtiff | [libtiff License](https://gitlab.com/libtiff/libtiff/blob/master/LICENSE.md) (BSD-like) |
41+
| libvips | LGPLv3 |
42+
| libwebp | New BSD License |
43+
| libxml2 | MIT Licence |
44+
| mozjpeg | [zlib License, IJG License, BSD-3-Clause](https://github.com/mozilla/mozjpeg/blob/master/LICENSE.md) |
45+
| pango | LGPLv3 |
46+
| pixman | MIT Licence |
47+
| proxy-libintl | LGPLv3 |
48+
| zlib-ng | [zlib Licence](https://github.com/zlib-ng/zlib-ng/blob/develop/LICENSE.md) |
49+
50+
---
51+
52+

0 commit comments

Comments
 (0)