Skip to content
Merged
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
1 change: 1 addition & 0 deletions VectorSharp.Embedding.NomicEmbed.Tests/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[assembly: CollectionBehavior(DisableTestParallelization = true)]
71 changes: 34 additions & 37 deletions VectorSharp.Embedding.NomicEmbed.Tests/EmbeddingPerformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace VectorSharp.Embedding.NomicEmbed.Tests
{
[TestClass]
[TestCategory("RequiresModel")]
[DoNotParallelize]
[Trait("Category", "RequiresModel")]
public class EmbeddingPerformanceTests
{
private const int WarmupCount = 5;
Expand All @@ -17,10 +15,9 @@ private static string GetModelDirectory()
string assemblyDir = Path.GetDirectoryName(typeof(EmbeddingPerformanceTests).Assembly.Location)!;
string modelsDir = Path.Combine(assemblyDir, "Models");

if (!Directory.Exists(modelsDir) || !File.Exists(Path.Combine(modelsDir, "model_int8.onnx")))
{
Assert.Inconclusive("Model files not found. Run tools/download-nomic-model.sh first.");
}
Skip.IfNot(
Directory.Exists(modelsDir) && File.Exists(Path.Combine(modelsDir, "model_int8.onnx")),
"Model files not found. Run tools/download-nomic-model.sh first.");

return modelsDir;
}
Expand All @@ -36,7 +33,7 @@ private static string[] CreateSampleTexts(int count)
return texts;
}

[TestMethod]
[SkippableFact]
public async Task PerformanceTest_SingleWorkerThroughput()
{
string modelsDir = GetModelDirectory();
Expand All @@ -62,7 +59,7 @@ public async Task PerformanceTest_SingleWorkerThroughput()
for (int i = 0; i < EmbeddingCount; i++)
{
float[] result = await service.EmbedAsync(texts[i]);
Assert.AreEqual(768, result.Length);
Assert.Equal(768, result.Length);
}

timer.Stop();
Expand All @@ -75,13 +72,13 @@ public async Task PerformanceTest_SingleWorkerThroughput()
Console.WriteLine($"Per embedding: {msPerEmbedding:F2} ms");
Console.WriteLine($"Throughput: {embeddingsPerSecond:F1} embeddings/second");

Assert.IsTrue(timer.ElapsedMilliseconds > 0);
Assert.True(timer.ElapsedMilliseconds > 0);
}

[TestMethod]
[DataRow(1)]
[DataRow(2)]
[DataRow(4)]
[SkippableTheory]
[InlineData(1)]
[InlineData(2)]
[InlineData(4)]
public async Task PerformanceTest_ThroughputByConcurrency(int concurrency)
{
string modelsDir = GetModelDirectory();
Expand Down Expand Up @@ -118,23 +115,23 @@ public async Task PerformanceTest_ThroughputByConcurrency(int concurrency)
Console.WriteLine($"Per embedding: {msPerEmbedding:F2} ms");
Console.WriteLine($"Throughput: {embeddingsPerSecond:F1} embeddings/second");

Assert.AreEqual(EmbeddingCount, results.Length);
Assert.Equal(EmbeddingCount, results.Length);
foreach (float[] result in results)
{
Assert.AreEqual(768, result.Length);
Assert.Equal(768, result.Length);
}
}

[TestMethod]
[DataRow(1, 0)]
[DataRow(2, 0)]
[DataRow(4, 0)]
[DataRow(2, 2)]
[DataRow(3, 2)]
[DataRow(4, 2)]
[DataRow(6, 2)]
[DataRow(6, 3)]
[DataRow(9, 2)]
[SkippableTheory]
[InlineData(1, 0)]
[InlineData(2, 0)]
[InlineData(4, 0)]
[InlineData(2, 2)]
[InlineData(3, 2)]
[InlineData(4, 2)]
[InlineData(6, 2)]
[InlineData(6, 3)]
[InlineData(9, 2)]
public async Task PerformanceTest_ThreadsVsConcurrency(int concurrency, int intraOpThreads)
{
string modelsDir = GetModelDirectory();
Expand Down Expand Up @@ -174,10 +171,10 @@ public async Task PerformanceTest_ThreadsVsConcurrency(int concurrency, int intr
double embeddingsPerSecond = EmbeddingCount / timer.Elapsed.TotalSeconds;
Console.WriteLine($"Total: {timer.ElapsedMilliseconds:N0} ms, Throughput: {embeddingsPerSecond:F1} embeddings/sec");

Assert.AreEqual(EmbeddingCount, results.Length);
Assert.Equal(EmbeddingCount, results.Length);
}

[TestMethod]
[SkippableFact]
public async Task PerformanceTest_MaxThroughput()
{
string modelsDir = GetModelDirectory();
Expand Down Expand Up @@ -221,14 +218,14 @@ public async Task PerformanceTest_MaxThroughput()
Console.WriteLine($"Per embedding: {timer.Elapsed.TotalMilliseconds / count:F2} ms");
Console.WriteLine($"Throughput: {embeddingsPerSecond:F1} embeddings/sec");

Assert.AreEqual(count, results.Length);
Assert.Equal(count, results.Length);
}

[TestMethod]
[DataRow(0)]
[DataRow(2)]
[DataRow(3)]
[DataRow(4)]
[SkippableTheory]
[InlineData(0)]
[InlineData(2)]
[InlineData(3)]
[InlineData(4)]
public async Task PerformanceTest_SweetSpotThroughput(int intraOpThreads)
{
string modelsDir = GetModelDirectory();
Expand Down Expand Up @@ -274,10 +271,10 @@ public async Task PerformanceTest_SweetSpotThroughput(int intraOpThreads)
Console.WriteLine($"Per embedding: {timer.Elapsed.TotalMilliseconds / count:F2} ms");
Console.WriteLine($"Throughput: {embeddingsPerSecond:F1} embeddings/sec");

Assert.AreEqual(count, results.Length);
Assert.Equal(count, results.Length);
}

[TestMethod]
[SkippableFact]
public async Task PerformanceTest_ConcurrencyScaling()
{
string modelsDir = GetModelDirectory();
Expand Down Expand Up @@ -327,7 +324,7 @@ public async Task PerformanceTest_ConcurrencyScaling()
Console.WriteLine($"Concurrency {concurrency}: {speedup:F2}x vs single worker");
}

Assert.IsTrue(results[1] > 0);
Assert.True(results[1] > 0);
}
}
}
1 change: 0 additions & 1 deletion VectorSharp.Embedding.NomicEmbed.Tests/MSTestSettings.cs

This file was deleted.

Loading
Loading