Skip to content

Commit

Permalink
feat: LCM (#118)
Browse files Browse the repository at this point in the history
* fix: better handling of unexpected baselines

* Working multiple lora v

* Adjust sliders when a LCM payload is detected
  • Loading branch information
db0 authored Jan 5, 2024
1 parent 268bed3 commit 6e58d3a
Show file tree
Hide file tree
Showing 14 changed files with 360 additions and 194 deletions.
54 changes: 47 additions & 7 deletions ConfigSlider.gd
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func _ready():
ParamBus.connect("models_changed",self,"_on_models_changed")
# warning-ignore:return_value_discarded
EventBus.connect("kudos_calculated", self, "_on_kudos_calculated")
ParamBus.connect("params_changed",self,"_on_params_changed")

func set_value(value) -> void:
$"%HSlider".value = value
Expand All @@ -86,12 +87,21 @@ func set_max_value(max_value) -> void:
$"%ConfigValue".text = str(max_value)
$"%HSlider".max_value = max_value

func set_upfront_limit(_upfront_limit) -> void:
upfront_limit = _upfront_limit
if not globals.config.get_value("Options", "larger_values", false):
$"%HSlider".max_value = upfront_limit

func reset_upfront_limit() -> void:
if not CONFIG[config_setting].has('upfront_limit'):
return
upfront_limit = CONFIG[config_setting].upfront_limit
if not globals.config.get_value("Options", "larger_values", false):
$"%HSlider".max_value = upfront_limit

func reset_max_value() -> void:
$"%HSlider".max_value = CONFIG[config_setting].max
if CONFIG[config_setting].has('upfront_limit'):
upfront_limit = CONFIG[config_setting].upfront_limit
if not globals.config.get_value("Options", "larger_values", false):
$"%HSlider".max_value = CONFIG[config_setting].upfront_limit
reset_upfront_limit()

func _on_HSlider_drag_ended(value_changed):
if not value_changed:
Expand Down Expand Up @@ -126,6 +136,7 @@ func _on_setting_changed(setting_name):
$"%HSlider".max_value = CONFIG[config_setting].max
else:
$"%HSlider".max_value = CONFIG[config_setting].upfront_limit
_on_params_changed()

# Only called for width/height changes
func _on_config_slider_changed() -> void:
Expand All @@ -135,7 +146,7 @@ func _on_config_slider_changed() -> void:
else:
config_value.modulate = Color(1,1,1)
$"%HSlider".modulate = Color(1,1,1)

# Only called for width/height changes
func _on_wh_changed(sister_slider) -> void:
stored_sister_slider = sister_slider
Expand All @@ -146,8 +157,12 @@ func _on_wh_changed(sister_slider) -> void:
upfront_limit = 576
if "stable diffusion 2" in baselines:
upfront_limit = 768
if "SDXL" in baselines:
if "stable_diffusion_xl" in baselines:
upfront_limit = 1024
if not globals.config.get_value("Options", "larger_values", false):
$"%HSlider".max_value = upfront_limit
if int(config_value.text) > upfront_limit:
config_value.text = str(upfront_limit)
if sister_slider.h_slider.value * h_slider.value > upfront_limit * upfront_limit and globals.user_kudos < generation_kudos:
for n in [sister_slider, self]:
n.config_value.modulate = Color(1,0,0)
Expand All @@ -156,7 +171,7 @@ func _on_wh_changed(sister_slider) -> void:
for n in [sister_slider, self]:
n.config_value.modulate = Color(1,1,1)
n.h_slider.modulate = Color(1,1,1)


func _on_models_changed(_models) -> void:
if not stored_sister_slider:
Expand All @@ -169,3 +184,28 @@ func _on_kudos_calculated(kudos) -> void:
_on_wh_changed(stored_sister_slider)
else:
_on_config_slider_changed()

func _on_params_changed() -> void:
if config_setting == "steps":
if ParamBus.has_controlnet() or ParamBus.is_lcm_payload():
if ParamBus.is_lcm_payload():
# Protect the user a bit during switching to LCM
if h_slider.value > 40:
h_slider.value = 8
set_upfront_limit(10)
else:
reset_upfront_limit()
if h_slider.value > 40:
h_slider.value = 20
set_max_value(40)
else:
reset_max_value()
if config_setting == "cfg_scale":
if ParamBus.is_lcm_payload():
# Protect the user a bit
if h_slider.value > 4:
h_slider.value = 2
set_max_value(4)
else:
reset_max_value()

2 changes: 1 addition & 1 deletion ConfigSlider.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ align = 2
unique_name_in_owner = true
margin_top = 24.0
margin_right = 300.0
margin_bottom = 40.0
margin_bottom = 36.0
mouse_filter = 1
min_value = 1.0
max_value = 20.0
Expand Down
22 changes: 20 additions & 2 deletions LucidCreations.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ custom_styles/panel = ExtResource( 39 )
margin_left = 10.0
margin_top = 10.0
margin_right = 614.0
margin_bottom = 483.0
margin_bottom = 515.0

[node name="LoraInfoLabel" type="RichTextLabel" parent="Margin/Panel/Display/Panels/Controls/Basic/Lora/SelectedLoras/LoraInfoCard/VBoxContainer"]
unique_name_in_owner = true
Expand Down Expand Up @@ -823,6 +823,24 @@ margin_right = 604.0
margin_bottom = 169.0
slider_name = "Clip Strength"

[node name="LoraVersions" type="HBoxContainer" parent="Margin/Panel/Display/Panels/Controls/Basic/Lora/SelectedLoras/LoraInfoCard/VBoxContainer"]
margin_right = 40.0
margin_bottom = 40.0

[node name="LoraVersionName" type="Label" parent="Margin/Panel/Display/Panels/Controls/Basic/Lora/SelectedLoras/LoraInfoCard/VBoxContainer/LoraVersions"]
margin_right = 40.0
margin_bottom = 20.0
text = "Version: "

[node name="LoraVersionSelection" type="MenuButton" parent="Margin/Panel/Display/Panels/Controls/Basic/Lora/SelectedLoras/LoraInfoCard/VBoxContainer/LoraVersions"]
unique_name_in_owner = true
margin_left = -118.0
margin_top = -10.0
margin_right = -98.0
margin_bottom = 18.0
toggle_mode = false
flat = false

[node name="HBoxContainer" type="HBoxContainer" parent="Margin/Panel/Display/Panels/Controls/Basic/Lora/SelectedLoras/LoraInfoCard/VBoxContainer"]
margin_top = 173.0
margin_right = 604.0
Expand Down Expand Up @@ -1142,7 +1160,7 @@ margin_top = 218.0
margin_right = 300.0
margin_bottom = 246.0
text = "k_lms"
items = [ "k_lms", null, false, 0, null, "k_heun", null, false, 1, null, "k_euler", null, false, 2, null, "k_euler_a", null, false, 3, null, "k_dpm_2", null, false, 4, null, "k_dpm_2_a", null, false, 5, null, "k_dpm_fast", null, false, 6, null, "k_dpm_adaptive", null, false, 7, null, "k_dpmpp_2s_a", null, false, 8, null, "k_dpmpp_2m", null, false, 9, null, "dpmsolver", null, false, 10, null, "k_dpmpp_sde", null, false, 11, null ]
items = [ "k_lms", null, false, 0, null, "k_heun", null, false, 1, null, "k_euler", null, false, 2, null, "k_euler_a", null, false, 3, null, "k_dpm_2", null, false, 4, null, "k_dpm_2_a", null, false, 5, null, "k_dpm_fast", null, false, 6, null, "k_dpm_adaptive", null, false, 7, null, "k_dpmpp_2s_a", null, false, 8, null, "k_dpmpp_2m", null, false, 9, null, "k_dpmpp_sde", null, false, 10, null, "dpmsolver", null, false, 11, null, "lcm", null, false, 12, null ]
selected = 0

[node name="SeedLabel" type="Label" parent="Margin/Panel/Display/Panels/Controls/Advanced"]
Expand Down
2 changes: 1 addition & 1 deletion Model.gd
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func _get_selected_models() -> Array:
if model_name == "SDXL_beta::stability.ai#6901":
model_defs.append({
"name": "SDXL_beta::stability.ai#6901",
"baseline": "SDXL",
"baseline": "stable_diffusion_xl",
"type": "SDXL",
"version": "beta",
})
Expand Down
24 changes: 13 additions & 11 deletions StableHordeClient.gd
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,35 @@ func _ready():
stable_horde_client.aihorde_url = globals.aihorde_url

_connect_hover_signals()
# warning-ignore:return_value_discarded
save.connect("pressed", self, "_on_save_pressed")
# warning-ignore:return_value_discarded
save_all.connect("pressed", self, "_on_save_all_pressed")
load_from_disk.connect("gensettings_loaded", self, "_on_load_from_disk_gensettings_loaded")
# warning-ignore:return_value_discarded
generate_button.connect("pressed",self,"_on_GenerateButton_pressed")
# warning-ignore:return_value_discarded
cancel_button.connect("pressed",self,"_on_CancelButton_pressed")
# warning-ignore:return_value_discarded
model.connect("prompt_inject_requested",self,"_on_prompt_inject")
# warning-ignore:return_value_discarded
lora.connect("prompt_inject_requested",self,"_on_prompt_inject")
# warning-ignore:return_value_discarded
ti.connect("prompt_inject_requested",self,"_on_prompt_inject")
# Ratings
# warning-ignore:return_value_discarded
EventBus.connect("shared_toggled", self, "_on_shared_toggled")
# warning-ignore:return_value_discarded
best_of.connect("toggled",self,"on_bestof_toggled")
# warning-ignore:return_value_discarded
aesthetic_rating.connect("item_selected",self,"on_aethetic_rating_selected")
# warning-ignore:return_value_discarded
artifacts_rating.connect("item_selected",self,"on_artifacts_rating_selected")
# warning-ignore:return_value_discarded
submit_ratings.connect("pressed", self, "_on_submit_ratings_pressed")
# warning-ignore:return_value_discarded
stable_horde_rate_generation.connect("generation_rated",self, "_on_generation_rated")
# warning-ignore:return_value_discarded
stable_horde_rate_generation.connect("request_failed",self, "_on_generation_rating_failed")
nsfw.connect("toggled", self,"_on_nsfw_toggled")
_on_shared_toggled()
Expand All @@ -148,7 +160,6 @@ func _ready():
_on_SamplerMethod_item_selected(sampler_method_id)
var control_type_id = stable_horde_client.get_control_type_id()
control_type.select(control_type_id)
_on_ControlType_item_selected(control_type_id)
# The stable horde client is set from the Parameters settings
options.set_api_key(stable_horde_client.api_key)
options.login()
Expand Down Expand Up @@ -287,7 +298,6 @@ func _on_image_process_update(stats: Dictionary) -> void:
status_text.bbcode_text = "Your queue position is {queue}.".format({"queue":stats.queue_position})
status_text.modulate = Color(0,1,0)


func _on_viewport_resized() -> void:
# Disabling now with the tabs
# return
Expand Down Expand Up @@ -485,14 +495,7 @@ func _on_SamplerMethod_item_selected(index: int) -> void:
else:
steps_slider.h_slider.editable = true
steps_slider.config_value.text = str(steps_slider.h_slider.value)

func _on_ControlType_item_selected(index: int) -> void:
# Adaptive doesn't have steps
if index != 0:
steps_slider.set_max_value(40)
else:
steps_slider.reset_max_value()


func _connect_hover_signals() -> void:
for node in [
negative_prompt,
Expand Down Expand Up @@ -725,7 +728,6 @@ func _on_load_from_disk_gensettings_loaded(settings) -> void:
for idx in range(control_type.get_item_count()):
if control_type.get_item_text(idx) == settings["control_type"]:
control_type.select(idx)
_on_ControlType_item_selected(idx)
if settings.has("source_image_path"):
if image_preview.load_image_from_path(settings["source_image_path"]):
stable_horde_client.source_image = image_preview.source_image
Expand Down
62 changes: 33 additions & 29 deletions addons/stable_horde_client/civitai_lora_model_fetch.gd
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ func process_request(json_ret) -> void:
func _parse_civitai_lora_data(civitai_entry) -> Dictionary:
var lora_details = {
"name": civitai_entry["name"],
"id": int(civitai_entry["id"]),
"id": str(civitai_entry["id"]),
"description": civitai_entry["description"],
"unusable": '',
"nsfw": civitai_entry["nsfw"],
"sha256": null,
}
if not lora_details["description"]:
lora_details["description"] = ''
Expand Down Expand Up @@ -87,31 +84,38 @@ func _parse_civitai_lora_data(civitai_entry) -> Dictionary:
lora_details["description"] = lora_details["description"].replace(repl,html_to_bbcode[repl])
if lora_details["description"].length() > 500:
lora_details["description"] = lora_details["description"].left(700) + ' [...]'
var versions = civitai_entry.get("modelVersions", {})
var versions : Array = civitai_entry.get("modelVersions", {})
if versions.size() == 0:
return lora_details
lora_details["triggers"] = versions[0]["trainedWords"]
lora_details["version"] = versions[0]["name"]
lora_details["base_model"] = versions[0]["baseModel"]
for file in versions[0]["files"]:
if not file.get("name", "").ends_with(".safetensors"):
continue
lora_details["size_mb"] = round(file["sizeKB"] / 1024)
# We only store these two to check if they would be present in the workers
lora_details["sha256"] = file.get("hashes", {}).get("SHA256")
lora_details["url"] = file.get("downloadUrl", "")
# If these two fields are not defined, the workers are not going to download it
# so we ignore it as well
var is_default = int(lora_details["id"]) in default_ids
if not is_default and not lora_details["sha256"]:
lora_details["unusable"] = 'Attention! This LoRa is unusable because it does not provide file validation.'
elif not lora_details["url"]:
lora_details["unusable"] = 'Attention! This LoRa is unusable because it appears to have no valid safetensors upload.'
elif not is_default and lora_details["size_mb"] > 230:
lora_details["unusable"] = 'Attention! This LoRa is unusable because is exceeds the max 230Mb filesize we allow on the AI Horde.'
lora_details["images"] = []
for img in versions[0]["images"]:
if img["nsfw"] in ["Mature", "X"]:
continue
lora_details["images"].append(img["url"])
lora_details["versions"] = {}
for version in versions:
var version_id := str(version["id"])
var new_version := {
"unusable": '',
}
new_version["id"] = version_id
new_version["triggers"] = version["trainedWords"]
new_version["name"] = version["name"]
new_version["base_model"] = version["baseModel"]
for file in version["files"]:
if not file.get("name", "").ends_with(".safetensors"):
continue
new_version["size_mb"] = round(file["sizeKB"] / 1024)
# We only store these two to check if they would be present in the workers
new_version["sha256"] = file.get("hashes", {}).get("SHA256")
new_version["url"] = file.get("downloadUrl", "")
# If these two fields are not defined, the workers are not going to download it
# so we ignore it as well
if not new_version.get("sha256"):
new_version["unusable"] = 'Attention! This LoRa is unusable because it does not provide file validation.'
elif not new_version.get("url"):
new_version["unusable"] = 'Attention! This LoRa is unusable because it appears to have no valid safetensors upload.'
elif new_version["size_mb"] > 230 and not default_ids.has(lora_details["id"]):
new_version["unusable"] = 'Attention! This LoRa is unusable because is exceeds the max 230Mb filesize we allow on the AI Horde.'
new_version["images"] = []
for img in version["images"]:
if img["nsfw"] in ["Mature", "X"]:
continue
new_version["images"].append(img["url"])
lora_details["versions"][version_id] = new_version
return lora_details
Loading

0 comments on commit 6e58d3a

Please sign in to comment.