transformers-php icon indicating copy to clipboard operation
transformers-php copied to clipboard

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

Open Tinywan opened this issue 1 year ago • 13 comments

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

Tinywan avatar Aug 23 '24 01:08 Tinywan

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');

RBFraphael avatar Oct 09 '24 13:10 RBFraphael

Maybe you have the same issue I had? You are trying the whole thing on a system without SSL enabled for CURL in PHP?

This answer here helps how to do this: https://stackoverflow.com/questions/28858351/php-ssl-certificate-error-unable-to-get-local-issuer-certificate

BillyGeat avatar Nov 21 '24 16:11 BillyGeat

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

I had the same problem. Did you solve it? How to solve?

swanghao avatar Feb 19 '25 09:02 swanghao

Try

[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo = "C:/…/cacert-2025-05-20.pem"

in php.ini. Take .pem from https://curl.se/docs/caextract.html.

raubv0gel avatar Jun 01 '25 20:06 raubv0gel

The curl .pem in php.ini didnt work for me, did anyone figure out a different solution yet?

Jieoogle avatar Sep 05 '25 10:09 Jieoogle

The curl .pem in php.ini didnt work for me, did anyone figure out a different solution yet?

Have you also added this .pem file into the [openssl] part?

This is how my php.ini looks like:

[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo = c:/webserver/cacert-2024-09-24.pem

[openssl]
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the identity of SSL/TLS peers. Most users should
; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
openssl.cafile=c:/webserver/cacert-2024-09-24.pem

BillyGeat avatar Sep 05 '25 10:09 BillyGeat

I did yea, this is my php.ini and i still get the same Error [curl] ; A default value for the CURLOPT_CAINFO option. This is required to be an ; absolute path. curl.cainfo = C:/Server/cacert-09-24.pem

[openssl] ; The location of a Certificate Authority (CA) file on the local filesystem ; to use when verifying the identity of SSL/TLS peers. Most users should ; not specify a value for this directive as PHP will attempt to use the ; OS-managed cert stores in its absence. If specified, this value may still ; be overridden on a per-stream basis via the "cafile" SSL stream context ; option. openssl.cafile = C:/Server/cacert-2024-09-24.pem

Fatal error: Uncaught TypeError: Codewithkyrian\Transformers\Configs\PretrainedConfig::__construct(): Argument #1 ($config) must be of type array, null given, called in C:\Server\web\vendor\codewithkyrian\transformers\src\Configs\PretrainedConfig.php on line 57 and defined in C:\Server\web\vendor\codewithkyrian\transformers\src\Configs\PretrainedConfig.php:29 Stack trace: #0 C:\Server\web\vendor\codewithkyrian\transformers\src\Configs\PretrainedConfig.php(57): Codewithkyrian\Transformers\Configs\PretrainedConfig->__construct(NULL) #1 C:\Server\web\vendor\codewithkyrian\transformers\src\Configs\AutoConfig.php(20): Codewithkyrian\Transformers\Configs\PretrainedConfig::fromPretrained('Xenova/all-Mini...', NULL, NULL, 'main', NULL) #2 C:\Server\web\vendor\codewithkyrian\transformers\src\Models\Auto\AutoModelBase.php(51): Codewithkyrian\Transformers\Configs\AutoConfig::fromPretrained('Xenova/all-Mini...', NULL, NULL, 'main', NULL) #3 C:\Server\web\vendor\codewithkyrian\transformers\src\Pipelines\Pipeline.php(85): Codewithkyrian\Transformers\Models\Auto\AutoModelBase::fromPretrained('Xenova/all-Mini...', true, NULL, NULL, 'main', NULL, NULL) #4 C:\Server\web\index.php(8): Codewithkyrian\Transformers\Pipelines\pipeline(Codewithkyrian\Transformers\Pipelines\Task::Embeddings, 'Xenova/all-Mini...') #5 {main} Next RuntimeException: Could not instantiate model for task: embeddings in C:\Server\web\vendor\codewithkyrian\transformers\src\Pipelines\Pipeline.php:93 Stack trace: #0 C:\Server\web\index.php(8): Codewithkyrian\Transformers\Pipelines\pipeline(Codewithkyrian\Transformers\Pipelines\Task::Embeddings, 'Xenova/all-Mini...') #1 {main} thrown in C:\Server\web\vendor\codewithkyrian\transformers\src\Pipelines\Pipeline.php on line 93

Jieoogle avatar Sep 05 '25 10:09 Jieoogle

I did yea, this is my php.ini and i still get the same Error

To be sure, that these two both accepted by PHP, can you please also check in phpinfo() that you see them there? They are then listed as Directives, on both, local and master value.

BillyGeat avatar Sep 05 '25 11:09 BillyGeat

Image Image

Yes they are both listed

Jieoogle avatar Sep 05 '25 11:09 Jieoogle

Out of curiosity: Why you have one time cacert-09-24.pem and the other cacert-2024-09-24.pem?

BillyGeat avatar Sep 05 '25 11:09 BillyGeat

Because i forgot to change it, but even after i changed it to be the same now the errors still the same

can i provide any other information that might be helpful to fixing this issue?

Jieoogle avatar Sep 05 '25 11:09 Jieoogle

I am not sure about this (assuming it is the same issue I had...), I have found my solution by debugging (NetBeans with xdebug) the whole procedure step by step to find where exactly it brakes and why.

BillyGeat avatar Sep 05 '25 11:09 BillyGeat

Ok so it seemed to work somehow, im getting a different Error now but ill try my best to work through it, thank you!

Jieoogle avatar Sep 05 '25 12:09 Jieoogle