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
291 stars 16 forks source link

FFI::addr() cannot create a reference to a temporary pointer #28

Closed victorratts13 closed 2 months ago

victorratts13 commented 2 months ago

Your question

I'm working on a personal project where I'm trying to load a simple model for testing. I'm having some problems with FFI where I get the error:

FFI::addr() cannot create a reference to a temporary pointer

Enviroment:

Context (optional)

No response

Reference (optional)

No response

CodeWithKyrian commented 2 months ago

Can you provide more information about the model, and some code on how you set things up so I can try to reproduce the error?

victorratts13 commented 2 months ago

Basically, I'm doing a test, but using Laravel Framework in the most current version (11.0). Previously I did a test using a hugface text-to-text model, however, I changed it to the "Hello world" that the transformersphp documentation suggests:

So the code looked like this:

<?php

use Illuminate\Support\Facades\Route;

use function Codewithkyrian\Transformers\Pipelines\pipeline;

Route::get('/', function () {
    // return phpinfo();
    $pipe = pipeline('sentiment-analysis');
    return $pipe('I love transformers!');
});

As you may have noticed, I used phpinfo() to check if the suggested extensions were installed:

Captura de Tela 2024-04-30 às 03 06 24

victorratts13 commented 2 months ago

UPDATE:

When I was debugging the code I came across this PHP alert

 PHP Warning:  PHP Startup: Unable to load dynamic library 'ffi' (tried: /usr/local/lib/php/pecl/20230831/ffi (dlopen(/usr/local/lib/php/pecl/20230831/ffi, 0x0009): tried: '/usr/local/lib/php/pecl/20230831/ffi' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/lib/php/pecl/20230831/ffi' (no such file), '/usr/local/lib/php/pecl/20230831/ffi' (no such file)), /usr/local/lib/php/pecl/20230831/ffi.so (dlopen(/usr/local/lib/php/pecl/20230831/ffi.so, 0x0009): tried: '/usr/local/lib/php/pecl/20230831/ffi.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/lib/php/pecl/20230831/ffi.so' (no such file), '/usr/local/lib/php/pecl/20230831/ffi.so' (no such file))) in Unknown on line 0

I imagined it was something with the FFI library, so I decided to install it using perl, however, the message appears to me:

Captura de Tela 2024-04-30 às 03 09 43

CodeWithKyrian commented 2 months ago

Hello @victorratts13. Does the problem still persist? It appears to be a problem with your FFI setup. If I may ask, how did you php? Herd, Brew or apt-get?

victorratts13 commented 2 months ago

I just found the problem.

1 - I installed an ubuntu-server VM to test outside my work environment.

2 - I installed all the development packages that transformersphp uses

sudo apt update && sudo apt install -y libffi-dev libz-dev libpng-dev git libzip-dev

3 - I ran the code again and it worked

Conclusion

It remained to install the dependencies that make FFI work within the command line

CodeWithKyrian commented 2 months ago

Oh, that's great. I was going to suggest installing php-ffi using apt-get actually. I'm glad it's all resolved