Skip to content

Commit 4d61ea3

Browse files
author
Yehudit Kerido
committed
Fix skipped model directory tests
Signed-off-by: Yehudit Kerido <[email protected]>
1 parent 5f5a079 commit 4d61ea3

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

candle-binding/src/ffi/init.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,11 @@ pub extern "C" fn init_lora_unified_classifier(
683683
}
684684
};
685685

686+
// Check if already initialized - return success if so
687+
if PARALLEL_LORA_ENGINE.get().is_some() {
688+
return true;
689+
}
690+
686691
// Load labels dynamically from model configurations
687692
let _intent_labels_vec = load_labels_from_model_config(intent_path).unwrap_or_else(|e| {
688693
eprintln!(
@@ -723,7 +728,9 @@ pub extern "C" fn init_lora_unified_classifier(
723728
) {
724729
Ok(engine) => {
725730
// Store in global static variable (Arc for efficient cloning during concurrent access)
731+
// Return true even if already set (race condition)
726732
PARALLEL_LORA_ENGINE.set(Arc::new(engine)).is_ok()
733+
|| PARALLEL_LORA_ENGINE.get().is_some()
727734
}
728735
Err(e) => {
729736
eprintln!(

src/semantic-router/pkg/classification/classifier_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
mcpclient "github.com/vllm-project/semantic-router/src/semantic-router/pkg/mcp"
2222
)
2323

24+
const testModelsDir = "../../../../models"
25+
2426
func TestClassifier(t *testing.T) {
2527
RegisterFailHandler(Fail)
2628
RunSpecs(t, "Classifier Suite")
@@ -2909,13 +2911,11 @@ func createMockModelFile(t *testing.T, dir, filename string) {
29092911

29102912
func TestAutoDiscoverModels_RealModels(t *testing.T) {
29112913
// Test with real models directory
2912-
modelsDir := "../../../../../models"
2914+
modelsDir := testModelsDir
29132915

29142916
paths, err := AutoDiscoverModels(modelsDir)
29152917
if err != nil {
2916-
// Skip this test in environments without the real models directory
2917-
t.Logf("AutoDiscoverModels() failed in real-models test: %v", err)
2918-
t.Skip("Skipping real-models discovery test because models directory is unavailable")
2918+
t.Fatalf("AutoDiscoverModels() failed: %v (models directory should exist at %s)", err, modelsDir)
29192919
}
29202920

29212921
t.Logf("Discovered paths:")
@@ -2964,10 +2964,9 @@ func TestAutoDiscoverModels_RealModels(t *testing.T) {
29642964
// TestAutoInitializeUnifiedClassifier tests the full initialization process
29652965
func TestAutoInitializeUnifiedClassifier(t *testing.T) {
29662966
// Test with real models directory
2967-
classifier, err := AutoInitializeUnifiedClassifier("../../../../../models")
2967+
classifier, err := AutoInitializeUnifiedClassifier(testModelsDir)
29682968
if err != nil {
2969-
t.Logf("AutoInitializeUnifiedClassifier() failed in real-models test: %v", err)
2970-
t.Skip("Skipping unified classifier init test because real models are unavailable")
2969+
t.Fatalf("AutoInitializeUnifiedClassifier() failed: %v (models directory should exist at %s)", err, testModelsDir)
29712970
}
29722971

29732972
if classifier == nil {
@@ -3305,7 +3304,7 @@ var (
33053304
// getTestClassifier returns a shared classifier instance for all integration tests
33063305
func getTestClassifier(t *testing.T) *UnifiedClassifier {
33073306
globalTestClassifierOnce.Do(func() {
3308-
classifier, err := AutoInitializeUnifiedClassifier("../../../../../models")
3307+
classifier, err := AutoInitializeUnifiedClassifier(testModelsDir)
33093308
if err != nil {
33103309
t.Logf("Failed to initialize classifier: %v", err)
33113310
return
@@ -3323,8 +3322,11 @@ func TestUnifiedClassifier_Integration(t *testing.T) {
33233322
// Get shared classifier instance
33243323
classifier := getTestClassifier(t)
33253324
if classifier == nil {
3326-
t.Skip("Skipping integration tests - classifier not available")
3327-
return
3325+
t.Fatal("Classifier initialization failed")
3326+
}
3327+
3328+
if !classifier.useLoRA {
3329+
t.Fatal("LoRA models not detected")
33283330
}
33293331

33303332
t.Run("RealBatchClassification", func(t *testing.T) {
@@ -3472,7 +3474,7 @@ func TestUnifiedClassifier_Integration(t *testing.T) {
34723474
func getBenchmarkClassifier(b *testing.B) *UnifiedClassifier {
34733475
// Reuse the global test classifier for benchmarks
34743476
globalTestClassifierOnce.Do(func() {
3475-
classifier, err := AutoInitializeUnifiedClassifier("../../../../../models")
3477+
classifier, err := AutoInitializeUnifiedClassifier(testModelsDir)
34763478
if err != nil {
34773479
b.Logf("Failed to initialize classifier: %v", err)
34783480
return

tools/make/models.mk

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ download-models: ## Download models (full or minimal set depending on CI_MINIMAL
2424
# - PII token classifier (ModernBERT Presidio)
2525
# - Jailbreak classifier (ModernBERT)
2626
# - Optional plain PII classifier mapping (small)
27+
# - LoRA models (BERT architecture) for unified classifier tests
2728

2829
download-models-minimal:
2930
download-models-minimal: ## Pre-download minimal set of models for CI tests
@@ -47,6 +48,16 @@ download-models-minimal: ## Pre-download minimal set of models for CI tests
4748
@if [ ! -f "models/pii_classifier_modernbert-base_model/.downloaded" ] || [ ! -d "models/pii_classifier_modernbert-base_model" ]; then \
4849
hf download LLM-Semantic-Router/pii_classifier_modernbert-base_model --local-dir models/pii_classifier_modernbert-base_model && printf '%s\n' "$$(date -u +%Y-%m-%dT%H:%M:%SZ)" > models/pii_classifier_modernbert-base_model/.downloaded; \
4950
fi
51+
# Download LoRA models for unified classifier integration tests
52+
@if [ ! -f "models/lora_intent_classifier_bert-base-uncased_model/.downloaded" ] || [ ! -d "models/lora_intent_classifier_bert-base-uncased_model" ]; then \
53+
hf download LLM-Semantic-Router/lora_intent_classifier_bert-base-uncased_model --local-dir models/lora_intent_classifier_bert-base-uncased_model && printf '%s\n' "$$(date -u +%Y-%m-%dT%H:%M:%SZ)" > models/lora_intent_classifier_bert-base-uncased_model/.downloaded; \
54+
fi
55+
@if [ ! -f "models/lora_pii_detector_bert-base-uncased_model/.downloaded" ] || [ ! -d "models/lora_pii_detector_bert-base-uncased_model" ]; then \
56+
hf download LLM-Semantic-Router/lora_pii_detector_bert-base-uncased_model --local-dir models/lora_pii_detector_bert-base-uncased_model && printf '%s\n' "$$(date -u +%Y-%m-%dT%H:%M:%SZ)" > models/lora_pii_detector_bert-base-uncased_model/.downloaded; \
57+
fi
58+
@if [ ! -f "models/lora_jailbreak_classifier_bert-base-uncased_model/.downloaded" ] || [ ! -d "models/lora_jailbreak_classifier_bert-base-uncased_model" ]; then \
59+
hf download LLM-Semantic-Router/lora_jailbreak_classifier_bert-base-uncased_model --local-dir models/lora_jailbreak_classifier_bert-base-uncased_model && printf '%s\n' "$$(date -u +%Y-%m-%dT%H:%M:%SZ)" > models/lora_jailbreak_classifier_bert-base-uncased_model/.downloaded; \
60+
fi
5061

5162
# Full model set for local development and docs
5263

0 commit comments

Comments
 (0)