Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot load libllama from Mac with Intel CPU #241

Closed
mayuanyang opened this issue Nov 4, 2023 · 13 comments
Closed

Cannot load libllama from Mac with Intel CPU #241

mayuanyang opened this issue Nov 4, 2023 · 13 comments
Assignees
Labels
enhancement New feature or request

Comments

@mayuanyang
Copy link

Is the provided libllama.dll only working for Mac with M1 M2 CPU?

Got the following error when trying to load it on Mac with Intel CPU, however it is working fine on Mac with M2 CPU

System.TypeInitializationException: The type initializer for 'LLama.Native.NativeApi' threw an exception.
---> LLama.Exceptions.RuntimeError: The native library cannot be found. It could be one of the following reasons:

  1. No LLamaSharp backend was installed. Please search LLamaSharp.Backend and install one of them.

  2. You are using a device with only CPU but installed cuda backend. Please install cpu backend instead.

  3. The backend is not compatible with your system cuda environment. Please check and fix it. If the environment is expected not to be changed, then consider build llama.cpp from source or submit an issue to LLamaSharp.

  4. One of the dependency of the native library is missed.

    at LLama.Native.NativeApi..cctor() in /Users/eddyma/Github/LLamaSharp/LLama/Native/NativeApi.cs:line 36
    --- End of inner exception stack trace ---
    at LLama.Native.NativeApi.llama_max_devices()
    at LLama.Abstractions.TensorSplitsCollection..ctor() in /Users/eddyma/Github/LLamaSharp/LLama/Abstractions/IModelParams.cs:line 111
    at LLama.Common.ModelParams..ctor(String modelPath) in /Users/eddyma/Github/LLamaSharp/LLama/Common/ModelParams.cs:line 89
    at LLama.WebAPI.Services.StatefulChatService..ctor(IConfiguration configuration) in /Users/eddyma/Github/LLamaSharp/LLama.WebAPI/Services/StatefulChatService.cs:line 19
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Span1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func`2 valueFactory)
    at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
    at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
    at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ServicesModelBinder.BindModelAsync(ModelBindingContext bindingContext)
    at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value, Object container)

@nappa0326
Copy link

Hello. I also have the same issue, and when I asked a question at #58, I received this reply.

@mayuanyang
Copy link
Author

Hello. I also have the same issue, and when I asked a question at #58, I received this reply.

thanks for your info, do you have the intel dylib for handy?

@mayuanyang
Copy link
Author

I decided to build it myself, for those who need libllama.dylib for Mac Intel, you might try this one
libllama.dylib.zip
Hope this helps
Cheers

@SignalRT
Copy link
Collaborator

SignalRT commented Nov 4, 2023

@mayuanyang , @nappa0326. I'm not able to test this, but I give a try in this branch to generate Intel binaries. If you can give try to the libllama.dylib generated in the deps binaries that you can download from this run:

https://github.com/SignalRT/LLamaSharp/actions/runs/6754571177#artifacts

The library is in the folder macOS-x86_64:

image

If this works should be possible to include this in the nuget packages. Let me know if it works.

@SignalRT SignalRT self-assigned this Nov 4, 2023
@mayuanyang
Copy link
Author

Hi @SignalRT
I tried both the dylib i built and the one you mentioned from the Action, they both seems loading fine, however i got weird result as screenshot below, any thought?
image
image

@SignalRT
Copy link
Collaborator

SignalRT commented Nov 5, 2023

@mayuanyang I'm not sure that metal works on Intel CPUs. Theoretically the binary of my compilation should disable METAL, but it seems that it's using metal....

Please try first this solution:

You can explicitly disable GPU inference with the --n-gpu-layers|-ngl 0 command-line argument.

And as second option this solution:

To disable the Metal build at compile time use the LLAMA_NO_METAL=1 flag or the LLAMA_METAL=OFF cmake option.

@SignalRT SignalRT mentioned this issue Nov 5, 2023
2 tasks
@mayuanyang
Copy link
Author

@SignalRT have tried that, still generate weird output

@SignalRT
Copy link
Collaborator

SignalRT commented Nov 5, 2023

@mayuanyang . I think that this is not related with the intel library. It's related to the llama.cpp version. I have the same result in arm64 if I build the library with the current version. And it works ok with the version:

ggerganov/llama.cpp@207b519

It seems that the changes in the main.yaml to introduce the build to support macOS Intel works, because it loads and gets the same results that I get with the current llama.cpp

To close this issue If you can build the library from the 207b519 commit id from llama.cpp and check if every thing works find it would help a lot.

It will also help to check it with the Intel build metal works and can be deactivated with the gpu layers. It will help to create the right nuget package to the MacOS intel.

@SignalRT
Copy link
Collaborator

SignalRT commented Nov 5, 2023

I can confirm that the garbage in the output is related with the changes in latest llama.cpp. I make a PR #249 with the changes in the source code. If you test the intel binaries with this branch it should work ok.

@mayuanyang
Copy link
Author

@SignalRT FYI, I manage to compile the llama.cpp on Mac Intel and run it, things seems to be working fine, hope that helps, happy to submit PR for any help if required :)

@martindevans martindevans added the enhancement New feature or request label Nov 6, 2023
@martindevans
Copy link
Member

See #258 which is introducing Intel Mac support. It should be included in the next release (very soon).

@AsakusaRinne AsakusaRinne moved this to 🏗 In progress in LLamaSharp Dev Nov 9, 2023
@SignalRT
Copy link
Collaborator

@mayuanyang , Please confirm that the current version solve all the issues with OSX Intel.

@mayuanyang
Copy link
Author

it is working now, thanks

@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in LLamaSharp Dev Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: ✅ Done
Development

No branches or pull requests

4 participants