diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d484501c..922059cb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,21 +2,65 @@ Hi, welcome to develop LLamaSharp with us together! We are always open for every contributor and any format of contributions! If you want to maintain this library actively together, please contact us to get the write access after some PRs. (Email: AsakusaRinne@gmail.com) -In this page, we'd like to introduce how to make contributions here easily. 😊 +In this page, we introduce how to make contributions here easily. 😊 -## Compile the native library from source +## The goal of LLamaSharp -Firstly, please clone the [llama.cpp](https://github.com/ggerganov/llama.cpp) repository and following the instructions in [llama.cpp readme](https://github.com/ggerganov/llama.cpp#build) to configure your local environment. +At the beginning, LLamaSharp is a C# binding of [llama.cpp](https://github.com/ggerganov/llama.cpp). It provided only some wrappers for llama.cpp to let C#/.NET users could run LLM models on their local device efficiently even if without any experience with C++. After around a year of development, more tools and integrations has been added to LLamaSharp, significantly expanding the application of LLamaSharp. Though llama.cpp is still the only backend of LLamaSharp, the goal of this repository is more likely to be an efficient and easy-to-use library of LLM inference, rather than just a binding of llama.cpp. -If you want to support cublas in the compilation, please make sure that you've installed the cuda. +In this way, our development of LLamaSharp is divided into two main directions: -When building from source, please add `-DBUILD_SHARED_LIBS=ON` to the cmake instruction. For example, when building with cublas but without openblas, use the following instruction: +1. To make LLamaSharp more efficient. For example, `BatchedExecutor` could accept multiple queries and generate the response for them at the same time, which significantly improves the throughput. This part is always related with native APIs and executors in LLamaSharp. +2. To make it easier to use LLamaSharp. We believe the best library is to let users build powerful functionalities with simple code. Higher-level APIs and integrations with other libraries are the key points of it. + + +## How to compile the native library from source + +If you want to contribute to the first direction of our goal, you may need to compile the native library yourself. + +Firstly, please follow the instructions in [llama.cpp readme](https://github.com/ggerganov/llama.cpp#build) to configure your local environment. Most importantly, CMake with version higher than 3.14 should be installed on your device. + +Secondly, clone the llama.cpp repositories. You could manually clone it and checkout to the right commit according to [Map of LLamaSharp and llama.cpp versions](https://github.com/SciSharp/LLamaSharp?tab=readme-ov-file#map-of-llamasharp-and-llama.cpp-versions), or use clone the submodule of LLamaSharp when cloning LLamaSharp. + +```shell +git clone --recursive https://github.com/SciSharp/LLamaSharp.git +``` + +If you want to support cublas in the compilation, please make sure that you've installed it. If you are using Intel CPU, please check the highest AVX ([Advanced Vector Extensions](https://en.wikipedia.org/wiki/Advanced_Vector_Extensions)) level that is supported by your device. + +As shown in [llama.cpp cmake file](https://github.com/ggerganov/llama.cpp/blob/master/CMakeLists.txt), there are many options that could be enabled or disabled when building the library. The following ones are commonly used when using it as a native library of LLamaSharp. + +```cpp +option(BUILD_SHARED_LIBS "build shared libraries") // Please always enable it +option(LLAMA_NATIVE "llama: enable -march=native flag") // Could be disabled +option(LLAMA_AVX "llama: enable AVX") // Enable it if the highest supported avx level is AVX +option(LLAMA_AVX2 "llama: enable AVX2") // Enable it if the highest supported avx level is AVX2 +option(LLAMA_AVX512 "llama: enable AVX512") // Enable it if the highest supported avx level is AVX512 +option(LLAMA_BLAS "llama: use BLAS") // Enable it if you want to use BLAS library to acclerate the computation on CPU +option(LLAMA_CUDA "llama: use CUDA") // Enable it if you have CUDA device +option(LLAMA_CLBLAST "llama: use CLBlast") // Enable it if you have a device with CLBLast or OpenCL support, for example, some AMD GPUs. +option(LLAMA_VULKAN "llama: use Vulkan") // Enable it if you have a device with Vulkan support +option(LLAMA_METAL "llama: use Metal") // Enable it if you are using a MAC with Metal device. +option(LLAMA_BUILD_TESTS "llama: build tests") // Please disable it. +option(LLAMA_BUILD_EXAMPLES "llama: build examples") // Please disable it. +option(LLAMA_BUILD_SERVER "llama: build server example")// Please disable it. +``` + +Most importantly, `-DBUILD_SHARED_LIBS=ON` must be added to the cmake instruction and other options depends on you. For example, when building with cublas but without openblas, use the following instruction: ```bash +mkdir build && cd build cmake .. -DLLAMA_CUBLAS=ON -DBUILD_SHARED_LIBS=ON +cmake --build . --config Release ``` -After running `cmake --build . --config Release`, you could find the `llama.dll`, `llama.so` or `llama.dylib` in your build directory. After pasting it to `LLamaSharp/LLama/runtimes` you can use it as the native library in LLamaSharp. +Now you could find the `llama.dll`, `libllama.so` or `llama.dylib` in your build directory (or `build/bin`). + +To load the compiled native library, please add the following code to the very beginning of your code. + +```cs +NativeLibraryConfig.Instance.WithLibrary(""); +``` ## Add a new feature to LLamaSharp @@ -39,19 +83,19 @@ You could use exactly the same prompt, the same model and the same parameters to If the experiment showed that it worked well in llama.cpp but didn't in LLamaSharp, a search for the problem could be started. While the reason of the problem could be various, the best way I think is to add log-print in the code of llama.cpp and use it in LLamaSharp after compilation. Thus, when running LLamaSharp, you could see what happened in the native library. -After finding out the reason, a painful but happy process comes. When working on the BUG fix, there's only one rule to follow, that is keeping the examples working well. If the modification fixed the BUG but impact on other functions, it would not be a good fix. - -During the BUG fix process, please don't hesitate to discuss together when you stuck on something. +During the BUG fix process, please don't hesitate to discuss together when you are blocked. ## Add integrations -All kinds of integration are welcomed here! Currently the following integrations are under work or on our schedule: +All kinds of integration are welcomed here! Currently the following integrations have been added but still need improvement: + +1. semantic-kernel +2. kernel-memory +3. BotSharp (maintained in SciSharp/BotSharp repo) +4. Langchain (maintained in tryAGI/LangChain repo) -1. BotSharp -2. semantic-kernel -3. Unity +If you find another library that is good to be integrated, please open an issue to let us know! -Besides, for some other integrations, like `ASP.NET core`, `SQL`, `Blazor` and so on, we'll appreciate it if you could help with that. If the time is limited for you, providing an example for it also means a lot! ## Add examples diff --git a/LLama.KernelMemory/LLamaSharp.KernelMemory.csproj b/LLama.KernelMemory/LLamaSharp.KernelMemory.csproj index b32c0619..9b4d7172 100644 --- a/LLama.KernelMemory/LLamaSharp.KernelMemory.csproj +++ b/LLama.KernelMemory/LLamaSharp.KernelMemory.csproj @@ -4,7 +4,7 @@ net6.0;net7.0;net8.0 enable enable - 0.8.0 + 0.11.0 Xbotter SciSharp STACK true @@ -17,7 +17,7 @@ The integration of LLamaSharp and Microsoft kernel-memory. It could make it easy to support document search for LLamaSharp model inference. - Support integration with kernel-memory + v0.11.0 updated the kernel-memory package and Fixed System.ArgumentException: EmbeddingMode must be true. MIT packages diff --git a/LLama.SemanticKernel/LLamaSharp.SemanticKernel.csproj b/LLama.SemanticKernel/LLamaSharp.SemanticKernel.csproj index 80b2e2cc..8f311141 100644 --- a/LLama.SemanticKernel/LLamaSharp.SemanticKernel.csproj +++ b/LLama.SemanticKernel/LLamaSharp.SemanticKernel.csproj @@ -10,7 +10,7 @@ enable enable - 0.8.0 + 0.11.0 Tim Miller, Xbotter SciSharp STACK true @@ -23,7 +23,7 @@ The integration of LLamaSharp and Microsoft semantic-kernel. - Support integration with semantic-kernel + v0.11.0 updates the semantic-kernel package. MIT packages diff --git a/LLama/LLamaSharp.csproj b/LLama/LLamaSharp.csproj index a7980600..5e3ffb73 100644 --- a/LLama/LLamaSharp.csproj +++ b/LLama/LLamaSharp.csproj @@ -7,8 +7,8 @@ AnyCPU;x64;Arm64 True - 0.10.0 - Yaohui Liu, Martin Evans, Haiping Chen + 0.11.0 + Rinne, Martin Evans, jlsantiago and all the other contributors in https://github.com/SciSharp/LLamaSharp/graphs/contributors. SciSharp STACK true MIT, SciSharp STACK $([System.DateTime]::UtcNow.ToString(yyyy)) @@ -17,11 +17,12 @@ https://avatars3.githubusercontent.com/u/44989469?s=200&v=4 LLama, LLM, GPT, ChatGPT, NLP, AI, Chat Bot, SciSharp - The .NET binding of LLama.cpp, making LLM inference and deployment easy and fast. For model - weights to run, please go to https://github.com/SciSharp/LLamaSharp for more information. + LLamaSharp is a cross-platform library to run 🦙LLaMA/LLaVA model (and others) in your local device. + Based on [llama.cpp](https://github.com/ggerganov/llama.cpp), inference with LLamaSharp is efficient on both CPU and GPU. + With the higher-level APIs and RAG support, it's convenient to deploy LLM (Large Language Model) in your application with LLamaSharp. - LLamaSharp 0.10.0 supports automatically device feature detection, adds integration with kernel-memory and fixes some performance issues. + LLamaSharp 0.11.0 added support for multi-modal (LLaVA), improved the BatchedExecutor and added state management of `ChatSession`. MIT packages diff --git a/README.md b/README.md index efb7385a..ce722019 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [![LLamaSharp Badge](https://img.shields.io/nuget/v/LLamaSharp.Backend.OpenCL?label=LLamaSharp.Backend.OpenCL)](https://www.nuget.org/packages/LLamaSharp.Backend.OpenCL) -**LLamaSharp is a cross-platform library to run 🦙LLaMA/LLaVA model (and others) in local device. Based on [llama.cpp](https://github.com/ggerganov/llama.cpp), inference with LLamaSharp is efficient on both CPU and GPU. With the higher-level APIs and RAG support, it's convenient to deploy LLM (Large Language Model) in your application with LLamaSharp.** +**LLamaSharp is a cross-platform library to run 🦙LLaMA/LLaVA model (and others) in your local device. Based on [llama.cpp](https://github.com/ggerganov/llama.cpp), inference with LLamaSharp is efficient on both CPU and GPU. With the higher-level APIs and RAG support, it's convenient to deploy LLM (Large Language Model) in your application with LLamaSharp.** **Please star the repo to show your support for this project!🤗** @@ -199,7 +199,7 @@ Please set anti-prompt or max-length when executing the inference. ## Contributing -Any contribution is welcomed! There's a TODO list in [LLamaSharp Dev Project](https://github.com/orgs/SciSharp/projects/5) and you could pick an interesting one to start. Please read the [contributing guide](https://scisharp.github.io/LLamaSharp/latest/ContributingGuide/) for more information. +Any contribution is welcomed! There's a TODO list in [LLamaSharp Dev Project](https://github.com/orgs/SciSharp/projects/5) and you could pick an interesting one to start. Please read the [contributing guide](./CONTRIBUTING.md) for more information. You can also do one of the followings to help us make LLamaSharp better: @@ -232,6 +232,7 @@ If you want to compile llama.cpp yourself you **must** use the exact commit ID l | v0.8.1 | | [`e937066`](https://github.com/ggerganov/llama.cpp/commit/e937066420b79a757bf80e9836eb12b88420a218) | | v0.9.0, v0.9.1 | [Mixtral-8x7B](https://huggingface.co/TheBloke/Mixtral-8x7B-v0.1-GGUF) | [`9fb13f9`](https://github.com/ggerganov/llama.cpp/blob/9fb13f95840c722ad419f390dc8a9c86080a3700) | | v0.10.0 | [Phi2](https://huggingface.co/TheBloke/phi-2-GGUF) | [`d71ac90`](https://github.com/ggerganov/llama.cpp/tree/d71ac90985854b0905e1abba778e407e17f9f887) | +| v0.11.0 | [LLaVA-v1.6](https://huggingface.co/ShadowBeast/llava-v1.6-mistral-7b-Q5_K_S-GGUF), [Phi2](https://huggingface.co/TheBloke/phi-2-GGUF)| [`3ab8b3a`](3ab8b3a92ede46df88bc5a2dfca3777de4a2b2b6) | ## License