ComfyUI Extension: LoRA Matcher Nodes for ComfyUI

Authored by Tr1dae

Created

Updated

0 stars

This custom node provides two different approaches to automatically match text prompts with LoRA models using their descriptions.

Custom Nodes (0)

    README

    LoRA Matcher Nodes for ComfyUI

    This custom node provides two different approaches to automatically match text prompts with LoRA models using their descriptions.

    šŸŽÆ Available Nodes

    1. Prompt LoRA Matcher (Fuzzy) - Fast Text Matching

    • Method: Fuzzy string matching using rapidfuzz
    • Speed: ⚔ Instant matching
    • Accuracy: Good for exact/near-exact matches
    • Requirements: None (works out of the box)

    2. AI LoRA Matcher (Semantic) - Smart AI Matching

    • Method: Semantic similarity using sentence-transformers
    • Speed: 🐌 Slower first run (downloads model)
    • Accuracy: šŸ¤– Understands meaning, synonyms, concepts
    • Requirements: Sentence-transformer models

    šŸ“ Model Setup (AI Matcher Only)

    The AI matcher can work with or without local models:

    Option 1: Automatic Download (Easiest)

    • No setup required
    • Models download automatically on first use
    • Slower initial load (~30-60 seconds)
    • Uses all-MiniLM-L12-v2 by default (higher accuracy)

    Option 2: Local Models (Recommended for Speed)

    Place sentence-transformer models in: custom_nodes/ComfyUI-LoraPromptMatcher/model/

    Recommended Models:

    1. all-MiniLM-L12-v2 ⭐⭐ (DEFAULT - Higher accuracy)

      • Size: ~45MB
      • Speed: Medium
      • Accuracy: ⭐⭐⭐⭐⭐ (Best semantic understanding)
    2. all-MiniLM-L6-v2 (Faster alternative)

      • Size: ~23MB
      • Speed: ⚔ Fast
      • Accuracy: ⭐⭐⭐⭐ (Good balance)
    3. paraphrase-MiniLM-L6-v2 (Good for paraphrases)

      • Size: ~23MB
      • Speed: Fast
      • Accuracy: Good for rephrased prompts

    Download Instructions:

    1. Visit: https://huggingface.co/sentence-transformers/
    2. Search for your chosen model (e.g., "all-MiniLM-L6-v2")
    3. Download the model files
    4. Extract to: custom_nodes/ComfyUI-LoraPromptMatcher/model/
    5. The directory structure should look like:
    model/
    ā”œā”€ā”€ all-MiniLM-L6-v2/
    │   ā”œā”€ā”€ config_sentence_transformers.json
    │   ā”œā”€ā”€ sentence_bert_config.json
    │   ā”œā”€ā”€ config.json
    │   ā”œā”€ā”€ pytorch_model.bin
    │   ā”œā”€ā”€ tokenizer.json
    │   ā”œā”€ā”€ tokenizer_config.json
    │   ā”œā”€ā”€ vocab.txt
    │   └── special_tokens_map.json
    

    āš™ļø Configuration

    LoRA Descriptions

    Edit reference_descriptions.json to add your LoRA models:

    {
        "my_lora.safetensors": "beautiful detailed portrait, realistic skin texture",
        "anime_style.safetensors": "anime art style, vibrant colors, expressive eyes",
        "cyberpunk.safetensors": "futuristic cyberpunk aesthetic, neon lights, high tech"
    }
    

    🚨 Warning System

    The AI matcher includes intelligent warnings:

    No Models Found

    ╔══════════════════════════════════════════════════════════════════════════════╗
    ā•‘                          šŸ¤– AI MODELS NOT FOUND šŸ¤–                          ā•‘
    ā•‘                                                                            ā•‘
    ā•‘  The AI LoRA Matcher requires sentence-transformer models for semantic    ā•‘
    ā•‘  matching, but none were found in the model directory.                    ā•‘
    ā•‘                                                                            ā•‘
    ā•‘  RECOMMENDED MODELS:                                                      ā•‘
    ā•‘  • all-MiniLM-L6-v2 (fast, good balance)                                   ā•‘
    ā•‘  • all-MiniLM-L12-v2 (better accuracy, slower)                            ā•‘
    ā•‘  • paraphrase-MiniLM-L6-v2 (good for paraphrases)                         ā•‘
    ā•‘                                                                            ā•‘
    ā•‘  DOWNLOAD FROM: huggingface.co/sentence-transformers/                     ā•‘
    ā•‘  Place model files in: custom_nodes/ComfyUI-LoraPromptMatcher/model/      ā•‘
    ā•‘                                                                            ā•‘
    ā•‘  ALTERNATIVE: The node will automatically download models from           ā•‘
    ā•‘  HuggingFace on first use (may be slower).                                ā•‘
    ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•
    

    GGUF Models Found (Wrong Type)

    ╔══════════════════════════════════════════════════════════════════════════════╗
    ā•‘                     šŸ”„ GGUF MODELS FOUND - ST MODELS NEEDED šŸ”„                ā•‘
    ā•‘                                                                            ā•‘
    ā•‘  Found GGUF models but the AI LoRA Matcher needs sentence-transformer     ā•‘
    ā•‘  models for semantic similarity matching.                                  ā•‘
    ā•‘                                                                            ā•‘
    ā•‘  DOWNLOAD sentence-transformer models from:                               ā•‘
    ā•‘  huggingface.co/sentence-transformers/                                     ā•‘
    ā•‘                                                                            ā•‘
    ā•‘  Recommended: all-MiniLM-L6-v2                                             ā•‘
    ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•
    

    šŸŽ›ļø Usage

    1. Add either node to your ComfyUI workflow
    2. Connect a MODEL input
    3. Enter your text description
    4. Adjust strength if needed (default: 1.0)
    5. The node outputs the model with the matched LoRA applied

    šŸ“Š Matching Examples

    | Input Prompt | Fuzzy Match | AI Match | Notes | |-------------|-------------|----------|--------| | "beautiful woman portrait" | portrait_lora (0.85) | portrait_lora (0.92) | Both work well | | "anime girl cute style" | anime_lora (0.76) | anime_lora (0.88) | AI better | | "person eating apple fruit" | food_lora (0.34) | food_lora (0.78) | AI much better | | "cyberpunk futuristic city" | No match (0.25) | cyberpunk_lora (0.71) | Only AI finds it |

    šŸ”§ Troubleshooting

    AI Matcher Not Working

    • Check console for warning messages
    • Ensure model directory exists: custom_nodes/ComfyUI-LoraPromptMatcher/model/
    • Try automatic download first (delete local models if issues persist)

    No LoRA Applied

    • Check reference_descriptions.json has your LoRA files
    • Verify LoRA files exist in the correct ComfyUI loras folder
    • Lower similarity threshold if matches are too strict

    Performance Issues

    • Use local models instead of automatic download
    • Try smaller models like all-MiniLM-L6-v2
    • The fuzzy matcher is always faster for simple cases

    šŸ“ Notes

    • The AI matcher caches embeddings for faster subsequent matches
    • Fuzzy matching uses token-based similarity (good for typos)
    • AI matching uses semantic understanding (better for concepts)
    • Both methods have adjustable similarity thresholds
    • Console output shows detailed matching information