Skip to content
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

Fix C# phi-2 test #1050

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linux-cpu-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
run: |
export ORTGENAI_LOG_ORT_LIB=1
cd test/csharp
dotnet test /p:Configuration=Release /p:NativeBuildOutputDir="../../build/cpu/" /p:OrtLibDir="../../ort/lib/"
dotnet test /p:Configuration=Release /p:NativeBuildOutputDir="../../build/cpu/" /p:OrtLibDir="../../ort/lib/" --verbosity normal
- name: Run tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mac-cpu-arm64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
run: |
export ORTGENAI_LOG_ORT_LIB=1
cd test/csharp
dotnet test /p:Configuration=Release /p:NativeBuildOutputDir="../../build/cpu/osx-arm64"
dotnet test /p:Configuration=Release /p:NativeBuildOutputDir="../../build/cpu/osx-arm64" --verbosity normal
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This produces much better results in terms of test cases.

- name: Run tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/win-cpu-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
- name: Build the C# API and Run the C# Tests
run: |
cd test\csharp
dotnet test /p:NativeBuildOutputDir="$env:GITHUB_WORKSPACE\$env:binaryDir\Release" /p:OrtLibDir="$env:GITHUB_WORKSPACE\ort\lib"
dotnet test /p:NativeBuildOutputDir="$env:GITHUB_WORKSPACE\$env:binaryDir\Release" /p:OrtLibDir="$env:GITHUB_WORKSPACE\ort\lib" --verbosity normal
- name: Verify Build Artifacts
if: always()
Expand Down
38 changes: 17 additions & 21 deletions test/csharp/TestOnnxRuntimeGenAIAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,24 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.ML.OnnxRuntimeGenAI.Tests
{
public class TestsFixture : IDisposable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test-case level fixture doesn't work. Because after OgaShutdown is called, it can't recover and the entire test crashes.

public class OnnxRuntimeGenAITests
{
private OgaHandle _handle;
public TestsFixture()
{
_handle = new OgaHandle();
}
private readonly ITestOutputHelper output;

public void Dispose()
// From https://stackoverflow.com/a/47841442
private static string GetThisFilePath([CallerFilePath] string path = null)
{
_handle.Dispose();
return path;
}
}

public class OnnxRuntimeGenAITests : IClassFixture<TestsFixture>
{
private readonly ITestOutputHelper output;
private static readonly string _phi2Path = Path.GetFullPath(Path.Combine(
GetThisFilePath(),"../..", "test_models", "phi-2", "int4", "cpu"));

public OnnxRuntimeGenAITests(ITestOutputHelper o)
{
Expand All @@ -37,7 +33,7 @@ private class IgnoreOnModelAbsenceFact : FactAttribute
{
public IgnoreOnModelAbsenceFact()
{
string modelPath = Path.Combine(Directory.GetCurrentDirectory(), "test_models", "cpu", "phi-2");
string modelPath = _phi2Path;
bool exists = System.IO.Directory.Exists(modelPath);
if (!System.IO.Directory.Exists(modelPath))
{
Expand Down Expand Up @@ -125,7 +121,7 @@ public void TestTopKSearch()
float temp = 0.6f;
ulong maxLength = 20;

string modelPath = Path.Combine(Directory.GetCurrentDirectory(), "test_models", "cpu", "phi-2");
string modelPath = _phi2Path;
using (var model = new Model(modelPath))
{
Assert.NotNull(model);
Expand Down Expand Up @@ -167,7 +163,7 @@ public void TestTopPSearch()
float temp = 0.6f;
ulong maxLength = 20;

string modelPath = Path.Combine(Directory.GetCurrentDirectory(), "test_models", "cpu", "phi-2");
string modelPath = _phi2Path;
using (var model = new Model(modelPath))
{
Assert.NotNull(model);
Expand Down Expand Up @@ -210,7 +206,7 @@ public void TestTopKTopPSearch()
float temp = 0.6f;
ulong maxLength = 20;

string modelPath = Path.Combine(Directory.GetCurrentDirectory(), "test_models", "cpu", "phi-2");
string modelPath = _phi2Path;
using (var model = new Model(modelPath))
{
Assert.NotNull(model);
Expand Down Expand Up @@ -249,7 +245,7 @@ public void TestTopKTopPSearch()
[IgnoreOnModelAbsenceFact(DisplayName = "TestTokenizerBatchEncodeDecode")]
public void TestTokenizerBatchEncodeDecode()
{
string modelPath = Path.Combine(Directory.GetCurrentDirectory(), "test_models", "cpu", "phi-2");
string modelPath = _phi2Path;
using (var model = new Model(modelPath))
{
Assert.NotNull(model);
Expand Down Expand Up @@ -278,7 +274,7 @@ public void TestTokenizerBatchEncodeDecode()
[IgnoreOnModelAbsenceFact(DisplayName = "TestTokenizerBatchEncodeSingleDecode")]
public void TestTokenizerBatchEncodeSingleDecode()
{
string modelPath = Path.Combine(Directory.GetCurrentDirectory(), "test_models", "cpu", "phi-2");
string modelPath = _phi2Path;
using (var model = new Model(modelPath))
{
Assert.NotNull(model);
Expand Down Expand Up @@ -309,7 +305,7 @@ public void TestTokenizerBatchEncodeSingleDecode()
[IgnoreOnModelAbsenceFact(DisplayName = "TestTokenizerBatchEncodeStreamDecode")]
public void TestTokenizerBatchEncodeStreamDecode()
{
string modelPath = Path.Combine(Directory.GetCurrentDirectory(), "test_models", "cpu", "phi-2");
string modelPath = _phi2Path;
using (var model = new Model(modelPath))
{
Assert.NotNull(model);
Expand Down Expand Up @@ -345,7 +341,7 @@ public void TestTokenizerBatchEncodeStreamDecode()
[IgnoreOnModelAbsenceFact(DisplayName = "TestTokenizerSingleEncodeDecode")]
public void TestTokenizerSingleEncodeDecode()
{
string modelPath = Path.Combine(Directory.GetCurrentDirectory(), "test_models", "cpu", "phi-2");
string modelPath = _phi2Path;
using (var model = new Model(modelPath))
{
Assert.NotNull(model);
Expand All @@ -369,7 +365,7 @@ public void TestTokenizerSingleEncodeDecode()
[IgnoreOnModelAbsenceFact(DisplayName = "TestPhi2")]
public void TestPhi2()
{
string modelPath = Path.Combine(Directory.GetCurrentDirectory(), "test_models", "cpu", "phi-2");
string modelPath = _phi2Path;
using (var model = new Model(modelPath))
{
Assert.NotNull(model);
Expand Down
Loading