forked from zhongkaifu/TensorSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixExpander.cs
More file actions
135 lines (123 loc) · 4.72 KB
/
Copy pathMatrixExpander.cs
File metadata and controls
135 lines (123 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright (c) Zhongkai Fu. All rights reserved.
// Licensed under the BSD-3-Clause license. See LICENSE in the repo root.
namespace TensorSharp.TestMatrix.Matrix;
public sealed record MatrixExpansion(
IReadOnlyList<TestCase> Cases,
IReadOnlyList<SkippedCombination> Skipped);
public sealed record SkippedCombination(
ModelSpec Model,
BackendInfo Backend,
FeatureSpec Feature,
string? EnvVar,
string Reason);
/// <summary>
/// Expands the cartesian product (models × backends × features × env-var sweeps)
/// into <see cref="TestCase"/>s, applying availability and capability filters.
/// </summary>
public sealed class MatrixExpander
{
private readonly IReadOnlyList<ModelSpec> _models;
private readonly IReadOnlyList<BackendInfo> _backends;
private readonly IReadOnlyList<FeatureSpec> _features;
private readonly IReadOnlyList<EnvVarSpec> _envVars;
public MatrixExpander(
IReadOnlyList<ModelSpec> models,
IReadOnlyList<BackendInfo> backends,
IReadOnlyList<FeatureSpec> features,
IReadOnlyList<EnvVarSpec> envVars)
{
_models = models;
_backends = backends;
_features = features;
_envVars = envVars;
}
public MatrixExpansion Expand()
{
var cases = new List<TestCase>();
var skipped = new List<SkippedCombination>();
foreach (ModelSpec model in _models)
{
foreach (BackendInfo backend in _backends)
{
if (!backend.IsAvailableOnHost())
{
skipped.Add(new SkippedCombination(model, backend, FeatureCatalog.SyntheticPrefill512, null,
$"backend '{backend.Id}' not available on this host"));
continue;
}
foreach (FeatureSpec feature in _features)
{
string? reason = WhyFeatureNotApplicable(model, feature);
if (reason is not null)
{
skipped.Add(new SkippedCombination(model, backend, feature, null, reason));
continue;
}
// 1. Baseline case (no env var sweep).
cases.Add(new TestCase(
Model: model,
Backend: backend,
Feature: feature,
EnvVar: null,
EnvValue: null,
ExtraEnv: new Dictionary<string, string>()));
// 2. Per-env-var sweep cases.
foreach (EnvVarSpec env in _envVars)
{
if (!env.AppliesTo(model, backend, feature))
{
continue;
}
foreach (string value in env.Values)
{
cases.Add(new TestCase(
Model: model,
Backend: backend,
Feature: feature,
EnvVar: env.Name,
EnvValue: value,
ExtraEnv: new Dictionary<string, string> { { env.Name, value } }));
}
}
}
}
}
return new MatrixExpansion(cases, skipped);
}
private static string? WhyFeatureNotApplicable(ModelSpec model, FeatureSpec feature)
{
if (feature.RequiresImage && !model.SupportsImage)
{
return $"{model.Id} does not support image input";
}
if (feature.RequiresAudio && !model.SupportsAudio)
{
return $"{model.Id} does not support audio input";
}
if (feature.RequiresVideo && !model.SupportsVideo)
{
return $"{model.Id} does not support video input";
}
if (feature.RequiresTools && !model.SupportsTools)
{
return $"{model.Id} does not support tool calling";
}
if (feature.Kind == FeatureKind.Thinking && !model.SupportsThinking)
{
return $"{model.Id} does not support thinking mode";
}
if (feature.RequiresImage && string.IsNullOrEmpty(model.MmprojPath))
{
return $"{model.Id} has no mmproj — image disabled";
}
if (feature.RequiresAudio && string.IsNullOrEmpty(model.MmprojPath))
{
return $"{model.Id} has no mmproj — audio disabled";
}
if (feature.RequiresVideo && string.IsNullOrEmpty(model.MmprojPath))
{
return $"{model.Id} has no mmproj — video disabled";
}
return null;
}
}