| @@ -15,11 +15,14 @@ jobs: | |||||
| strategy: | strategy: | ||||
| fail-fast: false | fail-fast: false | ||||
| matrix: | matrix: | ||||
| build: [linux-release, windows-release] | |||||
| build: [linux-release, windows-release, osx-release] | |||||
| include: | include: | ||||
| - build: linux-release | - build: linux-release | ||||
| os: ubuntu-latest | os: ubuntu-latest | ||||
| config: release | config: release | ||||
| - build: osx-release | |||||
| os: macos-14 # https://github.blog/changelog/2024-01-30-github-actions-introducing-the-new-m1-macos-runner-available-to-open-source/ | |||||
| config: release | |||||
| - build: windows-release | - build: windows-release | ||||
| os: windows-2019 | os: windows-2019 | ||||
| config: release | config: release | ||||
| @@ -27,8 +30,7 @@ jobs: | |||||
| - uses: actions/checkout@v4 | - uses: actions/checkout@v4 | ||||
| - uses: actions/setup-dotnet@v4 | - uses: actions/setup-dotnet@v4 | ||||
| with: | with: | ||||
| dotnet-version: | | |||||
| 7.0.x | |||||
| dotnet-version: | | |||||
| 8.0.x | 8.0.x | ||||
| - name: Cache Packages | - name: Cache Packages | ||||
| uses: actions/cache@v4 | uses: actions/cache@v4 | ||||
| @@ -43,7 +45,7 @@ jobs: | |||||
| - name: Build | - name: Build | ||||
| run: dotnet build LLamaSharp.sln -c ${{ matrix.config }} --no-restore | run: dotnet build LLamaSharp.sln -c ${{ matrix.config }} --no-restore | ||||
| - name: Test | - name: Test | ||||
| run: dotnet test LLamaSharp.sln -c ${{ matrix.config }} -l "console;verbosity=detailed" --diag:logs/log.txt | |||||
| run: dotnet test LLamaSharp.sln -c ${{ matrix.config }} -l "console;verbosity=detailed" --diag:logs/log.txt --filter Category!=NoCI | |||||
| - name: Upload artifacts | - name: Upload artifacts | ||||
| if: always() | if: always() | ||||
| uses: actions/upload-artifact@v3 | uses: actions/upload-artifact@v3 | ||||
| @@ -17,7 +17,8 @@ namespace LLama.Unittest | |||||
| _testOutputHelper = testOutputHelper; | _testOutputHelper = testOutputHelper; | ||||
| _params = new ModelParams(Constants.GenerativeModelPath) | _params = new ModelParams(Constants.GenerativeModelPath) | ||||
| { | { | ||||
| ContextSize = 2048 | |||||
| ContextSize = 2048, | |||||
| GpuLayerCount = Constants.CIGpuLayerCount | |||||
| }; | }; | ||||
| _model = LLamaWeights.LoadFromFile(_params); | _model = LLamaWeights.LoadFromFile(_params); | ||||
| } | } | ||||
| @@ -17,7 +17,8 @@ public sealed class BeamTests | |||||
| _testOutputHelper = testOutputHelper; | _testOutputHelper = testOutputHelper; | ||||
| _params = new ModelParams(Constants.GenerativeModelPath) | _params = new ModelParams(Constants.GenerativeModelPath) | ||||
| { | { | ||||
| ContextSize = 2048 | |||||
| ContextSize = 2048, | |||||
| GpuLayerCount = Constants.CIGpuLayerCount, | |||||
| }; | }; | ||||
| _model = LLamaWeights.LoadFromFile(_params); | _model = LLamaWeights.LoadFromFile(_params); | ||||
| } | } | ||||
| @@ -27,7 +28,6 @@ public sealed class BeamTests | |||||
| _model.Dispose(); | _model.Dispose(); | ||||
| } | } | ||||
| //[Fact(Skip = "Very very slow in CI")] | |||||
| [Fact] | [Fact] | ||||
| public void BasicBeam() | public void BasicBeam() | ||||
| { | { | ||||
| @@ -1,4 +1,6 @@ | |||||
| namespace LLama.Unittest | |||||
| using System.Runtime.InteropServices; | |||||
| namespace LLama.Unittest | |||||
| { | { | ||||
| internal static class Constants | internal static class Constants | ||||
| { | { | ||||
| @@ -8,5 +10,25 @@ | |||||
| public static readonly string LLavaModelPath = "Models/llava-v1.6-mistral-7b.Q3_K_XS.gguf"; | public static readonly string LLavaModelPath = "Models/llava-v1.6-mistral-7b.Q3_K_XS.gguf"; | ||||
| public static readonly string LLavaMmpPath = "Models/mmproj-model-f16.gguf"; | public static readonly string LLavaMmpPath = "Models/mmproj-model-f16.gguf"; | ||||
| public static readonly string LLavaImage = "Models/extreme-ironing-taxi-610x427.jpg"; | public static readonly string LLavaImage = "Models/extreme-ironing-taxi-610x427.jpg"; | ||||
| /// <summary> | |||||
| /// Calculate GpuLayer Count to use in UnitTest | |||||
| /// </summary> | |||||
| /// <returns> Defaults to 20 in all the cases, except MacOS/OSX release (to disable METAL on github CI)</returns> | |||||
| public static int CIGpuLayerCount | |||||
| { | |||||
| get | |||||
| { | |||||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | |||||
| { | |||||
| #if DEBUG | |||||
| return 20; | |||||
| #else | |||||
| return 0; | |||||
| #endif | |||||
| } | |||||
| else return 20; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -16,6 +16,7 @@ namespace LLama.Unittest | |||||
| { | { | ||||
| ContextSize = 2048, | ContextSize = 2048, | ||||
| Seed = 92, | Seed = 92, | ||||
| GpuLayerCount = Constants.CIGpuLayerCount, | |||||
| }; | }; | ||||
| _model = LLamaWeights.LoadFromFile(_params); | _model = LLamaWeights.LoadFromFile(_params); | ||||
| } | } | ||||
| @@ -14,6 +14,7 @@ namespace LLama.Unittest | |||||
| var @params = new ModelParams(Constants.GenerativeModelPath) | var @params = new ModelParams(Constants.GenerativeModelPath) | ||||
| { | { | ||||
| ContextSize = 768, | ContextSize = 768, | ||||
| GpuLayerCount = Constants.CIGpuLayerCount, | |||||
| }; | }; | ||||
| _weights = LLamaWeights.LoadFromFile(@params); | _weights = LLamaWeights.LoadFromFile(@params); | ||||
| _context = _weights.CreateContext(@params); | _context = _weights.CreateContext(@params); | ||||
| @@ -1,4 +1,4 @@ | |||||
| using LLama.Common; | |||||
| using LLama.Common; | |||||
| using Xunit.Abstractions; | using Xunit.Abstractions; | ||||
| namespace LLama.Unittest; | namespace LLama.Unittest; | ||||
| @@ -10,7 +10,21 @@ public sealed class LLamaEmbedderTests | |||||
| public LLamaEmbedderTests(ITestOutputHelper testOutputHelper) | public LLamaEmbedderTests(ITestOutputHelper testOutputHelper) | ||||
| { | { | ||||
| _testOutputHelper = testOutputHelper; | _testOutputHelper = testOutputHelper; | ||||
| var @params = new ModelParams(Constants.EmbeddingModelPath) | |||||
| { | |||||
| ContextSize = 4096, | |||||
| Threads = 5, | |||||
| Embeddings = true, | |||||
| GpuLayerCount = Constants.CIGpuLayerCount, | |||||
| }; | |||||
| using var weights = LLamaWeights.LoadFromFile(@params); | |||||
| _embedder = new(weights, @params); | |||||
| } | |||||
| public void Dispose() | |||||
| { | |||||
| _embedder.Dispose(); | |||||
| } | } | ||||
| private static float Dot(float[] a, float[] b) | private static float Dot(float[] a, float[] b) | ||||
| @@ -17,7 +17,8 @@ namespace LLama.Unittest | |||||
| var @params = new ModelParams(Constants.GenerativeModelPath) | var @params = new ModelParams(Constants.GenerativeModelPath) | ||||
| { | { | ||||
| // Llava models requires big context | // Llava models requires big context | ||||
| ContextSize = 4096 | |||||
| ContextSize = 4096, | |||||
| GpuLayerCount = Constants.CIGpuLayerCount, | |||||
| }; | }; | ||||
| _llamaWeights = LLamaWeights.LoadFromFile(@params); | _llamaWeights = LLamaWeights.LoadFromFile(@params); | ||||
| _lLavaWeights = LLavaWeights.LoadFromFile(Constants.LLavaMmpPath); | _lLavaWeights = LLavaWeights.LoadFromFile(Constants.LLavaMmpPath); | ||||
| @@ -32,7 +33,7 @@ namespace LLama.Unittest | |||||
| _lLavaWeights.Dispose(); | _lLavaWeights.Dispose(); | ||||
| } | } | ||||
| [Fact(Skip = "Very very slow in CI")] | |||||
| [Fact,Trait("Category", "NoCI")] | |||||
| public void EmbedImageAsFileName() | public void EmbedImageAsFileName() | ||||
| { | { | ||||
| int n_past = 0; | int n_past = 0; | ||||
| @@ -40,7 +41,7 @@ namespace LLama.Unittest | |||||
| Assert.True( _lLavaWeights.EvalImageEmbed( _context, emb, ref n_past ) ); | Assert.True( _lLavaWeights.EvalImageEmbed( _context, emb, ref n_past ) ); | ||||
| } | } | ||||
| [Fact(Skip = "Very very slow in CI")] | |||||
| [Fact,Trait("Category", "NoCI")] | |||||
| public void EmbedImageAsBinary() | public void EmbedImageAsBinary() | ||||
| { | { | ||||
| int n_past = 0; | int n_past = 0; | ||||
| @@ -9,7 +9,8 @@ public class MemoryDisposalTests | |||||
| { | { | ||||
| var @params = new ModelParams(Constants.GenerativeModelPath) | var @params = new ModelParams(Constants.GenerativeModelPath) | ||||
| { | { | ||||
| ContextSize = 2048 | |||||
| ContextSize = 2048, | |||||
| GpuLayerCount = 0, | |||||
| }; | }; | ||||
| var model = LLamaWeights.LoadFromFile(@params); | var model = LLamaWeights.LoadFromFile(@params); | ||||
| @@ -23,7 +24,8 @@ public class MemoryDisposalTests | |||||
| { | { | ||||
| var @params = new ModelParams(Constants.GenerativeModelPath) | var @params = new ModelParams(Constants.GenerativeModelPath) | ||||
| { | { | ||||
| ContextSize = 2048 | |||||
| ContextSize = 2048, | |||||
| GpuLayerCount = Constants.CIGpuLayerCount, | |||||
| }; | }; | ||||
| var model = LLamaWeights.LoadFromFile(@params); | var model = LLamaWeights.LoadFromFile(@params); | ||||
| @@ -20,6 +20,7 @@ namespace LLama.Unittest | |||||
| ContextSize = 60, | ContextSize = 60, | ||||
| Seed = 1754, | Seed = 1754, | ||||
| BatchSize = 2, | BatchSize = 2, | ||||
| GpuLayerCount = Constants.CIGpuLayerCount, | |||||
| }; | }; | ||||
| _weights = LLamaWeights.LoadFromFile(_params); | _weights = LLamaWeights.LoadFromFile(_params); | ||||
| } | } | ||||
| @@ -14,7 +14,8 @@ public sealed class TokenTests | |||||
| { | { | ||||
| _params = new ModelParams(Constants.GenerativeModelPath) | _params = new ModelParams(Constants.GenerativeModelPath) | ||||
| { | { | ||||
| ContextSize = 2048 | |||||
| ContextSize = 2048, | |||||
| GpuLayerCount = Constants.CIGpuLayerCount, | |||||
| }; | }; | ||||
| _model = LLamaWeights.LoadFromFile(_params); | _model = LLamaWeights.LoadFromFile(_params); | ||||
| } | } | ||||