Initialize the pattern matcher with all supported formats.
(self)
| 67 | """Detects and matches LoRA format patterns in state dicts.""" |
| 68 | |
| 69 | def __init__(self): |
| 70 | """Initialize the pattern matcher with all supported formats.""" |
| 71 | self.patterns: Dict[LoRAFormat, LoRAPatternDefinition] = { |
| 72 | LoRAFormat.STANDARD: LoRAPatternDefinition( |
| 73 | LoRAFormat.STANDARD, |
| 74 | up_suffix=".lora_up.weight", |
| 75 | down_suffix=".lora_down.weight", |
| 76 | mid_suffix=".lora_mid.weight", |
| 77 | ), |
| 78 | LoRAFormat.DIFFUSERS: LoRAPatternDefinition( |
| 79 | LoRAFormat.DIFFUSERS, |
| 80 | up_suffix="_lora.up.weight", |
| 81 | down_suffix="_lora.down.weight", |
| 82 | ), |
| 83 | LoRAFormat.DIFFUSERS_V2: LoRAPatternDefinition( |
| 84 | LoRAFormat.DIFFUSERS_V2, |
| 85 | up_suffix=".lora_B.weight", |
| 86 | down_suffix=".lora_A.weight", |
| 87 | ), |
| 88 | LoRAFormat.DIFFUSERS_V3: LoRAPatternDefinition( |
| 89 | LoRAFormat.DIFFUSERS_V3, |
| 90 | up_suffix=".lora.up.weight", |
| 91 | down_suffix=".lora.down.weight", |
| 92 | ), |
| 93 | LoRAFormat.MOCHI: LoRAPatternDefinition( |
| 94 | LoRAFormat.MOCHI, |
| 95 | up_suffix=".lora_B", |
| 96 | down_suffix=".lora_A", |
| 97 | has_weight_suffix=False, |
| 98 | ), |
| 99 | LoRAFormat.TRANSFORMERS: LoRAPatternDefinition( |
| 100 | LoRAFormat.TRANSFORMERS, |
| 101 | up_suffix=".lora_linear_layer.up.weight", |
| 102 | down_suffix=".lora_linear_layer.down.weight", |
| 103 | ), |
| 104 | LoRAFormat.QWEN: LoRAPatternDefinition( |
| 105 | LoRAFormat.QWEN, |
| 106 | up_suffix=".lora_B.default.weight", |
| 107 | down_suffix=".lora_A.default.weight", |
| 108 | ), |
| 109 | } |
| 110 | |
| 111 | def detect_format(self, key: str, lora_weights: Dict) -> Optional[Tuple[LoRAFormat, str]]: |
| 112 | """ |
nothing calls this directly
no test coverage detected