Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ jobs:
with:
path: |
models/
key: ${{ runner.os }}-models-v1-${{ hashFiles('tools/make/models.mk') }}
key: ${{ runner.os }}-models-v2-${{ hashFiles('tools/make/models.mk') }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is v2 being used here? Is it really necessary for us to upgrade to v2? The model files are very large and will occupy a lot of cache space on GitHub.

restore-keys: |
${{ runner.os }}-models-v1-
${{ runner.os }}-models-v2-
continue-on-error: true # Don't fail the job if caching fails

- name: Check go mod tidy
Expand Down
7 changes: 7 additions & 0 deletions candle-binding/src/ffi/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,11 @@ pub extern "C" fn init_lora_unified_classifier(
}
};

// Check if already initialized - return success if so
if PARALLEL_LORA_ENGINE.get().is_some() {
return true;
}

// Load labels dynamically from model configurations
let _intent_labels_vec = load_labels_from_model_config(intent_path).unwrap_or_else(|e| {
eprintln!(
Expand Down Expand Up @@ -723,7 +728,9 @@ pub extern "C" fn init_lora_unified_classifier(
) {
Ok(engine) => {
// Store in global static variable (Arc for efficient cloning during concurrent access)
// Return true even if already set (race condition)
PARALLEL_LORA_ENGINE.set(Arc::new(engine)).is_ok()
|| PARALLEL_LORA_ENGINE.get().is_some()
}
Err(e) => {
eprintln!(
Expand Down
20 changes: 10 additions & 10 deletions src/semantic-router/pkg/classification/classifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2909,13 +2909,11 @@ func createMockModelFile(t *testing.T, dir, filename string) {

func TestAutoDiscoverModels_RealModels(t *testing.T) {
// Test with real models directory
modelsDir := "../../../../../models"
modelsDir := "../../../../models"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we define it as a constant? This is used in many places.


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

t.Logf("Discovered paths:")
Expand Down Expand Up @@ -2964,10 +2962,9 @@ func TestAutoDiscoverModels_RealModels(t *testing.T) {
// TestAutoInitializeUnifiedClassifier tests the full initialization process
func TestAutoInitializeUnifiedClassifier(t *testing.T) {
// Test with real models directory
classifier, err := AutoInitializeUnifiedClassifier("../../../../../models")
classifier, err := AutoInitializeUnifiedClassifier("../../../../models")
if err != nil {
t.Logf("AutoInitializeUnifiedClassifier() failed in real-models test: %v", err)
t.Skip("Skipping unified classifier init test because real models are unavailable")
t.Fatalf("AutoInitializeUnifiedClassifier() failed: %v (models directory should exist at ../../../../models)", err)
}

if classifier == nil {
Expand Down Expand Up @@ -3305,7 +3302,7 @@ var (
// getTestClassifier returns a shared classifier instance for all integration tests
func getTestClassifier(t *testing.T) *UnifiedClassifier {
globalTestClassifierOnce.Do(func() {
classifier, err := AutoInitializeUnifiedClassifier("../../../../../models")
classifier, err := AutoInitializeUnifiedClassifier("../../../../models")
if err != nil {
t.Logf("Failed to initialize classifier: %v", err)
return
Expand All @@ -3323,8 +3320,11 @@ func TestUnifiedClassifier_Integration(t *testing.T) {
// Get shared classifier instance
classifier := getTestClassifier(t)
if classifier == nil {
t.Skip("Skipping integration tests - classifier not available")
return
t.Fatal("Classifier initialization failed")
}

if !classifier.useLoRA {
t.Fatal("LoRA models not detected")
}

t.Run("RealBatchClassification", func(t *testing.T) {
Expand Down
11 changes: 11 additions & 0 deletions tools/make/models.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ download-models: ## Download models (full or minimal set depending on CI_MINIMAL
# - PII token classifier (ModernBERT Presidio)
# - Jailbreak classifier (ModernBERT)
# - Optional plain PII classifier mapping (small)
# - LoRA models (BERT architecture) for unified classifier tests

download-models-minimal:
download-models-minimal: ## Pre-download minimal set of models for CI tests
Expand All @@ -47,6 +48,16 @@ download-models-minimal: ## Pre-download minimal set of models for CI tests
@if [ ! -f "models/pii_classifier_modernbert-base_model/.downloaded" ] || [ ! -d "models/pii_classifier_modernbert-base_model" ]; then \
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; \
fi
# Download LoRA models for unified classifier integration tests
@if [ ! -f "models/lora_intent_classifier_bert-base-uncased_model/.downloaded" ] || [ ! -d "models/lora_intent_classifier_bert-base-uncased_model" ]; then \
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; \
fi
@if [ ! -f "models/lora_pii_detector_bert-base-uncased_model/.downloaded" ] || [ ! -d "models/lora_pii_detector_bert-base-uncased_model" ]; then \
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; \
fi
@if [ ! -f "models/lora_jailbreak_classifier_bert-base-uncased_model/.downloaded" ] || [ ! -d "models/lora_jailbreak_classifier_bert-base-uncased_model" ]; then \
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; \
fi

# Full model set for local development and docs

Expand Down
Loading