Skip to content

Commit f631517

Browse files
authored
test(models): harden model catalog and recommender test suites (#4143)
Add a direct table test for isGPUBackend that pins gpuBackendTokens membership (cuda, tensorrt, openvino-gpu), the GPU subset that gates the fp16 size lever. The lever was previously exercised only through openvino-gpu, so cuda and tensorrt membership was untested; the table now fails if a GPU token is dropped from the set or a CPU token added. Replace hard-coded host-capability string literals in the catalog selection and regional tests with the hwprofile.Cap* constants, so a capability-token rename fails to compile instead of silently drifting the tests. Tokens with no exported constant (cuda, tensorrt, precisions, the per-generation Intel GPU prefix) are left as literals. Test-only: no production code changes.
1 parent d64ab0a commit f631517

3 files changed

Lines changed: 40 additions & 11 deletions

File tree

internal/classifier/model_catalog_regional_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/stretchr/testify/require"
99

1010
"github.com/tphakala/birdnet-go/internal/classifier/region"
11+
"github.com/tphakala/birdnet-go/internal/hwprofile"
1112
)
1213

1314
// regionalTilesPerFamily is how many region-sliced variants the generator emits
@@ -96,7 +97,7 @@ func TestEmbeddedCatalog_RegionalVariants(t *testing.T) {
9697
assert.Containsf(t, v.Requirements.Excludes, "openvino-gpu-intel-gen12", "fp16 variant %q must exclude the Iris Xe gen12 miscompile", v.ID)
9798
}
9899
if strings.HasPrefix(v.ID, "int8-arm@") {
99-
assert.Equalf(t, []string{"aarch64"}, v.Requirements.Arch, "int8-arm variant %q must require aarch64", v.ID)
100+
assert.Equalf(t, []string{hwprofile.CapAArch64}, v.Requirements.Arch, "int8-arm variant %q must require aarch64", v.ID)
100101
}
101102
}
102103
assert.Equalf(t, regionalTilesPerFamily, regional, "%s must expose %d regional tiles", entryID, regionalTilesPerFamily)

internal/classifier/model_catalog_selection_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/tphakala/birdnet-go/internal/classifier"
1010
"github.com/tphakala/birdnet-go/internal/classifier/recommend"
11+
"github.com/tphakala/birdnet-go/internal/hwprofile"
1112
)
1213

1314
// mib is one mebibyte, matching the recommender's MinRAMMB-to-bytes conversion.
@@ -78,7 +79,7 @@ func TestRecommend_RegionalTiles(t *testing.T) {
7879
// region +100, backend.recommended +40, and low-ram+int8 ram.constrained_fit
7980
// +25 = 165, versus no-dft-fp32's region +100 + backend.supported +10 = 110.
8081
lowRAM := 300 * mib
81-
gotPerch := recommendedVariantID(&perch, []string{"aarch64", "onnxruntime-cpu", "low-ram"}, lowRAM, slug)
82+
gotPerch := recommendedVariantID(&perch, []string{hwprofile.CapAArch64, hwprofile.CapONNXRuntimeCPU, hwprofile.CapLowRAM}, lowRAM, slug)
8283
assert.Equalf(t, "int8-arm@"+slug, gotPerch, "low-RAM aarch64 host in %q must get the regional int8-arm slice", slug)
8384
assert.Equalf(t, "regional/"+slug+"/perch_v2_"+slug+"_int8_arm.onnx", modelRemotePath(t, &perch, gotPerch),
8485
"recommended perch variant must own the manifest low-ram selection path")
@@ -87,7 +88,7 @@ func TestRecommend_RegionalTiles(t *testing.T) {
8788
// slice (region.matched +100 + backend.recommended +40 = 140) over the
8889
// region's fp16 slice (+100 + backend.supported +10 = 110) and over the
8990
// global model (which loses the fallback bonus once a slice matches).
90-
gotV30 := recommendedVariantID(&v30, []string{"x86-64", "onnxruntime-cpu"}, 8*1024*mib, slug)
91+
gotV30 := recommendedVariantID(&v30, []string{hwprofile.CapX86_64, hwprofile.CapONNXRuntimeCPU}, 8*1024*mib, slug)
9192
assert.Equalf(t, "fp32@"+slug, gotV30, "CPU host in %q must get the regional fp32 slice", slug)
9293
})
9394
}
@@ -96,7 +97,7 @@ func TestRecommend_RegionalTiles(t *testing.T) {
9697
// the global variant wins on its fallback bonus.
9798
t.Run("global-host-picks-global", func(t *testing.T) {
9899
t.Parallel()
99-
caps := []string{"x86-64", "onnxruntime-cpu"}
100+
caps := []string{hwprofile.CapX86_64, hwprofile.CapONNXRuntimeCPU}
100101
high := 8 * 1024 * mib
101102

102103
gotV30 := recommendedVariantID(&v30, caps, high, "")
@@ -125,13 +126,13 @@ func TestRecommend_V30GlobalSelection(t *testing.T) {
125126
caps []string
126127
wantPath string // manifest selection value
127128
}{
128-
{"x86-64/onnxruntime", []string{"x86-64", "onnxruntime-cpu"}, "full/birdnet-v3.0-preview3.1-fp32-b1.onnx"},
129-
{"x86-64/openvino-cpu", []string{"x86-64", "onnxruntime-cpu", "openvino-cpu"}, "full/birdnet-v3.0-preview3.1-fp32-b1.onnx"},
130-
{"x86-64/openvino-gpu", []string{"x86-64", "onnxruntime-cpu", "openvino-cpu", "openvino-gpu"}, "full/birdnet-v3.0-preview3.1-fp16-b1.onnx"},
131-
{"aarch64-a76/openvino", []string{"aarch64", "aarch64-a76", "onnxruntime-cpu", "openvino-cpu"}, "full/birdnet-v3.0-preview3.1-fp32-b1.onnx"},
132-
{"aarch64/onnxruntime", []string{"aarch64", "onnxruntime-cpu"}, "full/birdnet-v3.0-preview3.1-fp32-b1.onnx"},
133-
{"cuda", []string{"x86-64", "onnxruntime-cpu", "cuda"}, "full/birdnet-v3.0-preview3.1-fp16-b1.onnx"},
134-
{"tensorrt", []string{"x86-64", "onnxruntime-cpu", "cuda", "tensorrt"}, "full/birdnet-v3.0-preview3.1-fp16-b1.onnx"},
129+
{"x86-64/onnxruntime", []string{hwprofile.CapX86_64, hwprofile.CapONNXRuntimeCPU}, "full/birdnet-v3.0-preview3.1-fp32-b1.onnx"},
130+
{"x86-64/openvino-cpu", []string{hwprofile.CapX86_64, hwprofile.CapONNXRuntimeCPU, hwprofile.CapOpenVINOCPU}, "full/birdnet-v3.0-preview3.1-fp32-b1.onnx"},
131+
{"x86-64/openvino-gpu", []string{hwprofile.CapX86_64, hwprofile.CapONNXRuntimeCPU, hwprofile.CapOpenVINOCPU, hwprofile.CapOpenVINOGPU}, "full/birdnet-v3.0-preview3.1-fp16-b1.onnx"},
132+
{"aarch64-a76/openvino", []string{hwprofile.CapAArch64, hwprofile.CapAArch64A76, hwprofile.CapONNXRuntimeCPU, hwprofile.CapOpenVINOCPU}, "full/birdnet-v3.0-preview3.1-fp32-b1.onnx"},
133+
{"aarch64/onnxruntime", []string{hwprofile.CapAArch64, hwprofile.CapONNXRuntimeCPU}, "full/birdnet-v3.0-preview3.1-fp32-b1.onnx"},
134+
{"cuda", []string{hwprofile.CapX86_64, hwprofile.CapONNXRuntimeCPU, "cuda"}, "full/birdnet-v3.0-preview3.1-fp16-b1.onnx"},
135+
{"tensorrt", []string{hwprofile.CapX86_64, hwprofile.CapONNXRuntimeCPU, "cuda", "tensorrt"}, "full/birdnet-v3.0-preview3.1-fp16-b1.onnx"},
135136
}
136137
for _, tc := range cases {
137138
t.Run(tc.name, func(t *testing.T) {

internal/classifier/recommend/recommend_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,33 @@ func TestDeviceMatches(t *testing.T) {
196196
}
197197
}
198198

199+
// TestIsGPUBackend pins the gpuBackendTokens membership that gates the fp16 GPU
200+
// size lever. The lever is otherwise exercised only through openvino-gpu, so
201+
// cuda and tensorrt membership is untested (no current build emits those
202+
// tokens); this direct table catches a future edit that drops one of the three
203+
// GPU tokens from the set, or adds a CPU token to it.
204+
func TestIsGPUBackend(t *testing.T) {
205+
t.Parallel()
206+
207+
tests := []struct {
208+
backend string
209+
want bool
210+
}{
211+
{backendCUDA, true},
212+
{backendTensorRT, true},
213+
{hwprofile.CapOpenVINOGPU, true},
214+
{hwprofile.CapONNXRuntimeCPU, false},
215+
{hwprofile.CapOpenVINOCPU, false},
216+
{hwprofile.CapTFLite, false},
217+
}
218+
for _, tt := range tests {
219+
t.Run(tt.backend, func(t *testing.T) {
220+
t.Parallel()
221+
assert.Equalf(t, tt.want, isGPUBackend(tt.backend), "isGPUBackend(%q)", tt.backend)
222+
})
223+
}
224+
}
225+
199226
func TestRank_X86BenchmarkPrefixMatch(t *testing.T) {
200227
t.Parallel()
201228

0 commit comments

Comments
 (0)