CodeWithKyrian / transformers-php

Transformers PHP is a toolkit for PHP developers to add machine learning magic to their projects easily.
https://codewithkyrian.github.io/transformers-php/
Apache License 2.0
549 stars 29 forks source link

PHP Fatal error: Uncaught TypeError: Codewithkyrian\Transformers\Utils\AutoConfig::__construct(): Argument #1 ($config) must be of type array, null given #62

Open Tinywan opened 2 months ago

Tinywan commented 2 months ago

Your question

sudo /usr/local/php-8.3.1/bin/php ./vendor/bin/transformers download openblas-linux-x86_64-0.3.27

✔ Initializing download... PHP Fatal error: Uncaught TypeError: Codewithkyrian\Transformers\Utils\AutoConfig::__construct(): Argument #1 ($config) must be of type array, null given, called in /home/www/build/php8/vendor/codewithkyrian/transformers/src/Utils/AutoConfig.php on line 52 and defined in /home/www/build/php8/vendor/codewithkyrian/transformers/src/Utils/AutoConfig.php:25 Stack trace:

0 /home/www/build/php8/vendor/codewithkyrian/transformers/src/Utils/AutoConfig.php(52): Codewithkyrian\Transformers\Utils\AutoConfig->__construct()

1 /home/www/build/php8/vendor/codewithkyrian/transformers/src/Models/Auto/PretrainedMixin.php(52): Codewithkyrian\Transformers\Utils\AutoConfig::fromPretrained()

2 /home/www/build/php8/vendor/codewithkyrian/transformers/src/Commands/DownloadModelCommand.php(89): Codewithkyrian\Transformers\Models\Auto\PretrainedMixin::fromPretrained()

3 /home/www/build/php8/vendor/symfony/console/Command/Command.php(279): Codewithkyrian\Transformers\Commands\DownloadModelCommand->execute()

4 /home/www/build/php8/vendor/symfony/console/Application.php(1029): Symfony\Component\Console\Command\Command->run()

5 /home/www/build/php8/vendor/symfony/console/Application.php(316): Symfony\Component\Console\Application->doRunCommand()

6 /home/www/build/php8/vendor/symfony/console/Application.php(167): Symfony\Component\Console\Application->doRun()

7 /home/www/build/php8/vendor/codewithkyrian/transformers/bin/transformers(18): Symfony\Component\Console\Application->run()

8 /home/www/build/php8/vendor/bin/transformers(119): include('...')

9 {main}

thrown in /home/www/build/php8/vendor/codewithkyrian/transformers/src/Utils/AutoConfig.php on line 25

Context (optional)

PHP Version

/usr/local/php-8.3.1/bin/php -v
PHP 8.3.1 (cli) (built: Dec 25 2023 21:14:50) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.1, Copyright (c) Zend Technologies

Reference (optional)

No response

RBFraphael commented 3 weeks ago

Also having this problem. Did you found a solution?

In my case, I'm facing the same exception, but when running the code (not downloading model).

<?php

use function Codewithkyrian\Transformers\Pipelines\pipeline;

require_once __DIR__ . "/vendor/autoload.php";

$textGenerator = pipeline('text-generation', 'meta-llama/Llama-3.2-1B', quantized: false);
$input = <<<INPUT
Generate a text talking about trees in Central Park.
INPUT;

$data = $textGenerator($input);

var_dump($data);

When running with php main.php, the following exception is thrown in terminal:

PHP Fatal error:  Uncaught TypeError: Codewithkyrian\Transformers\Utils\AutoConfig::__construct(): Argument #1 ($config) must be of type array, null given, called in /home/raphael/Projects/AI/llama/vendor/codewithkyrian/transformers/src/Utils/AutoConfig.php on line 52 and defined in /home/raphael/Projects/AI/llama/vendor/codewithkyrian/transformers/src/Utils/AutoConfig.php:25
Stack trace:
#0 /home/raphael/Projects/AI/llama/vendor/codewithkyrian/transformers/src/Utils/AutoConfig.php(52): Codewithkyrian\Transformers\Utils\AutoConfig->__construct()
#1 /home/raphael/Projects/AI/llama/vendor/codewithkyrian/transformers/src/Models/Auto/PretrainedMixin.php(52): Codewithkyrian\Transformers\Utils\AutoConfig::fromPretrained()
#2 /home/raphael/Projects/AI/llama/vendor/codewithkyrian/transformers/src/Pipelines/Task.php(180): Codewithkyrian\Transformers\Models\Auto\PretrainedMixin::fromPretrained()
#3 /home/raphael/Projects/AI/llama/vendor/codewithkyrian/transformers/src/Pipelines/Pipeline.php(80): Codewithkyrian\Transformers\Pipelines\Task->autoModel()
#4 /home/raphael/Projects/AI/llama/main.php(7): Codewithkyrian\Transformers\Pipelines\pipeline()
#5 {main}
  thrown in /home/raphael/Projects/AI/llama/vendor/codewithkyrian/transformers/src/Utils/AutoConfig.php on line 25

Here's my PHP version:

PHP 8.3.12 (cli) (built: Sep 27 2024 03:53:05) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.12, Copyright (c), by Zend Technologies
    with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans

Important to mention that I've manually downloaded the meta-llama/Llama-3.2-1B from HuggingFace, and converted to onnx using the conversion script. When testing without specifying a model, it works as expected. So, maybe there's a problem when you specify a model that is already downloaded.


EDIT

Also tested with other model (Xenova/gpt-3.5-turbo ) and ran into the same issue.

$textGenerator = pipeline('text-generation', 'Xenova/gpt-3.5-turbo');