From ccf635e4db70da0bfe96b8118a83eb092d443b62 Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Sun, 30 Jul 2023 00:24:08 +0100 Subject: [PATCH 1/8] Added GH action for some simple CI --- .github/workflows/main.yml | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..f8204697 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,48 @@ +name: CI +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + build: + name: Test + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + build: [linux-debug, linux-release, macos-debug, macos-release, windows-debug, windows-release] + include: + - build: linux-debug + os: ubuntu-latest + config: debug + - build: linux-release + os: ubuntu-latest + config: release + - build: macos-debug + os: macos-latest + config: debug + - build: macos-release + os: macos-latest + config: release + - build: windows-debug + os: windows-2019 + config: debug + - build: windows-release + os: windows-2019 + config: release + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-dotnet@v1 + with: + dotnet-version: '7.0.x' + # workaround for actions/setup-dotnet#155 + - name: Clear package cache + run: dotnet clean LlamaSharp.sln && dotnet nuget locals all --clear + - name: Restore packages + run: dotnet restore LlamaSharp.sln + - name: Build + run: dotnet build LlamaSharp.sln -c ${{ matrix.config }} --no-restore + - name: Test + run: dotnet test LlamaSharp.sln -c ${{ matrix.config }} From e7e3df6c6b732fc80d9bad15e557ff0fa52ceeba Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Sun, 30 Jul 2023 00:34:32 +0100 Subject: [PATCH 2/8] fixed capitalisation --- .github/workflows/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f8204697..ded0afb1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,10 +39,10 @@ jobs: dotnet-version: '7.0.x' # workaround for actions/setup-dotnet#155 - name: Clear package cache - run: dotnet clean LlamaSharp.sln && dotnet nuget locals all --clear + run: dotnet clean LLamaSharp.sln && dotnet nuget locals all --clear - name: Restore packages - run: dotnet restore LlamaSharp.sln + run: dotnet restore LLamaSharp.sln - name: Build - run: dotnet build LlamaSharp.sln -c ${{ matrix.config }} --no-restore + run: dotnet build LLamaSharp.sln -c ${{ matrix.config }} --no-restore - name: Test - run: dotnet test LlamaSharp.sln -c ${{ matrix.config }} + run: dotnet test LLamaSharp.sln -c ${{ matrix.config }} From 7ef07104e77d2b8cd6965955a95714b88812c478 Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Sun, 30 Jul 2023 00:38:32 +0100 Subject: [PATCH 3/8] Added queue fix, so that CI can pass --- LLama/Common/FixedSizeQueue.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LLama/Common/FixedSizeQueue.cs b/LLama/Common/FixedSizeQueue.cs index e059ef70..4b082feb 100644 --- a/LLama/Common/FixedSizeQueue.cs +++ b/LLama/Common/FixedSizeQueue.cs @@ -30,9 +30,11 @@ namespace LLama.Common /// public FixedSizeQueue(int size, IEnumerable data) { +#if NETCOREAPP3_0_OR_GREATER // Try an early check on the amount of data supplied (if possible) if (data.TryGetNonEnumeratedCount(out var count) && count > size) throw new ArgumentException($"The max size set for the quene is {size}, but got {count} initial values."); +#endif // Size of "data" is unknown, copy it all into a list _maxSize = size; @@ -40,7 +42,7 @@ namespace LLama.Common // Now check if that list is a valid size if (_storage.Count > _maxSize) - throw new ArgumentException($"The max size set for the quene is {size}, but got {count} initial values."); + throw new ArgumentException($"The max size set for the quene is {size}, but got {_storage.Count} initial values."); } /// From 618e02fb9cea2b956b493a5f35df1e653a3a4c4a Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Sun, 30 Jul 2023 00:43:21 +0100 Subject: [PATCH 4/8] - moved dotnet version into matrix - using 6.0.x instead of 7.0.x --- .github/workflows/main.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ded0afb1..bbd55d86 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,26 +17,32 @@ jobs: - build: linux-debug os: ubuntu-latest config: debug + dotnet: 6.0.x - build: linux-release os: ubuntu-latest config: release + dotnet: 6.0.x - build: macos-debug os: macos-latest config: debug + dotnet: 6.0.x - build: macos-release os: macos-latest config: release + dotnet: 6.0.x - build: windows-debug os: windows-2019 config: debug + dotnet: 6.0.x - build: windows-release os: windows-2019 config: release + dotnet: 6.0.x steps: - uses: actions/checkout@v2 - uses: actions/setup-dotnet@v1 with: - dotnet-version: '7.0.x' + dotnet-version: ${{ matrix.dotnet }} # workaround for actions/setup-dotnet#155 - name: Clear package cache run: dotnet clean LLamaSharp.sln && dotnet nuget locals all --clear From 71b1ccd2f7b97d17f0eb7c7bb8712520fa6af1d4 Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Sun, 30 Jul 2023 00:47:00 +0100 Subject: [PATCH 5/8] Always installing both 6 and 7 --- .github/workflows/main.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bbd55d86..9c1fdb1e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,32 +17,29 @@ jobs: - build: linux-debug os: ubuntu-latest config: debug - dotnet: 6.0.x - build: linux-release os: ubuntu-latest config: release - dotnet: 6.0.x - build: macos-debug os: macos-latest config: debug - dotnet: 6.0.x - build: macos-release os: macos-latest config: release - dotnet: 6.0.x - build: windows-debug os: windows-2019 config: debug - dotnet: 6.0.x - build: windows-release os: windows-2019 config: release - dotnet: 6.0.x steps: - uses: actions/checkout@v2 - uses: actions/setup-dotnet@v1 with: - dotnet-version: ${{ matrix.dotnet }} + dotnet-version: 6.0.x + - uses: actions/setup-dotnet@v1 + with: + dotnet-version: 7.0.x # workaround for actions/setup-dotnet#155 - name: Clear package cache run: dotnet clean LLamaSharp.sln && dotnet nuget locals all --clear From 1545b821d7a9fd2a2bd9d1c6c2e540883f3dc89c Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Sun, 30 Jul 2023 00:49:55 +0100 Subject: [PATCH 6/8] Cleaned up installing multiple dotnets --- .github/workflows/main.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9c1fdb1e..08ca74db 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,11 +35,10 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 6.0.x - - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 7.0.x + with: + dotnet-version: | + 6.0.x + 7.0.x # workaround for actions/setup-dotnet#155 - name: Clear package cache run: dotnet clean LLamaSharp.sln && dotnet nuget locals all --clear From c46751ae662a0a8359628763d4f35aa2d27bc096 Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Sun, 30 Jul 2023 00:52:08 +0100 Subject: [PATCH 7/8] Fixed yaml syntax --- .github/workflows/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 08ca74db..2a0407bd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,10 +35,10 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: | - 6.0.x - 7.0.x + with: + dotnet-version: | + 6.0.x + 7.0.x # workaround for actions/setup-dotnet#155 - name: Clear package cache run: dotnet clean LLamaSharp.sln && dotnet nuget locals all --clear From d6fc83e9814c7a85dd676f838105b11f1c8ad203 Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Sun, 30 Jul 2023 19:44:47 +0100 Subject: [PATCH 8/8] - Added a folder with a 7B Llama2 model, automatically downloaded from huggingface. This can be used for unit tests. - Caching that folder, so CI only has to download it once. --- .github/workflows/main.yml | 5 +++++ .gitignore | 3 ++- LLama.Unittest/BasicTest.cs | 7 +++++-- LLama.Unittest/LLama.Unittest.csproj | 15 +++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2a0407bd..b00368fb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,6 +39,11 @@ jobs: dotnet-version: | 6.0.x 7.0.x + - name: Cache Gradle packages + uses: actions/cache@v3 + with: + key: "unit_test_models" + path: LLama.Unittest/Models # workaround for actions/setup-dotnet#155 - name: Clear package cache run: dotnet clean LLamaSharp.sln && dotnet nuget locals all --clear diff --git a/.gitignore b/.gitignore index d1d0ba40..2f38fac0 100644 --- a/.gitignore +++ b/.gitignore @@ -341,4 +341,5 @@ test/TensorFlowNET.Examples/mnist *.xsd # docs -site/ \ No newline at end of file +site/ +/LLama.Unittest/Models/*.bin diff --git a/LLama.Unittest/BasicTest.cs b/LLama.Unittest/BasicTest.cs index 29178432..fd602cf0 100644 --- a/LLama.Unittest/BasicTest.cs +++ b/LLama.Unittest/BasicTest.cs @@ -1,11 +1,14 @@ +using LLama.Common; + namespace LLama.Unittest { public class BasicTest { [Fact] - public void SimpleQA() + public void LoadModel() { - + var model = new LLamaModel(new ModelParams("Models/llama-2-7b-chat.ggmlv3.q3_K_S.bin", contextSize: 256)); + model.Dispose(); } } } \ No newline at end of file diff --git a/LLama.Unittest/LLama.Unittest.csproj b/LLama.Unittest/LLama.Unittest.csproj index 93922e81..65dbd161 100644 --- a/LLama.Unittest/LLama.Unittest.csproj +++ b/LLama.Unittest/LLama.Unittest.csproj @@ -23,8 +23,23 @@ + + + + + + + + + + + + PreserveNewest + + +