-
Notifications
You must be signed in to change notification settings - Fork 479
feat: optimize the native library loading. #688
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
Conversation
|
Can this be split into two parts (in two PRs):
With that split we've exposed all of the parts required for custom downloaders to be implemented outside of the project, which then means people can use this auto download infrastructure but without having to trust our binaries at all. If that separation is made we can also have the debate about if LLamaSharp should include a default implementation, I'm strongly of the opinion it shouldn't. We can provide a downloader as a separate package if we want (e.g. LLamaSharp.backend.AutoDownload backend). This would also mean we avoid adding another external dependency to LLamaSharp. |
|
I'll modify this PR to leave only the parts not related with downloading and add the other as a separate PR. |
|
@martindevans I've removed all things related with auto-download. |
|
I haven't gone through this fully in depth, but there's a few minor nitpicks I noticed above. Overall this looks like a good direction. I like the idea to split the various type of native libs up into separate files altogether, that'll get some of the complexity of the system udner control! |
Co-authored-by: Martin Evans <[email protected]>
Co-authored-by: Martin Evans <[email protected]>
Implement the proposal in #670
Public API changes
Add
NativeLibraryConfig.WithAutoDownloadBy default it's disabled and the user could enable it with some settings.
Add
NativeLibraryConfig.WithSelectingPolicyTo allow users to customize the auto-selection process. Users could return a list of paths from
INativeLibrarySelectingPolicy.Select, ordered by the priority.Make
NativeLibraryConfig.DescriptionpublicI made this change to simplify some implementations. It seems not to be risky to expose this class.
Add
NativeLibraryConfig.All,NativeLibraryConfig.LLama,NativeLibraryConfig.LLavaSharedand makeNativeLibraryConfig.Instanceobsolete.There has been two native libraries now, so the name
Instanceseems no longer reasonable. With this modification, users could specify configurations for one of them. Meanwhile, usingNativeLibraryConfig.Allwill apply same configurations to both of them.Add
NativeLibraryConfig.VersionMapPlease tell me if there's a better design. I added it to provide a mapping from version tag (such as v0.11.2) to the llama.cpp commit hash, which is also the revision of huggingface remote branch.
Add
NativeLibraryConfig.DryRunThis API executes the whole loading process except assigning the loaded pointer to
NativeApi. I added it for the following two reasons.false, the user could have chances to revise the configuration before loading the model.Task.Result, I'm still not sure whether there's potential problem using async method in a static constructor. So, currently, users are supposed to callDryRunwhen auto-download is enabled.Other changes
TODO
How to test it
Comment all the content in LLama/LLamaSharp.Runtime.targets and run the examples. It's better to enable the full logs (though in a bit mess now).