amisima commited on
Commit
48fa4bb
·
verified ·
1 Parent(s): 8b6d7e9

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +71 -4
  2. app.py +0 -0
  3. lora_catalog.json +226 -0
  4. lora_loader.py +259 -139
README.md CHANGED
@@ -1,12 +1,79 @@
1
  ---
2
- title: Wan2.2 14B Custom Lora
3
- emoji: 🏆
4
  colorFrom: indigo
5
  colorTo: pink
6
  sdk: gradio
7
- sdk_version: 6.0.1
8
  app_file: app.py
9
  pinned: false
 
 
 
 
 
 
 
 
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Wan 2.2 I2V 14B · Custom lora
3
+ emoji: 🎬
4
  colorFrom: indigo
5
  colorTo: pink
6
  sdk: gradio
7
+ sdk_version: 6.24.0
8
  app_file: app.py
9
  pinned: false
10
+ short_description: Image to video with your own lora, from HF or CivitAI
11
+ tags:
12
+ - not-for-all-audiences
13
+ - video
14
+ - image-to-video
15
+ - wan
16
+ - wan2.2
17
+ - lora
18
+ - zerogpu
19
  ---
20
 
21
+ # Wan 2.2 I2V 14B · Custom lora
22
+
23
+ Turn a still image into smooth cinematic motion, with your own adapters, and without guessing what a
24
+ run will cost.
25
+
26
+ ## Please read before uploading a photograph
27
+
28
+ Upload only photographs of yourself, or of people who have agreed to this. **Sexual imagery of a real
29
+ person, made without that person's consent, breaks Hugging Face's
30
+ [content policy](https://huggingface.co/content-policy) and is not welcome here.** The same applies to
31
+ anything involving a minor, in any form, without exception.
32
+
33
+ This Space is tagged *Not For All Audiences*: adapters loaded into it may produce adult material, and
34
+ what a visitor loads is their own responsibility under that policy.
35
+
36
+ ## What is in here
37
+
38
+ **Your own lora, from anywhere.** Five slots that take a Hugging Face repo, a file inside one, or a
39
+ CivitAI download link pasted into the High or Low box — Wan adapters ship their two halves as separate
40
+ files, so each slot has one box for each. Downloads are cached, and CivitAI's domains are tried in turn,
41
+ because one of them will sometimes answer a datacentre address with a Cloudflare challenge while
42
+ another does not. A gated model needs `CIVITAI_TOKEN` under *Settings → Variables and secrets*: the
43
+ Space downloads on its own machine, so being signed in to CivitAI in a browser does not authenticate it.
44
+
45
+ **Search CivitAI from inside the Space.** A word gets you the title, version, file, size, downloads,
46
+ base model and trigger words, and one press drops the result into a slot. A link already in a slot can
47
+ be named the same way, so a row reads its real title rather than a number.
48
+
49
+ **Built-in presets, kept private.** The catalogue of bundled adapters is not in this repository. It is
50
+ read at start-up from a private repo named by `LORA_CATALOG_REPO`; with the variable unset the Space
51
+ starts with no presets and the custom slots still work.
52
+
53
+ **Fast options.** Speed presets that set steps, flow shift and scheduler in one click, including the
54
+ lightx2v Lightning adapters at 4, 6 and 8 steps. The checkpoint is a Lightning merge already, so
55
+ *Built-in* is where to start.
56
+
57
+ **ZeroGPU cost, before you press the button.** The readout above Generate uses the same formula the
58
+ Space reserves with, so heavy settings show as a number rather than as a run that dies mid-way.
59
+
60
+ **Continue the scene.** One press takes the last frame, generates from it with the settings untouched,
61
+ and joins the two clips into one file. Press again for a third.
62
+
63
+ **Clip stitching and looping, on the CPU.** Queue clips into a single file; boomerang the whole clip or
64
+ just its tail. None of it touches the GPU allowance.
65
+
66
+ **A prompt builder** that wraps what you typed in shot, lens, light and pacing language, and optionally
67
+ rewrites it with a small local language model.
68
+
69
+ **Named profiles**, saved under a name and recalled from a dropdown, or exported as `.json`.
70
+
71
+ **Tall and wide images.** The checkpoint accepts 480–832 px per side, so anything past 1.73:1 has to
72
+ give: choose between cropping the middle out and keeping the whole picture between black bars.
73
+
74
+ ## Notes
75
+
76
+ * fp8 quantized, AoT compiled, with RIFE interpolation for smoother motion.
77
+ * An adapter carrying bias tensors cannot be loaded into a torchao-quantized layer, so the bias is
78
+ dropped and the rest of the adapter is loaded rather than the whole thing failing.
79
+ * Profiles live inside the Space, and are visible to everyone who opens it.
app.py CHANGED
The diff for this file is too large to render. See raw diff
 
lora_catalog.json ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "baseline_repo": "lkzd7/WAN2.2_LoraSet_NSFW",
3
+ "pinned_revisions": {
4
+ "lkzd7/WAN2.2_LoraSet_NSFW": "ccfa867ce4b1",
5
+ "Lythiga/WAN2.2_I2V_Lora": "67ef542e6faa",
6
+ "rolechar/rc_wan2.2_i2v_loraset_nsfw_private": "4855a2f216ac",
7
+ "lopi999/Wan2.2-I2V_General-NSFW-LoRA": "aeef17d7fa51"
8
+ },
9
+ "baseline_files": [
10
+ "Blink_Squatting_Cowgirl_Position_I2V_HIGH.safetensors",
11
+ "Blink_Squatting_Cowgirl_Position_I2V_LOW.safetensors",
12
+ "PENISLORA_22_i2v_HIGH_e320.safetensors",
13
+ "PENISLORA_22_i2v_LOW_e496.safetensors",
14
+ "Pornmaster_wan 2.2_14b_I2V_bukkake_v1.4_high_noise.safetensors",
15
+ "Pornmaster_wan 2.2_14b_I2V_bukkake_v1.4_low_noise.safetensors",
16
+ "W22_Multiscene_Photoshoot_Softcore_i2v_HN.safetensors",
17
+ "W22_Multiscene_Photoshoot_Softcore_i2v_LN.safetensors",
18
+ "WAN-2.2-I2V-Double-Blowjob-HIGH-v1.safetensors",
19
+ "WAN-2.2-I2V-Double-Blowjob-LOW-v1.safetensors",
20
+ "WAN-2.2-I2V-HandjobBlowjobCombo-HIGH-v1.safetensors",
21
+ "WAN-2.2-I2V-HandjobBlowjobCombo-LOW-v1.safetensors",
22
+ "WAN-2.2-I2V-SensualTeasingBlowjob-HIGH-v1.safetensors",
23
+ "WAN-2.2-I2V-SensualTeasingBlowjob-LOW-v1.safetensors",
24
+ "iGOON_Blink_Blowjob_I2V_HIGH.safetensors",
25
+ "iGOON_Blink_Blowjob_I2V_LOW.safetensors",
26
+ "iGoon - Blink_Front_Doggystyle_I2V_HIGH.safetensors",
27
+ "iGoon - Blink_Front_Doggystyle_I2V_LOW.safetensors",
28
+ "iGoon - Blink_Missionary_I2V_HIGH.safetensors",
29
+ "iGoon - Blink_Missionary_I2V_LOW v2.safetensors",
30
+ "iGoon - Blink_Missionary_I2V_LOW.safetensors",
31
+ "iGoon%20-%20Blink_Back_Doggystyle_HIGH.safetensors",
32
+ "iGoon%20-%20Blink_Back_Doggystyle_LOW.safetensors",
33
+ "iGoon%20-%20Blink_Facial_I2V_HIGH.safetensors",
34
+ "iGoon%20-%20Blink_Facial_I2V_LOW.safetensors",
35
+ "iGoon_Blink_Missionary_I2V_HIGH v2.safetensors",
36
+ "iGoon_Blink_Titjob_I2V_HIGH.safetensors",
37
+ "iGoon_Blink_Titjob_I2V_LOW.safetensors",
38
+ "lips-bj_high_noise.safetensors",
39
+ "lips-bj_low_noise.safetensors",
40
+ "mql_casting_sex_doggy_kneel_diagonally_behind_vagina_wan22_i2v_v1_high_noise.safetensors",
41
+ "mql_casting_sex_doggy_kneel_diagonally_behind_vagina_wan22_i2v_v1_low_noise.safetensors",
42
+ "mql_casting_sex_reverse_cowgirl_lie_front_vagina_wan22_i2v_v1_high_noise.safetensors",
43
+ "mql_casting_sex_reverse_cowgirl_lie_front_vagina_wan22_i2v_v1_low_noise.safetensors",
44
+ "mql_casting_sex_spoon_wan22_i2v_v1_high_noise.safetensors",
45
+ "mql_casting_sex_spoon_wan22_i2v_v1_low_noise.safetensors",
46
+ "mql_massage_tits_wan22_i2v_v1_high_noise.safetensors",
47
+ "mql_massage_tits_wan22_i2v_v1_low_noise.safetensors",
48
+ "mql_panties_aside_wan22_i2v_v1_high_noise.safetensors",
49
+ "mql_panties_aside_wan22_i2v_v1_low_noise.safetensors",
50
+ "sfbehind_v2.1_high_noise.safetensors",
51
+ "sfbehind_v2.1_low_noise.safetensors",
52
+ "sid3l3g_transition_v2.0_H.safetensors",
53
+ "sid3l3g_transition_v2.0_L.safetensors",
54
+ "wan2.2_i2v_high_ulitmate_pussy_asshole.safetensors",
55
+ "wan2.2_i2v_low_ulitmate_pussy_asshole.safetensors",
56
+ "wan22-mouthfull-140epoc-high-k3nk.safetensors",
57
+ "wan22-mouthfull-152epoc-low-k3nk.safetensors"
58
+ ],
59
+ "extra": {
60
+ "Ultimate Deepthroat": [
61
+ "Lythiga/WAN2.2_I2V_Lora",
62
+ "wan22-ultimatedeepthroat-i2v-102epoc-high-k3nk.safetensors",
63
+ "wan22-ultimatedeepthroat-I2V-101epoc-low-k3nk.safetensors"
64
+ ],
65
+ "BBC Deepthroat": [
66
+ "Lythiga/WAN2.2_I2V_Lora",
67
+ "wan22-bbcdeepthroat-115epoc-high-k3nk.safetensors",
68
+ "wan22-bbcdeepthroat-155epoc-low-720-k3nk.safetensors"
69
+ ],
70
+ "Throat V2": [
71
+ "Lythiga/WAN2.2_I2V_Lora",
72
+ "Wan22_ThroatV2_High.safetensors",
73
+ "Wan22_ThroatV2_Low.safetensors"
74
+ ],
75
+ "JFJ Deepthroat": [
76
+ "Lythiga/WAN2.2_I2V_Lora",
77
+ "jfj-deepthroat-W22-I2V-HN.safetensors",
78
+ null
79
+ ],
80
+ "BBC Blowjob Extreme": [
81
+ "Lythiga/WAN2.2_I2V_Lora",
82
+ "BBC Blowjobs Extreme_high_noise.safetensors",
83
+ "BBC Blowjobs Extreme_low_noise.safetensors"
84
+ ],
85
+ "POV Blowjob": [
86
+ "Lythiga/WAN2.2_I2V_Lora",
87
+ "Pov_Blowjob_Wan2.2_high_I2V_v1.0.safetensors",
88
+ null
89
+ ],
90
+ "Cunnilingus": [
91
+ "Lythiga/WAN2.2_I2V_Lora",
92
+ "wan22-cunilingus-I2V-106epoc-high.safetensors",
93
+ "wan22-cunilingus-I2V-72epoc-low.safetensors"
94
+ ],
95
+ "Reverse Cowgirl v2": [
96
+ "Lythiga/WAN2.2_I2V_Lora",
97
+ "wan22.r3v3rs3_c0wg1rl-14b-High-i2v_e70.safetensors",
98
+ "wan22.r3v3rs3_c0wg1rl-14b-Low-i2v_e70.safetensors"
99
+ ],
100
+ "Doggy Front View v2": [
101
+ "Lythiga/WAN2.2_I2V_Lora",
102
+ "doggy_style_sex_front_view_Wan2.2_I2V_high_v1.0.safetensors",
103
+ "doggy_style_sex_front_view_Wan2.2_I2V_Low_v1.0.safetensors"
104
+ ],
105
+ "Fucked From Behind": [
106
+ "Lythiga/WAN2.2_I2V_Lora",
107
+ "derpfuckedfrombehind_000002125_high_noise.safetensors",
108
+ "derpfuckedfrombehind_000002125_low_noise.safetensors"
109
+ ],
110
+ "Prone Bone": [
111
+ "Lythiga/WAN2.2_I2V_Lora",
112
+ "Pronebone_high_noise.safetensors",
113
+ "Pronebone_low_noise.safetensors"
114
+ ],
115
+ "Reverse Suspended Congress": [
116
+ "Lythiga/WAN2.2_I2V_Lora",
117
+ "reverse_suspended_congress_I2V_high.safetensors",
118
+ "reverse_suspended_congress_I2V_low.safetensors"
119
+ ],
120
+ "POV Missionary": [
121
+ "Lythiga/WAN2.2_I2V_Lora",
122
+ "wan2.2_i2v_highnoise_pov_missionary_v1.0.safetensors",
123
+ "wan2.2_i2v_lownoise_pov_missionary_v1.0.safetensors"
124
+ ],
125
+ "Mating Press": [
126
+ "Lythiga/WAN2.2_I2V_Lora",
127
+ "mating_press_high.safetensors",
128
+ "mating_press_low.safetensors"
129
+ ],
130
+ "Standing Upright Sex": [
131
+ "Lythiga/WAN2.2_I2V_Lora",
132
+ "Upright_sex_Wan2.2_14B_TI2V_HIGH_v1.0.safetensors",
133
+ "Upright_sex_Wan2.2_14B_TI2V_LOW_v1.0.safetensors"
134
+ ],
135
+ "Oral Insertion": [
136
+ "Lythiga/WAN2.2_I2V_Lora",
137
+ "wan2.2-i2v-high-oral-insertion-v1.0.safetensors",
138
+ "wan2.2-i2v-low-oral-insertion-v1.0.safetensors"
139
+ ],
140
+ "Handjob": [
141
+ "Lythiga/WAN2.2_I2V_Lora",
142
+ "WAN-2.2-I2V-Handjob-HIGH-v1.safetensors",
143
+ "WAN-2.2-I2V-Handjob-LOW-v1.safetensors"
144
+ ],
145
+ "Balls Sucking": [
146
+ "Lythiga/WAN2.2_I2V_Lora",
147
+ "WAN-2.2-I2V_Balls_sucking_High_noise.safetensors",
148
+ "WAN-2.2-I2V_Balls_sucking_Low_noise.safetensors"
149
+ ],
150
+ "Fingering": [
151
+ "rolechar/rc_wan2.2_i2v_loraset_nsfw_private",
152
+ "Sensual_fingering_v1_high_noise.safetensors",
153
+ "Sensual_fingering_v1_low_noise.safetensors"
154
+ ],
155
+ "Facesplash Cumshot": [
156
+ "Lythiga/WAN2.2_I2V_Lora",
157
+ "wan22-f4c3spl4sh-100epoc-high-k3nk.safetensors",
158
+ "wan22-f4c3spl4sh-154epoc-low-k3nk.safetensors"
159
+ ],
160
+ "Creampie CRM": [
161
+ "Lythiga/WAN2.2_I2V_Lora",
162
+ "Creampie CRM-FULL-EPOCH-80-HIGH.safetensors",
163
+ "Creampie CRM-FULL-EPOCH-80-LOW.safetensors"
164
+ ],
165
+ "Pornmaster Creampie": [
166
+ "Lythiga/WAN2.2_I2V_Lora",
167
+ "Pornmaster_wan 2.2_14b_I2V_Creampie_v1_high_noise.safetensors",
168
+ "Pornmaster_wan 2.2_14b_I2V_Creampie_v1_low_noise.safetensors"
169
+ ],
170
+ "Cum (generic)": [
171
+ "Lythiga/WAN2.2_I2V_Lora",
172
+ "Wan22_Cum_high_noise_1.V1.safetensors",
173
+ "Wan22_Cum_low_noise_1.V1.safetensors"
174
+ ],
175
+ "French Kiss": [
176
+ "Lythiga/WAN2.2_I2V_Lora",
177
+ "WAN2.2-FrenchKiss_HighNoise.safetensors",
178
+ "WAN2.2-FrenchKiss_LowNoise.safetensors"
179
+ ],
180
+ "Twerking": [
181
+ "Lythiga/WAN2.2_I2V_Lora",
182
+ "Twerking_I2V_high_noise.safetensors",
183
+ "Twerking_I2V_low_noise.safetensors"
184
+ ],
185
+ "Ahegao Drooling": [
186
+ "rolechar/rc_wan2.2_i2v_loraset_nsfw_private",
187
+ "middlefinger_drooling_ahegao_high.safetensors",
188
+ "middlefinger_drooling_ahegao_low.safetensors"
189
+ ],
190
+ "General NSFW Booster": [
191
+ "lopi999/Wan2.2-I2V_General-NSFW-LoRA",
192
+ "NSFW-22-H-e8.safetensors",
193
+ "NSFW-22-L-e8.safetensors"
194
+ ],
195
+ "Penetration Insert": [
196
+ "Lythiga/WAN2.2_I2V_Lora",
197
+ "PenInsert_high_noise.safetensors",
198
+ "PenInsert_low_noise.safetensors"
199
+ ],
200
+ "Biggest Cock (size)": [
201
+ "Lythiga/WAN2.2_I2V_Lora",
202
+ "WAN-2.2-I2V_BiggestCock_high_noise_V1.safetensors",
203
+ "WAN-2.2-I2V_BiggestCock_low_noise_V1.safetensors"
204
+ ],
205
+ "Doggy Slider": [
206
+ "Lythiga/WAN2.2_I2V_Lora",
207
+ "I2V_doggyslider_high.safetensors",
208
+ "I2V_doggyslider_low.safetensors"
209
+ ],
210
+ "Pussy Helper": [
211
+ "rolechar/rc_wan2.2_i2v_loraset_nsfw_private",
212
+ "wan2.2_i2v_ulitmate_pussy_helper_high.safetensors",
213
+ "wan2.2_i2v_ulitmate_pussy_helper_low.safetensors"
214
+ ],
215
+ "FOV Slider (camera)": [
216
+ "Lythiga/WAN2.2_I2V_Lora",
217
+ "wan2.2-i2v-high-sex-fov-slider-v1.0.safetensors",
218
+ "wan2.2-i2v-low-sex-fov-slider-v1.0.safetensors"
219
+ ],
220
+ "Smashcut (camera)": [
221
+ "rolechar/rc_wan2.2_i2v_loraset_nsfw_private",
222
+ "wan2.2-i2v-sex-smashcut-v1.0-high.safetensors",
223
+ "wan2.2-i2v-sex-smashcut-v1.0-low.safetensors"
224
+ ]
225
+ }
226
+ }
lora_loader.py CHANGED
@@ -1,133 +1,96 @@
1
  """
2
- LoRA Loader for WAN 2.2 I2V - multi-repo.
3
- Baseline: lkzd7/WAN2.2_LoraSet_NSFW. Plus curated I2V act/helper LoRAs from
4
- Lythiga/WAN2.2_I2V_Lora, rolechar/rc_wan2.2_i2v_loraset_nsfw_private,
5
- lopi999/Wan2.2-I2V_General-NSFW-LoRA. T2V / lightning / furry / dance / male-char filtered out.
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  """
 
 
7
  import os
8
- import urllib.parse
9
  import re
 
 
 
 
10
  from huggingface_hub import hf_hub_download, list_repo_files
11
 
12
- LORA_REPO = "lkzd7/WAN2.2_LoraSet_NSFW"
13
  HF_TOKEN = os.environ.get("HF_TOKEN")
14
 
15
- PINNED_REVISIONS = {
16
- "lkzd7/WAN2.2_LoraSet_NSFW": "ccfa867ce4b1",
17
- "Lythiga/WAN2.2_I2V_Lora": "67ef542e6faa",
18
- "rolechar/rc_wan2.2_i2v_loraset_nsfw_private": "4855a2f216ac",
19
- "lopi999/Wan2.2-I2V_General-NSFW-LoRA": "aeef17d7fa51",
20
- }
21
-
22
- LORA_FILES = [
23
- "Blink_Squatting_Cowgirl_Position_I2V_HIGH.safetensors",
24
- "Blink_Squatting_Cowgirl_Position_I2V_LOW.safetensors",
25
- "PENISLORA_22_i2v_HIGH_e320.safetensors",
26
- "PENISLORA_22_i2v_LOW_e496.safetensors",
27
- "Pornmaster_wan 2.2_14b_I2V_bukkake_v1.4_high_noise.safetensors",
28
- "Pornmaster_wan 2.2_14b_I2V_bukkake_v1.4_low_noise.safetensors",
29
- "W22_Multiscene_Photoshoot_Softcore_i2v_HN.safetensors",
30
- "W22_Multiscene_Photoshoot_Softcore_i2v_LN.safetensors",
31
- "WAN-2.2-I2V-Double-Blowjob-HIGH-v1.safetensors",
32
- "WAN-2.2-I2V-Double-Blowjob-LOW-v1.safetensors",
33
- "WAN-2.2-I2V-HandjobBlowjobCombo-HIGH-v1.safetensors",
34
- "WAN-2.2-I2V-HandjobBlowjobCombo-LOW-v1.safetensors",
35
- "WAN-2.2-I2V-SensualTeasingBlowjob-HIGH-v1.safetensors",
36
- "WAN-2.2-I2V-SensualTeasingBlowjob-LOW-v1.safetensors",
37
- "iGOON_Blink_Blowjob_I2V_HIGH.safetensors",
38
- "iGOON_Blink_Blowjob_I2V_LOW.safetensors",
39
- "iGoon - Blink_Front_Doggystyle_I2V_HIGH.safetensors",
40
- "iGoon - Blink_Front_Doggystyle_I2V_LOW.safetensors",
41
- "iGoon - Blink_Missionary_I2V_HIGH.safetensors",
42
- "iGoon - Blink_Missionary_I2V_LOW v2.safetensors",
43
- "iGoon - Blink_Missionary_I2V_LOW.safetensors",
44
- "iGoon%20-%20Blink_Back_Doggystyle_HIGH.safetensors",
45
- "iGoon%20-%20Blink_Back_Doggystyle_LOW.safetensors",
46
- "iGoon%20-%20Blink_Facial_I2V_HIGH.safetensors",
47
- "iGoon%20-%20Blink_Facial_I2V_LOW.safetensors",
48
- "iGoon_Blink_Missionary_I2V_HIGH v2.safetensors",
49
- "iGoon_Blink_Titjob_I2V_HIGH.safetensors",
50
- "iGoon_Blink_Titjob_I2V_LOW.safetensors",
51
- "lips-bj_high_noise.safetensors",
52
- "lips-bj_low_noise.safetensors",
53
- "mql_casting_sex_doggy_kneel_diagonally_behind_vagina_wan22_i2v_v1_high_noise.safetensors",
54
- "mql_casting_sex_doggy_kneel_diagonally_behind_vagina_wan22_i2v_v1_low_noise.safetensors",
55
- "mql_casting_sex_reverse_cowgirl_lie_front_vagina_wan22_i2v_v1_high_noise.safetensors",
56
- "mql_casting_sex_reverse_cowgirl_lie_front_vagina_wan22_i2v_v1_low_noise.safetensors",
57
- "mql_casting_sex_spoon_wan22_i2v_v1_high_noise.safetensors",
58
- "mql_casting_sex_spoon_wan22_i2v_v1_low_noise.safetensors",
59
- "mql_massage_tits_wan22_i2v_v1_high_noise.safetensors",
60
- "mql_massage_tits_wan22_i2v_v1_low_noise.safetensors",
61
- "mql_panties_aside_wan22_i2v_v1_high_noise.safetensors",
62
- "mql_panties_aside_wan22_i2v_v1_low_noise.safetensors",
63
- "sfbehind_v2.1_high_noise.safetensors",
64
- "sfbehind_v2.1_low_noise.safetensors",
65
- "sid3l3g_transition_v2.0_H.safetensors",
66
- "sid3l3g_transition_v2.0_L.safetensors",
67
- "wan2.2_i2v_high_ulitmate_pussy_asshole.safetensors",
68
- "wan2.2_i2v_low_ulitmate_pussy_asshole.safetensors",
69
- "wan22-mouthfull-140epoc-high-k3nk.safetensors",
70
- "wan22-mouthfull-152epoc-low-k3nk.safetensors",
71
- ]
72
-
73
- LORA_PAIRS = {}
74
- for f in LORA_FILES:
75
- name = urllib.parse.unquote(f).replace(".safetensors", "")
76
- is_high = bool(re.search(r'(high|HN|_H\b)', name, re.IGNORECASE))
77
- is_low = bool(re.search(r'(low|LN|_L\b)', name, re.IGNORECASE))
78
- group = re.sub(r'[\s_-]*(high|low|noise|HN|LN)([\s_-]*noise)?[\s_-]*(v?\d+(\.\d+)?)?\s*$', '', name, flags=re.IGNORECASE).strip()
79
- group = re.sub(r'[\s_]+$', '', group)
80
- LORA_PAIRS.setdefault(group, {"HIGH": None, "LOW": None})
81
- if is_high:
82
- LORA_PAIRS[group]["HIGH"] = (LORA_REPO, f)
83
- elif is_low:
84
- LORA_PAIRS[group]["LOW"] = (LORA_REPO, f)
85
-
86
- L = "Lythiga/WAN2.2_I2V_Lora"
87
- R = "rolechar/rc_wan2.2_i2v_loraset_nsfw_private"
88
- P = "lopi999/Wan2.2-I2V_General-NSFW-LoRA"
89
-
90
- EXTRA = {
91
- "Ultimate Deepthroat": (L, "wan22-ultimatedeepthroat-i2v-102epoc-high-k3nk.safetensors", "wan22-ultimatedeepthroat-I2V-101epoc-low-k3nk.safetensors"),
92
- "BBC Deepthroat": (L, "wan22-bbcdeepthroat-115epoc-high-k3nk.safetensors", "wan22-bbcdeepthroat-155epoc-low-720-k3nk.safetensors"),
93
- "Throat V2": (L, "Wan22_ThroatV2_High.safetensors", "Wan22_ThroatV2_Low.safetensors"),
94
- "JFJ Deepthroat": (L, "jfj-deepthroat-W22-I2V-HN.safetensors", None),
95
- "BBC Blowjob Extreme": (L, "BBC Blowjobs Extreme_high_noise.safetensors", "BBC Blowjobs Extreme_low_noise.safetensors"),
96
- "POV Blowjob": (L, "Pov_Blowjob_Wan2.2_high_I2V_v1.0.safetensors", None),
97
- "Cunnilingus": (L, "wan22-cunilingus-I2V-106epoc-high.safetensors", "wan22-cunilingus-I2V-72epoc-low.safetensors"),
98
- "Reverse Cowgirl v2": (L, "wan22.r3v3rs3_c0wg1rl-14b-High-i2v_e70.safetensors", "wan22.r3v3rs3_c0wg1rl-14b-Low-i2v_e70.safetensors"),
99
- "Doggy Front View v2": (L, "doggy_style_sex_front_view_Wan2.2_I2V_high_v1.0.safetensors", "doggy_style_sex_front_view_Wan2.2_I2V_Low_v1.0.safetensors"),
100
- "Fucked From Behind": (L, "derpfuckedfrombehind_000002125_high_noise.safetensors", "derpfuckedfrombehind_000002125_low_noise.safetensors"),
101
- "Prone Bone": (L, "Pronebone_high_noise.safetensors", "Pronebone_low_noise.safetensors"),
102
- "Reverse Suspended Congress": (L, "reverse_suspended_congress_I2V_high.safetensors", "reverse_suspended_congress_I2V_low.safetensors"),
103
- "POV Missionary": (L, "wan2.2_i2v_highnoise_pov_missionary_v1.0.safetensors", "wan2.2_i2v_lownoise_pov_missionary_v1.0.safetensors"),
104
- "Mating Press": (L, "mating_press_high.safetensors", "mating_press_low.safetensors"),
105
- "Standing Upright Sex": (L, "Upright_sex_Wan2.2_14B_TI2V_HIGH_v1.0.safetensors", "Upright_sex_Wan2.2_14B_TI2V_LOW_v1.0.safetensors"),
106
- "Oral Insertion": (L, "wan2.2-i2v-high-oral-insertion-v1.0.safetensors", "wan2.2-i2v-low-oral-insertion-v1.0.safetensors"),
107
- "Handjob": (L, "WAN-2.2-I2V-Handjob-HIGH-v1.safetensors", "WAN-2.2-I2V-Handjob-LOW-v1.safetensors"),
108
- "Balls Sucking": (L, "WAN-2.2-I2V_Balls_sucking_High_noise.safetensors", "WAN-2.2-I2V_Balls_sucking_Low_noise.safetensors"),
109
- "Fingering": (R, "Sensual_fingering_v1_high_noise.safetensors", "Sensual_fingering_v1_low_noise.safetensors"),
110
- "Facesplash Cumshot": (L, "wan22-f4c3spl4sh-100epoc-high-k3nk.safetensors", "wan22-f4c3spl4sh-154epoc-low-k3nk.safetensors"),
111
- "Creampie CRM": (L, "Creampie CRM-FULL-EPOCH-80-HIGH.safetensors", "Creampie CRM-FULL-EPOCH-80-LOW.safetensors"),
112
- "Pornmaster Creampie": (L, "Pornmaster_wan 2.2_14b_I2V_Creampie_v1_high_noise.safetensors", "Pornmaster_wan 2.2_14b_I2V_Creampie_v1_low_noise.safetensors"),
113
- "Cum (generic)": (L, "Wan22_Cum_high_noise_1.V1.safetensors", "Wan22_Cum_low_noise_1.V1.safetensors"),
114
- "French Kiss": (L, "WAN2.2-FrenchKiss_HighNoise.safetensors", "WAN2.2-FrenchKiss_LowNoise.safetensors"),
115
- "Twerking": (L, "Twerking_I2V_high_noise.safetensors", "Twerking_I2V_low_noise.safetensors"),
116
- "Ahegao Drooling": (R, "middlefinger_drooling_ahegao_high.safetensors", "middlefinger_drooling_ahegao_low.safetensors"),
117
- "General NSFW Booster": (P, "NSFW-22-H-e8.safetensors", "NSFW-22-L-e8.safetensors"),
118
- "Penetration Insert": (L, "PenInsert_high_noise.safetensors", "PenInsert_low_noise.safetensors"),
119
- "Biggest Cock (size)": (L, "WAN-2.2-I2V_BiggestCock_high_noise_V1.safetensors", "WAN-2.2-I2V_BiggestCock_low_noise_V1.safetensors"),
120
- "Doggy Slider": (L, "I2V_doggyslider_high.safetensors", "I2V_doggyslider_low.safetensors"),
121
- "Pussy Helper": (R, "wan2.2_i2v_ulitmate_pussy_helper_high.safetensors", "wan2.2_i2v_ulitmate_pussy_helper_low.safetensors"),
122
- "FOV Slider (camera)": (L, "wan2.2-i2v-high-sex-fov-slider-v1.0.safetensors", "wan2.2-i2v-low-sex-fov-slider-v1.0.safetensors"),
123
- "Smashcut (camera)": (R, "wan2.2-i2v-sex-smashcut-v1.0-high.safetensors", "wan2.2-i2v-sex-smashcut-v1.0-low.safetensors"),
124
- }
125
- for label, (repo, hi, lo) in EXTRA.items():
126
- LORA_PAIRS.setdefault(label, {"HIGH": None, "LOW": None})
127
- if hi:
128
- LORA_PAIRS[label]["HIGH"] = (repo, hi)
129
- if lo:
130
- LORA_PAIRS[label]["LOW"] = (repo, lo)
131
 
132
 
133
  def get_lora_choices():
@@ -172,7 +135,13 @@ def parse_hf_file_link(link: str):
172
 
173
 
174
  def list_loras_from_repo(repo_link: str):
175
- repo_id = parse_repo_link(repo_link)
 
 
 
 
 
 
176
  if not repo_id:
177
  return ["(None)"]
178
  try:
@@ -187,7 +156,7 @@ def list_loras_from_repo(repo_link: str):
187
  def download_lora(group_name):
188
  if not group_name:
189
  return None, None
190
- clean_name = re.sub(r'\s*$$HIGH only$$|\s*$$LOW only$$', '', group_name)
191
  if clean_name not in LORA_PAIRS:
192
  return None, None
193
  pair = LORA_PAIRS[clean_name]
@@ -201,9 +170,124 @@ def download_lora(group_name):
201
  return high_path, low_path
202
 
203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  def download_repo_file(repo_link: str, filename: str):
205
  if not filename or filename == "(None)":
206
  return None
 
 
 
 
 
 
 
 
 
 
 
207
  repo_from_file, weight = parse_hf_file_link(filename)
208
  if repo_from_file and weight:
209
  return hf_hub_download(
@@ -219,12 +303,55 @@ def download_repo_file(repo_link: str, filename: str):
219
  )
220
 
221
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  def _load_path(pipe, path, adapter_name, into_t2=False):
223
  kwargs = {"adapter_name": adapter_name}
224
  if into_t2:
225
  kwargs["load_into_transformer_2"] = True
226
- pipe.load_lora_weights(path, **kwargs)
227
- return adapter_name
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
 
229
 
230
  def load_lora_to_pipe(pipe, group_name, adapter_name="lora", high_scale=1.0, low_scale=1.0):
@@ -233,14 +360,12 @@ def load_lora_to_pipe(pipe, group_name, adapter_name="lora", high_scale=1.0, low
233
  high_path, low_path = download_lora(group_name)
234
  names, weights = [], []
235
  if high_path:
236
- n = f"{adapter_name}_high"
237
- _load_path(pipe, high_path, n, into_t2=False)
238
- names.append(n)
239
  weights.append(float(high_scale))
240
  if low_path:
241
- n = f"{adapter_name}_low"
242
- _load_path(pipe, low_path, n, into_t2=True)
243
- names.append(n)
244
  weights.append(float(low_scale))
245
  if names:
246
  print(f"Loaded preset LoRA: {group_name} scales={weights}")
@@ -269,16 +394,12 @@ def load_lora_slots(pipe, slots):
269
  ls = float(slot.get("low_scale", 1.0) or 1.0)
270
  if fh and fh != "(None)":
271
  path = download_repo_file(repo, fh)
272
- n = f"link_{idx}_high"
273
- _load_path(pipe, path, n, into_t2=False)
274
- all_names.append(n)
275
  all_weights.append(hs)
276
  print(f"Loaded link HIGH: {fh} scale={hs}")
277
  if fl and fl != "(None)":
278
  path = download_repo_file(repo, fl)
279
- n = f"link_{idx}_low"
280
- _load_path(pipe, path, n, into_t2=True)
281
- all_names.append(n)
282
  all_weights.append(ls)
283
  print(f"Loaded link LOW: {fl} scale={ls}")
284
  if all_names:
@@ -293,4 +414,3 @@ def unload_lora(pipe):
293
  pipe.unload_lora_weights()
294
  except Exception:
295
  pass
296
-
 
1
  """
2
+ LoRA loader for WAN 2.2 I2V.
3
+
4
+ The catalogue of built-in adapters is deliberately NOT in this file. It is read at start-up from a
5
+ private repository named by `LORA_CATALOG_REPO`, so nothing in the public Space carries adapter
6
+ names, titles or descriptions - only the machinery that loads whatever the catalogue lists. With the
7
+ variable unset the Space starts with no built-in presets, and every custom slot still works.
8
+
9
+ Set-up, once:
10
+
11
+ 1. create a PRIVATE dataset repo, e.g. `you/wan-lora-catalog`
12
+ 2. upload `lora_catalog.json` to it
13
+ 3. in the Space, Settings -> Variables and secrets:
14
+ LORA_CATALOG_REPO = you/wan-lora-catalog (variable)
15
+ HF_TOKEN = a token that can read it (secret)
16
+
17
+ Also resolves plain download links (CivitAI and anything else serving a .safetensors), so a slot can
18
+ take a URL instead of a repo file.
19
  """
20
+ import hashlib
21
+ import json
22
  import os
 
23
  import re
24
+ import struct
25
+ import tempfile
26
+ import urllib.parse
27
+
28
  from huggingface_hub import hf_hub_download, list_repo_files
29
 
 
30
  HF_TOKEN = os.environ.get("HF_TOKEN")
31
 
32
+ # Where the catalogue lives, and what it is called inside that repo.
33
+ LORA_CATALOG_REPO = os.environ.get("LORA_CATALOG_REPO", "").strip()
34
+ LORA_CATALOG_FILE = os.environ.get("LORA_CATALOG_FILE", "lora_catalog.json").strip()
35
+ LORA_CATALOG_TYPE = os.environ.get("LORA_CATALOG_TYPE", "dataset").strip()
36
+
37
+ LORA_REPO = ""
38
+ PINNED_REVISIONS: dict = {}
39
+ LORA_PAIRS: dict = {}
40
+
41
+
42
+ def _load_catalog() -> None:
43
+ """Read the private catalogue into `LORA_PAIRS`. Failure is not fatal: the Space runs without
44
+ built-in presets, and every custom slot still works."""
45
+ global LORA_REPO, PINNED_REVISIONS
46
+
47
+ if not LORA_CATALOG_REPO:
48
+ print("LORA_CATALOG_REPO is not set - starting with no built-in presets")
49
+ return
50
+
51
+ try:
52
+ path = hf_hub_download(
53
+ LORA_CATALOG_REPO, LORA_CATALOG_FILE,
54
+ repo_type=LORA_CATALOG_TYPE, token=HF_TOKEN,
55
+ )
56
+ with open(path, encoding="utf-8") as handle:
57
+ catalog = json.load(handle)
58
+ except Exception as error:
59
+ print(f"Could not read the catalogue ({type(error).__name__}): no built-in presets")
60
+ return
61
+
62
+ LORA_REPO = catalog.get("baseline_repo", "")
63
+ PINNED_REVISIONS = dict(catalog.get("pinned_revisions") or {})
64
+
65
+ # The baseline repo lists files rather than pairs, so high and low are matched by name.
66
+ for filename in catalog.get("baseline_files") or []:
67
+ name = urllib.parse.unquote(filename).replace(".safetensors", "")
68
+ is_high = bool(re.search(r"(high|HN|_H\b)", name, re.IGNORECASE))
69
+ is_low = bool(re.search(r"(low|LN|_L\b)", name, re.IGNORECASE))
70
+ group = re.sub(
71
+ r"[\s_-]*(high|low|noise|HN|LN)([\s_-]*noise)?[\s_-]*(v?\d+(\.\d+)?)?\s*$",
72
+ "", name, flags=re.IGNORECASE,
73
+ ).strip()
74
+ group = re.sub(r"[\s_]+$", "", group)
75
+ LORA_PAIRS.setdefault(group, {"HIGH": None, "LOW": None})
76
+ if is_high:
77
+ LORA_PAIRS[group]["HIGH"] = (LORA_REPO, filename)
78
+ elif is_low:
79
+ LORA_PAIRS[group]["LOW"] = (LORA_REPO, filename)
80
+
81
+ # The curated entries name their repo and both halves outright.
82
+ for label, entry in (catalog.get("extra") or {}).items():
83
+ repo, high, low = (list(entry) + [None, None, None])[:3]
84
+ LORA_PAIRS.setdefault(label, {"HIGH": None, "LOW": None})
85
+ if high:
86
+ LORA_PAIRS[label]["HIGH"] = (repo, high)
87
+ if low:
88
+ LORA_PAIRS[label]["LOW"] = (repo, low)
89
+
90
+ print(f"Loaded {len(LORA_PAIRS)} built-in presets from the private catalogue")
91
+
92
+
93
+ _load_catalog()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
 
96
  def get_lora_choices():
 
135
 
136
 
137
  def list_loras_from_repo(repo_link: str):
138
+ """Files in a Hugging Face repo. A direct download link is handed back as the
139
+ only choice, so pasting a CivitAI URL into the repo box fills the dropdowns."""
140
+ link = (repo_link or "").strip()
141
+ if is_direct_link(link):
142
+ return ["(None)", link]
143
+
144
+ repo_id = parse_repo_link(link)
145
  if not repo_id:
146
  return ["(None)"]
147
  try:
 
156
  def download_lora(group_name):
157
  if not group_name:
158
  return None, None
159
+ clean_name = re.sub(r'\s*\(HIGH only\)|\s*\(LOW only\)', '', group_name)
160
  if clean_name not in LORA_PAIRS:
161
  return None, None
162
  pair = LORA_PAIRS[clean_name]
 
170
  return high_path, low_path
171
 
172
 
173
+ # ----------------------------------------------------------------------------
174
+ # Direct links (CivitAI and any other plain .safetensors URL)
175
+ # ----------------------------------------------------------------------------
176
+ # The download runs on the Space's machine, not in the visitor's browser, so a
177
+ # CivitAI session in a browser tab does not authenticate it: a gated model
178
+ # answers a server with an HTML login page instead of weights. CIVITAI_TOKEN
179
+ # (Settings -> Variables and secrets) is appended automatically when it is set,
180
+ # and the file header is checked, so a login page fails with a sentence that
181
+ # says what to do rather than a parse error deep inside safetensors.
182
+
183
+ CIVITAI_HOSTS = ("civitai.com", "civitai.red", "civitai.green", "civitai.work")
184
+ CIVITAI_TOKEN = os.environ.get("CIVITAI_TOKEN", "").strip()
185
+
186
+
187
+ def is_direct_link(text: str) -> bool:
188
+ """A URL that is not a huggingface.co link, so a plain file download."""
189
+ text = (text or "").strip().strip('"').strip("'")
190
+ if not text.startswith(("http://", "https://")):
191
+ return False
192
+ host = (urllib.parse.urlparse(text).hostname or "").lower()
193
+ return not host.endswith("huggingface.co")
194
+
195
+
196
+ def _civitai_alternatives(url: str):
197
+ """The same download through each CivitAI domain in turn. They mirror one another, and one of
198
+ them will sometimes answer a datacentre IP with a Cloudflare challenge while another does not."""
199
+ yield url
200
+ host = (urllib.parse.urlparse(url).hostname or "").lower()
201
+ if any(host.endswith(known) for known in CIVITAI_HOSTS):
202
+ for other in CIVITAI_HOSTS:
203
+ if not host.endswith(other):
204
+ yield url.replace(host, other, 1)
205
+
206
+
207
+ def download_direct_link(url: str) -> str:
208
+ import requests
209
+
210
+ url = url.strip().strip('"').strip("'")
211
+ cache_dir = os.path.join(tempfile.gettempdir(), "url-loras")
212
+ os.makedirs(cache_dir, exist_ok=True)
213
+ cached = os.path.join(cache_dir, hashlib.sha256(url.encode()).hexdigest()[:16] + ".safetensors")
214
+ if os.path.exists(cached) and os.path.getsize(cached) > 1_000_000:
215
+ return cached
216
+
217
+ response, host, last = None, "", None
218
+ for candidate in _civitai_alternatives(url):
219
+ host = (urllib.parse.urlparse(candidate).hostname or "").lower()
220
+ request_url = candidate
221
+ if CIVITAI_TOKEN and any(host.endswith(known) for known in CIVITAI_HOSTS) and "token=" not in candidate:
222
+ request_url = candidate + ("&" if "?" in candidate else "?") + f"token={CIVITAI_TOKEN}"
223
+ try:
224
+ attempt = requests.get(request_url, stream=True, timeout=180,
225
+ headers={"User-Agent": "Mozilla/5.0"})
226
+ attempt.raise_for_status()
227
+ except Exception as error:
228
+ # Not quoting the exception: requests puts the URL in its message and the URL carries
229
+ # the token.
230
+ last = f"{type(error).__name__} from {host}"
231
+ print(f"[lora] {last}; trying another CivitAI domain")
232
+ continue
233
+ if "text/html" in (attempt.headers.get("content-type") or "").lower():
234
+ last = f"a web page instead of a file from {host}"
235
+ print(f"[lora] {last}; trying another CivitAI domain")
236
+ continue
237
+ response = attempt
238
+ break
239
+
240
+ if response is None:
241
+ raise ValueError(
242
+ f"Could not fetch that link ({last}). CivitAI sometimes puts a Cloudflare challenge in "
243
+ "front of a datacentre address, and a gated model needs CIVITAI_TOKEN under Settings -> "
244
+ "Variables and secrets. Downloading the file yourself and uploading it always works."
245
+ )
246
+
247
+ written = 0
248
+ with open(cached, "wb") as handle:
249
+ for chunk in response.iter_content(chunk_size=1 << 20):
250
+ if chunk:
251
+ handle.write(chunk)
252
+ written += len(chunk)
253
+
254
+ if written < 1_000_000:
255
+ os.remove(cached)
256
+ raise ValueError(
257
+ "That link returned only a few kilobytes - almost always a login or error page rather "
258
+ "than weights. Check the link, or add CIVITAI_TOKEN to the Space."
259
+ )
260
+
261
+ # safetensors starts with an 8-byte little-endian header length, then that much JSON.
262
+ with open(cached, "rb") as handle:
263
+ length = struct.unpack("<Q", handle.read(8))[0]
264
+ if not (0 < length < 100_000_000):
265
+ os.remove(cached)
266
+ raise ValueError("The downloaded file is not a .safetensors (bad header).")
267
+ try:
268
+ json.loads(handle.read(length).decode("utf-8"))
269
+ except Exception:
270
+ os.remove(cached)
271
+ raise ValueError("The downloaded file is not a .safetensors (unreadable header).")
272
+
273
+ print(f"Downloaded {written / 1e6:.0f} MB from {host}")
274
+ return cached
275
+
276
+
277
  def download_repo_file(repo_link: str, filename: str):
278
  if not filename or filename == "(None)":
279
  return None
280
+
281
+ # A local file (already downloaded, or uploaded into the Space) is used as it is.
282
+ if os.path.exists(filename):
283
+ return filename
284
+
285
+ # A plain download link, in either box.
286
+ if is_direct_link(filename):
287
+ return download_direct_link(filename)
288
+ if is_direct_link(repo_link) and filename == repo_link:
289
+ return download_direct_link(repo_link)
290
+
291
  repo_from_file, weight = parse_hf_file_link(filename)
292
  if repo_from_file and weight:
293
  return hf_hub_download(
 
303
  )
304
 
305
 
306
+ def _strip_lora_bias(state_dict):
307
+ """Drop the adapter's bias terms.
308
+
309
+ This transformer is quantized to fp8 with torchao, and `TorchaoLoraLinear` has no path for a
310
+ LoRA that carries bias - PEFT refuses the whole adapter with "does not support lora_bias".
311
+ The bias is a vector per layer against full weight matrices, so dropping it costs very little
312
+ and is the difference between the adapter working and not loading at all.
313
+ """
314
+ dropped = {key: value for key, value in state_dict.items()
315
+ if not (key.endswith(".bias") or key.endswith(".diff_b"))}
316
+ removed = len(state_dict) - len(dropped)
317
+ if removed:
318
+ print(f"Dropped {removed} bias tensors: a torchao-quantized layer cannot take them")
319
+ return dropped
320
+
321
+
322
  def _load_path(pipe, path, adapter_name, into_t2=False):
323
  kwargs = {"adapter_name": adapter_name}
324
  if into_t2:
325
  kwargs["load_into_transformer_2"] = True
326
+
327
+ try:
328
+ pipe.load_lora_weights(path, **kwargs)
329
+ return adapter_name
330
+ except Exception as error:
331
+ if "lora_bias" not in str(error):
332
+ raise
333
+ print(f"Retrying {os.path.basename(str(path))} without its bias tensors ({error})")
334
+
335
+ # PEFT may already have registered the name before it refused, and a second load under the same
336
+ # name then fails for an unrelated reason. Clear it, and fall back to a fresh name if it will
337
+ # not clear.
338
+ try:
339
+ pipe.delete_adapters(adapter_name)
340
+ except Exception:
341
+ pass
342
+
343
+ from safetensors.torch import load_file
344
+
345
+ state_dict = _strip_lora_bias(load_file(path))
346
+ try:
347
+ pipe.load_lora_weights(state_dict, **kwargs)
348
+ return adapter_name
349
+ except Exception as error:
350
+ if "already" not in str(error).lower():
351
+ raise
352
+ kwargs["adapter_name"] = adapter_name = f"{adapter_name}_nb"
353
+ pipe.load_lora_weights(state_dict, **kwargs)
354
+ return adapter_name
355
 
356
 
357
  def load_lora_to_pipe(pipe, group_name, adapter_name="lora", high_scale=1.0, low_scale=1.0):
 
360
  high_path, low_path = download_lora(group_name)
361
  names, weights = [], []
362
  if high_path:
363
+ # `_load_path` returns the name it registered, which differs from the one asked for when a
364
+ # bias-stripped retry had to fall back to a fresh name.
365
+ names.append(_load_path(pipe, high_path, f"{adapter_name}_high", into_t2=False))
366
  weights.append(float(high_scale))
367
  if low_path:
368
+ names.append(_load_path(pipe, low_path, f"{adapter_name}_low", into_t2=True))
 
 
369
  weights.append(float(low_scale))
370
  if names:
371
  print(f"Loaded preset LoRA: {group_name} scales={weights}")
 
394
  ls = float(slot.get("low_scale", 1.0) or 1.0)
395
  if fh and fh != "(None)":
396
  path = download_repo_file(repo, fh)
397
+ all_names.append(_load_path(pipe, path, f"link_{idx}_high", into_t2=False))
 
 
398
  all_weights.append(hs)
399
  print(f"Loaded link HIGH: {fh} scale={hs}")
400
  if fl and fl != "(None)":
401
  path = download_repo_file(repo, fl)
402
+ all_names.append(_load_path(pipe, path, f"link_{idx}_low", into_t2=True))
 
 
403
  all_weights.append(ls)
404
  print(f"Loaded link LOW: {fl} scale={ls}")
405
  if all_names:
 
414
  pipe.unload_lora_weights()
415
  except Exception:
416
  pass