mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
feat: optimize performance lora filtering in metadata (#3048)
* feat: add remove_performance_lora method * feat: use class PerformanceLoRA instead of strings in config * refactor: cleanup flags, use __member__ to check if enums contains key * feat: only filter lora of selected performance instead of all performance LoRAs * fix: disable intermediate results for all restricted performances too fast for Gradio, which becomes a bottleneck * refactor: rename parse_json to to_json, rename parse_string to to_string * feat: use speed steps as default instead of hardcoded 30 * feat: add method to_steps to Performance * refactor: remove method ordinal_suffix, not needed anymore * feat: only filter lora of selected performance instead of all performance LoRAs both metadata and history log * feat: do not filter LoRAs in metadata parser but rather in metadata load action
This commit is contained in:
+57
-1
@@ -1,5 +1,7 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import modules.flags
|
||||
from modules import util
|
||||
|
||||
|
||||
@@ -77,5 +79,59 @@ class TestUtils(unittest.TestCase):
|
||||
for test in test_cases:
|
||||
prompt, loras, loras_limit, skip_file_check = test["input"]
|
||||
expected = test["output"]
|
||||
actual = util.parse_lora_references_from_prompt(prompt, loras, loras_limit=loras_limit, skip_file_check=skip_file_check)
|
||||
actual = util.parse_lora_references_from_prompt(prompt, loras, loras_limit=loras_limit,
|
||||
skip_file_check=skip_file_check)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
def test_can_parse_tokens_and_strip_performance_lora(self):
|
||||
lora_filenames = [
|
||||
'hey-lora.safetensors',
|
||||
modules.flags.PerformanceLoRA.EXTREME_SPEED.value,
|
||||
modules.flags.PerformanceLoRA.LIGHTNING.value,
|
||||
os.path.join('subfolder', modules.flags.PerformanceLoRA.HYPER_SD.value)
|
||||
]
|
||||
|
||||
test_cases = [
|
||||
{
|
||||
"input": ("some prompt, <lora:hey-lora:0.4>", [], 5, True, modules.flags.Performance.QUALITY),
|
||||
"output": (
|
||||
[('hey-lora.safetensors', 0.4)],
|
||||
'some prompt'
|
||||
),
|
||||
},
|
||||
{
|
||||
"input": ("some prompt, <lora:hey-lora:0.4>", [], 5, True, modules.flags.Performance.SPEED),
|
||||
"output": (
|
||||
[('hey-lora.safetensors', 0.4)],
|
||||
'some prompt'
|
||||
),
|
||||
},
|
||||
{
|
||||
"input": ("some prompt, <lora:sdxl_lcm_lora:1>, <lora:hey-lora:0.4>", [], 5, True, modules.flags.Performance.EXTREME_SPEED),
|
||||
"output": (
|
||||
[('hey-lora.safetensors', 0.4)],
|
||||
'some prompt'
|
||||
),
|
||||
},
|
||||
{
|
||||
"input": ("some prompt, <lora:sdxl_lightning_4step_lora:1>, <lora:hey-lora:0.4>", [], 5, True, modules.flags.Performance.LIGHTNING),
|
||||
"output": (
|
||||
[('hey-lora.safetensors', 0.4)],
|
||||
'some prompt'
|
||||
),
|
||||
},
|
||||
{
|
||||
"input": ("some prompt, <lora:sdxl_hyper_sd_4step_lora:1>, <lora:hey-lora:0.4>", [], 5, True, modules.flags.Performance.HYPER_SD),
|
||||
"output": (
|
||||
[('hey-lora.safetensors', 0.4)],
|
||||
'some prompt'
|
||||
),
|
||||
}
|
||||
]
|
||||
|
||||
for test in test_cases:
|
||||
prompt, loras, loras_limit, skip_file_check, performance = test["input"]
|
||||
lora_filenames = modules.util.remove_performance_lora(lora_filenames, performance)
|
||||
expected = test["output"]
|
||||
actual = util.parse_lora_references_from_prompt(prompt, loras, loras_limit=loras_limit, lora_filenames=lora_filenames)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
Reference in New Issue
Block a user