Skip to content

Commit

Permalink
Merge pull request #672 from SignalRT/master
Browse files Browse the repository at this point in the history
Reintroduce MacOS on CI
  • Loading branch information
SignalRT authored Apr 19, 2024
2 parents 3c76440 + df9a549 commit 8f358e1
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 16 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ jobs:
strategy:
fail-fast: false
matrix:
build: [linux-release, windows-release]
build: [linux-release, windows-release, osx-release]
include:
- build: linux-release
os: ubuntu-latest
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
os: windows-2019
config: release
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
7.0.x
dotnet-version: |
8.0.x
- name: Cache Packages
uses: actions/cache@v4
Expand All @@ -43,7 +45,7 @@ jobs:
- name: Build
run: dotnet build LLamaSharp.sln -c ${{ matrix.config }} --no-restore
- 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
if: always()
uses: actions/upload-artifact@v3
Expand Down
3 changes: 2 additions & 1 deletion LLama.Unittest/BasicTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public BasicTest(ITestOutputHelper testOutputHelper)
_testOutputHelper = testOutputHelper;
_params = new ModelParams(Constants.GenerativeModelPath)
{
ContextSize = 2048
ContextSize = 2048,
GpuLayerCount = Constants.CIGpuLayerCount
};
_model = LLamaWeights.LoadFromFile(_params);
}
Expand Down
4 changes: 2 additions & 2 deletions LLama.Unittest/BeamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public BeamTests(ITestOutputHelper testOutputHelper)
_testOutputHelper = testOutputHelper;
_params = new ModelParams(Constants.GenerativeModelPath)
{
ContextSize = 2048
ContextSize = 2048,
GpuLayerCount = Constants.CIGpuLayerCount,
};
_model = LLamaWeights.LoadFromFile(_params);
}
Expand All @@ -27,7 +28,6 @@ public void Dispose()
_model.Dispose();
}

//[Fact(Skip = "Very very slow in CI")]
[Fact]
public void BasicBeam()
{
Expand Down
24 changes: 23 additions & 1 deletion LLama.Unittest/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace LLama.Unittest
using System.Runtime.InteropServices;

namespace LLama.Unittest
{
internal static class Constants
{
Expand All @@ -8,5 +10,25 @@ internal static class Constants
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 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;
}
}
}
}
1 change: 1 addition & 0 deletions LLama.Unittest/GrammarTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public GrammarTest()
{
ContextSize = 2048,
Seed = 92,
GpuLayerCount = Constants.CIGpuLayerCount,
};
_model = LLamaWeights.LoadFromFile(_params);
}
Expand Down
1 change: 1 addition & 0 deletions LLama.Unittest/LLamaContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public LLamaContextTests()
var @params = new ModelParams(Constants.GenerativeModelPath)
{
ContextSize = 768,
GpuLayerCount = Constants.CIGpuLayerCount,
};
_weights = LLamaWeights.LoadFromFile(@params);
_context = _weights.CreateContext(@params);
Expand Down
18 changes: 16 additions & 2 deletions LLama.Unittest/LLamaEmbedderTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LLama.Common;
using LLama.Common;
using Xunit.Abstractions;

namespace LLama.Unittest;
Expand All @@ -10,7 +10,21 @@ public sealed class LLamaEmbedderTests
public LLamaEmbedderTests(ITestOutputHelper 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);

Check failure on line 22 in LLama.Unittest/LLamaEmbedderTests.cs

View workflow job for this annotation

GitHub Actions / Test (osx-release)

The name '_embedder' does not exist in the current context

Check failure on line 22 in LLama.Unittest/LLamaEmbedderTests.cs

View workflow job for this annotation

GitHub Actions / Test (osx-release)

The name '_embedder' does not exist in the current context

Check failure on line 22 in LLama.Unittest/LLamaEmbedderTests.cs

View workflow job for this annotation

GitHub Actions / Test (linux-release)

The name '_embedder' does not exist in the current context

Check failure on line 22 in LLama.Unittest/LLamaEmbedderTests.cs

View workflow job for this annotation

GitHub Actions / Test (linux-release)

The name '_embedder' does not exist in the current context

Check failure on line 22 in LLama.Unittest/LLamaEmbedderTests.cs

View workflow job for this annotation

GitHub Actions / Test (windows-release)

The name '_embedder' does not exist in the current context

Check failure on line 22 in LLama.Unittest/LLamaEmbedderTests.cs

View workflow job for this annotation

GitHub Actions / Test (windows-release)

The name '_embedder' does not exist in the current context
}

public void Dispose()
{
_embedder.Dispose();

Check failure on line 27 in LLama.Unittest/LLamaEmbedderTests.cs

View workflow job for this annotation

GitHub Actions / Test (osx-release)

The name '_embedder' does not exist in the current context

Check failure on line 27 in LLama.Unittest/LLamaEmbedderTests.cs

View workflow job for this annotation

GitHub Actions / Test (osx-release)

The name '_embedder' does not exist in the current context

Check failure on line 27 in LLama.Unittest/LLamaEmbedderTests.cs

View workflow job for this annotation

GitHub Actions / Test (linux-release)

The name '_embedder' does not exist in the current context

Check failure on line 27 in LLama.Unittest/LLamaEmbedderTests.cs

View workflow job for this annotation

GitHub Actions / Test (linux-release)

The name '_embedder' does not exist in the current context

Check failure on line 27 in LLama.Unittest/LLamaEmbedderTests.cs

View workflow job for this annotation

GitHub Actions / Test (windows-release)

The name '_embedder' does not exist in the current context

Check failure on line 27 in LLama.Unittest/LLamaEmbedderTests.cs

View workflow job for this annotation

GitHub Actions / Test (windows-release)

The name '_embedder' does not exist in the current context
}

private static float Dot(float[] a, float[] b)
Expand Down
7 changes: 4 additions & 3 deletions LLama.Unittest/LLavaWeightsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public LLavaWeightTests()
var @params = new ModelParams(Constants.GenerativeModelPath)
{
// Llava models requires big context
ContextSize = 4096
ContextSize = 4096,
GpuLayerCount = Constants.CIGpuLayerCount,
};
_llamaWeights = LLamaWeights.LoadFromFile(@params);
_lLavaWeights = LLavaWeights.LoadFromFile(Constants.LLavaMmpPath);
Expand All @@ -32,15 +33,15 @@ public void Dispose()
_lLavaWeights.Dispose();
}

[Fact(Skip = "Very very slow in CI")]
[Fact,Trait("Category", "NoCI")]
public void EmbedImageAsFileName()
{
int n_past = 0;
SafeLlavaImageEmbedHandle emb = _lLavaWeights.CreateImageEmbeddings(_context, Constants.LLavaImage);
Assert.True( _lLavaWeights.EvalImageEmbed( _context, emb, ref n_past ) );
}

[Fact(Skip = "Very very slow in CI")]
[Fact,Trait("Category", "NoCI")]
public void EmbedImageAsBinary()
{
int n_past = 0;
Expand Down
6 changes: 4 additions & 2 deletions LLama.Unittest/MemoryDisposalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public void ModelDisposal()
{
var @params = new ModelParams(Constants.GenerativeModelPath)
{
ContextSize = 2048
ContextSize = 2048,
GpuLayerCount = 0,
};
var model = LLamaWeights.LoadFromFile(@params);

Expand All @@ -23,7 +24,8 @@ public void ContextDisposal()
{
var @params = new ModelParams(Constants.GenerativeModelPath)
{
ContextSize = 2048
ContextSize = 2048,
GpuLayerCount = Constants.CIGpuLayerCount,
};
var model = LLamaWeights.LoadFromFile(@params);

Expand Down
1 change: 1 addition & 0 deletions LLama.Unittest/StatelessExecutorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public StatelessExecutorTest(ITestOutputHelper testOutputHelper)
ContextSize = 60,
Seed = 1754,
BatchSize = 2,
GpuLayerCount = Constants.CIGpuLayerCount,
};
_weights = LLamaWeights.LoadFromFile(_params);
}
Expand Down
3 changes: 2 additions & 1 deletion LLama.Unittest/TokenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public TokenTests()
{
_params = new ModelParams(Constants.GenerativeModelPath)
{
ContextSize = 2048
ContextSize = 2048,
GpuLayerCount = Constants.CIGpuLayerCount,
};
_model = LLamaWeights.LoadFromFile(_params);
}
Expand Down

0 comments on commit 8f358e1

Please sign in to comment.