File size: 33,679 Bytes
0a0298d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# LoRA Block Weight
- custom script for [AUTOMATIC1111's stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) 
- When applying Lora, strength can be set block by block.

- [AUTOMATIC1111's stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) 甚のスクリプトです
- Loraを適甚する際、匷さを階局ごずに蚭定できたす

[<img src="https://img.shields.io/badge/lang-Egnlish-red.svg?style=plastic" height="25" />](#overview)
[<img src="https://img.shields.io/badge/蚀語-日本語-green.svg?style=plastic" height="25" />](#抂芁)
[<img src="https://img.shields.io/badge/Support-%E2%99%A5-magenta.svg?logo=github&style=plastic" height="25" />](https://github.com/sponsors/hako-mikan)

> [!IMPORTANT]
> If you have an error :`ValueError: could not convert string to float`  
> use new syntax`<lora:"lora name":1:lbw=IN02>`


## Updates/曎新情報
### 2024.04.06.0000(JST)
- add [new UI](#make-weights): make weights
- りェむトを䜜成する[新しいUI](#りェむトの䜜成)を远加

### 2023.11.22.2000(JST)
- bugfix
- added new feature:start in steps
- 機胜远加:LoRAの途䞭開始

### 2023.11.21.1930(JST)
- added new feature:stop in steps
- 機胜远加:LoRAの途䞭停止  
By specifying `<lora:"lora name":lbw=ALL:stop=10>`, you can disable the effect of LoRA at the specified step. In the case of character or composition LoRA, a sufficient effect is achieved in about 10 steps, and by cutting it off at this point, it is possible to minimize the impact on the style of the painting  
`<lora:"lora name":lbw=ALL:stop=10>`ず指定するこずで指定したstepでLoRAの効果を無くしたす。キャラクタヌや構図LoRAの堎合には10 step皋床で十分な効果があり、ここで切るこずで画颚ぞの圱響を抑えるこずが可胜です。

# Overview
Lora is a powerful tool, but it is sometimes difficult to use and can affect areas that you do not want it to affect. This script allows you to set the weights block-by-block. Using this script, you may be able to get the image you want.

## Usage
Place lora_block_weight.py in the script folder.  
Or you can install from Extentions tab in web-ui. When installing, please restart web-ui.bat.

### Active  
Check this box to activate it.

### Prompt
In the prompt box, enter the Lora you wish to use as usual. Enter the weight or identifier by typing ":" after the strength value. The identifier can be edited in the Weights setting.  
```
<lora:"lora name":1:0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0>.  
<lora:"lora name":1:0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>.  (a1111-sd-webui-locon, etc.)
<lyco:"lora name":1:1:lbw=IN02>  (a1111-sd-webui-lycoris, web-ui 1.5 or later)
<lyco:"lora name":1:1:lbw=1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0>  (a1111-sd-webui-lycoris, web-ui 1.5 or later)
```
For LyCORIS using a1111-sd-webui-lycoris, syntax is different.
`lbw=IN02` is used and follow lycoirs syntax for others such as unet or else.
a1111-sd-webui-lycoris is under under development, so this syntax might be changed. 

Lora strength is in effect and applies to the entire Blocks.  
It is case-sensitive.
For LyCORIS, full-model blobks used,so you need to input 26 weights.
You can use weight for LoRA, in this case, the weight of blocks not in LoRA is set to 0.  
If the above format is not used, the preset will treat it as a comment line.

### start, stop step
By specifying `<lora:"lora name":lbw=ALL:start=10>`, the effect of LoRA appears from the designated step. By specifying `<lora:"lora name":lbw=ALL:stop=10>`, the effect of LoRA is eliminated at the specified step. In the case of character or composition LoRA, a significant effect is achieved in about 10 steps, and by cutting it off at this point, it is possible to minimize the influence on the style of the painting. By specifying `<lora:"lora name":lbw=ALL:step=5-10>`, LoRA is activated only between steps 5-10."

### Weights Setting
Enter the identifier and weights.
Unlike the full model, Lora is divided into 17 blocks, including the encoder. Therefore, enter 17 values.
BASE, IN, OUT, etc. are the blocks equivalent to the full model.
Due to various formats such as Full Model and LyCORIS and SDXL, script currently accept weights for 12, 17, 20, and 26. Generally, even if weights in incompatible formats are inputted, the system will still function. However, any layers not provided will be treated as having a weight of 0.

LoRA(17)
|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|  
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|  
|BASE|IN01|IN02|IN04|IN05|IN07|IN08|MID|OUT03|OUT04|OUT05|OUT06|OUT07|OUT08|OUT09|OUT10|OUT11|

LyCORIS, etc.  (26)
|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|  
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
|BASE|IN00|IN01|IN02|IN03|IN04|IN05|IN06|IN07|IN08|IN09|IN10|IN11|MID|OUT00|OUT01|OUT02|OUT03|OUT04|OUT05|OUT06|OUT07|OUT08|OUT09|OUT10|OUT11|

SDXL LoRA(12)
|1|2|3|4|5|6|7|8|9|10|11|12|
|-|-|-|-|-|-|-|-|-|-|-|-|
|BASE|IN04|IN05|IN07|IN08|MID|OUT0|OUT1|OUT2|OUT3|OUT4|OUT05|

SDXL - LyCORIS/LoCon(20)
|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
|BASE|IN00|IN01|IN02|IN03|IN04|IN05|IN06|IN07|IN08||MID|OUT00|OUT01|OUT02|OUT03|OUT04|OUT05|OUT06|OUT07|OUT08|

### Special Values (Random)
Basically, a numerical value must be entered to work correctly, but by entering `R` and `U`, a random value will be entered.  
R : Numerical value with 3 decimal places from 0~1
U : 3 decimal places from -1.5 to 1.5

For example, if ROUT:1,1,1,1,1,1,1,1,R,R,R,R,R,R,R,R,R  
Only the OUT blocks is randomized.
The randomized values will be displayed on the command prompt screen when the image is generated.

### Special Values (Dynamic)
The special value `X` may also be included to use a dynamic weight specified in the LoRA syntax. This is activated by including an additional weight value after the specified `Original Weight`.

For example, if ROUT:X,1,1,1,1,1,1,1,1,1,1,1,X,X,X,X,X and you had a prompt containing \<lora:my_lore:0.5:ROUT:0.7\>. The `X` weights in ROUT would be replaced with `0.7` at runtime.

> NOTE: If you select an `Original Weight` tag that has a dynamic weight (`X`) and you do not specify a value in the LoRA syntax, it will default to `1`.

### Save Presets

The "Save Presets" button saves the text in the current text box. It is better to use a text editor, so use the "Open TextEditor" button to open a text editor, edit the text, and reload it.  
The text box above the Weights setting is a list of currently available identifiers, useful for copying and pasting into an XY plot. 17 identifiers are required to appear in the list.

### Fun Usage
Used in conjunction with the XY plot, it is possible to examine the impact of each level of the hierarchy.  
![xy_grid-0017-4285963917](https://user-images.githubusercontent.com/122196982/215341315-493ce5f9-1d6e-4990-a38c-6937e78c6b46.jpg)

The setting values are as follows.  
NOT:0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  
ALL:1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1  
INS:1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0  
IND:1,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0  
INALL:1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0  
MIDD:1,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0  
OUTD:1,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0  
OUTS:1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1  
OUTALL:1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1 

## XYZ Plotting Function
The optimal value can be searched by changing the value of each layer individually.
### Usage 
Check "Active" to activate the function. If Script (such as XYZ plot in Automatic1111) is enabled, it will take precedence.
Hires. fix is not supported. batch size is fixed to 1. batch count should be set to 1.  
Enter XYZ as the identifier of the LoRA that you want to change. It will work even if you do not enter a value corresponding to XYZ in the preset. If a value corresponding to XYZ is entered, that value will be used as the initial value.  
Inputting ZYX, inverted value will be automatically inputted.
This feature enables to match weights of two LoRAs.  
Inputing XYZ for LoRA1 and ZYX for LoRA2, you get,  
LoRA1 1,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0  
LoRA2 0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1    
### Axis type
#### values
Sets the weight of the hierarchy to be changed. Enter the values separated by commas. 0,0.25,0.5,0.75,1", etc.

#### Block ID
If a block ID is entered, only that block will change to the value specified by value. As with the other types, use commas to separate them. Multiple blocks can be changed at the same time by separating them with a space or hyphen. The initial NOT will invert the change, so NOT IN09-OUT02 will change all blocks except IN09-OUT02.

#### seed
Seed changes, and is intended to be specified on the Z-axis.

#### Original Weights
Specify the initial value to change the weight of each block. If Original Weight is enabled, the value entered for XYZ is ignored.

### Input example
X : value, value : 1,0.25,0.5,0.75,1  
Y : Block ID, value : BASE,IN01-IN08,IN05-OUT05,OUT03-OUT11,NOT OUT03-OUT11  
Z : Original Weights, Value : NONE,ALL0.5,ALL  

In this case, an XY plot is created corresponding to the initial values NONE,ALL0.5,ALL.
If you select Seed for Z and enter -1,-1,-1, the XY plot will be created 3 times with different seeds.

### Original Weights Combined XY Plot
If both X and Y are set to Original Weights then an XY plot is made by combining the weights. If both X and Y have a weight in the same block then the Y case is set to zero before adding the arrays, this value will be used during the YX case where X's value is then set to zero. The intended usage is without overlapping blocks.

Given these names and values in the "Weights setting":  
INS:1,1,1,0,0,0,0,0,0,0,0,0  
MID:1,0,0,0,0,1,0,0,0,0,0,0  
OUTD:1,0,0,0,0,0,1,1,1,0,0,0  

With:  
X : Original Weights, value: INS,MID,OUTD  
Y : Original Weights, value: INS,MID,OUTD  
Z : none  

An XY plot is made with 9 elements. The diagonal is the X values: INS,MID,OUTD unchanged. So we have for the first row:
```
INS+INS  = 1,1,1,0,0,0,0,0,0,0,0,0 (Just INS unchanged, first image on the diagonal)
MID+INS  = 1,1,1,0,0,1,0,0,0,0,0,0 (second column of first row)
OUTD+INS = 1,1,1,0,0,0,1,1,1,0,0,0 (third column of first row)
```

Then the next row is INS+MID, MID+MID, OUTD+MID, and so on. Example image [here](https://user-images.githubusercontent.com/55250869/270830887-dff65f45-823a-4dbd-94c5-34d37c84a84f.jpg)

### Effective Block Analyzer
This function check which layers are working well. The effect of the block is visualized and quantified by setting the intensity of the other bocks to 1, decreasing the intensity of the block you want to examine, and taking the difference.  
#### Range
If you enter 0.5, 1, all initial values are set to 1, and only the target block is calculated as 0.5. Normally, 0.5 will make a difference, but some LoRAs may have difficulty making a difference, in which case, set 0.5 to 0 or a negative value.

#### settings
##### diff color
Specify the background color of the diff file.

##### chnage X-Y
Swaps the X and Y axes. By default, Block is assigned to the Y axis.

##### Threshold
Sets the threshold at which a change is recognized when calculating the difference. Basically, the default value is fine, but if you want to detect subtle differences in color, etc., lower the value.

#### Blocks
Enter the blocks to be examined, using the same format as for XYZ plots.

Here is the English translation in Markdown format:

### Guide for API users
#### Regular Usage
By default, Active is checked in the initial settings, so you can use it simply by installing it. You can use it by entering the format as instructed in the prompt. If executed, the phrase "LoRA Block Weight" will appear on the command prompt screen. If for some reason Active is not enabled, you can make it active by entering a value in the API for `"alwayson_scripts"`. 
When you enable API mode and use the UI, two extensions will appear. Please use the one on the bottom.
The default presets can be used for presets. If you want to use your own presets, you can either edit the preset file or use the following format for the data passed to the API. 

The code that can be used when passing to the API in json format is as follows. The presets you enter here will become available. If you want to use multiple presets, please separate them with `\n`.

```json
"prompt": "myprompt, <lora:mylora:1:MYSETS>",
"alwayson_scripts": {
    "LoRA Block Weight": {
        "args": ["MYSETS:1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\nYOURSETS:0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1", true, 1 ,"","","","","","","","","","","","","",""]
    }
}
```
#### XYZ Plot
Please use the format below. Please delete `"alwayson_scripts"` as it will cause an error.

```json
"prompt": "myprompt, <lora:mylora:1:XYZ>",
"script_name":"LoRA Block Weight",
"script_args": ["XYZ:1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1", true, 1 ,"seed","-1,-1","","","","","","","","","","","",""]
```
In this case, the six following `True,1` correspond to `xtype,xvalues,ytype,yvalues,ztype,zvalues`. It will be ignored if left blank. Please follow the instructions in the XYZ plot section for entering values. Even numbers should be enclosed in `""`.

The following types are available.

```json
"none","Block ID","values","seed","Original Weights","elements"
```
#### Effective Block Analyzer
It can be used by using the following format.

```json
"prompt": "myprompt, <lora:mylora:1:XYZ>",
"script_name":"LoRA Block Weight",
"script_args": ["XYZ:1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1", true, 2 ,"","","","","","","0,1","17ALL",1,"white",20,true,"",""]
```
For `"0,1"`, specify the weight. If you specify `"17ALL"`, it will examine all the layers of the normal LoRA. If you want to specify individually, please write like `"BASE,IN00,IN01,IN02"`. Specify whether to reverse XY for `True` in the `"1"` for the number of times you want to check (if it is 2 or more, multiple seeds will be set), and `white` for the background color.

#### Make Weights
In "make weights," you can create a weight list from a slider. When you press the "add to preset" button, the weight specified by the identifier is added to the end of the preset. If a preset with the same name already exists, it will be overwritten. The "add to preset and save" button allows you to save the preset simultaneously.
![makeweights](https://github.com/hako-mikan/sd-webui-lora-block-weight/assets/122196982/9f0f3c1f-d824-45a6-926d-e1b431d5ef61)

# 抂芁
Loraは匷力なツヌルですが、時に扱いが難しく、圱響しおほしくないずころにたで圱響がでたりしたす。このスクリプトではLoraを適甚する際、適甚床合いをU-Netの階局ごずに蚭定するこずができたす。これを䜿甚するこずで求める画像に近づけるこずができるかもしれたせん。

## 䜿い方
むンストヌル時はWeb-ui.batを再起動をしおください。

### Active  
ここにチェックを入れるこずで動䜜したす。

### プロンプト
プロンプト画面では通垞通り䜿甚したいLoraを蚘入しおください。その際、匷さの倀の次に「:」を入力しりェむトか識別子を入力したす。識別子はWeights setting で線集したす。  
```
<lora:"lora name":1:0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0>.  
<lora:"lora name":1:0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>.  (a1111-sd-webui-locon, etc.)
<lora:"lora name":1:1:lbw=IN02>  (a1111-sd-webui-lycoris, web-ui 1.5 or later)
<lora:"lora name":1:1:lbw=1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0>  (a1111-sd-webui-lycoris, web-ui 1.5 or later)
<lora:"lora name":1:1:lbw=IN02:stop=10>
```
Loraの匷さは有効で、階局党䜓にかかりたす。倧文字ず小文字は区別されたす。
LyCORISに察しおLoRAのプリセットも䜿甚できたすが、その堎合LoRAで䜿われおいない階局のりェむトは0に蚭定されたす。  
䞊蚘の圢匏になっおいない堎合プリセットではコメント行ずしお扱われたす。
a1111-sd-webui-lycoris版のLyCORISや、ver1.5以降のweb-uiを䜿甚する堎合構文が異なりたす。`lbw=IN02`を䜿っお䞋さい。順番は問いたせん。その他の曞匏はlycorisの曞匏にしたがっお䞋さい。詳しくはLyCORISのドキュメントを参照しお䞋さい。識別子を入力しお䞋さい。a1111-sd-webui-lycoris版は開発途䞭のためこの構文は倉曎される可胜性がありたす。
### start, stop step  
`<lora:"lora name":lbw=ALL:start=10>`ず指定するず、指定したstepからLoRAの効果が珟れたす。  
`<lora:"lora name":lbw=ALL:stop=10>`ず指定するこずで指定したstepでLoRAの効果を無くしたす。キャラクタヌや構図LoRAの堎合には10 step皋床で十分な効果があり、ここで切るこずで画颚ぞの圱響を抑えるこずが可胜です。  
`<lora:"lora name":lbw=ALL:step=5-10>`ず指定するずstep 5-10の間のみLoRAが有効化したす。

### Weights setting
識別子ずりェむトを入力したす。
フルモデルず異なり、Loraでぱンコヌダヌを含め17のブロックに分かれおいたす。よっお、17個の数倀を入力しおください。
BASE,IN,OUTなどはフルモデル盞圓の階局です。
フルモデルやLyCORIS、SDXLなど様々な圢匏があるため、珟状では12,17,20,26のりェむトを受け付けたす。基本的に圢匏が合わないりェむトを入力しおも動䜜したすが、未入力の局は0ずしお扱われたす。
|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|  
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
|BASE|IN01|IN02|IN04|IN05|IN07|IN08|MID|OUT03|OUT04|OUT05|OUT06|OUT07|OUT08|OUT09|OUT10|OUT11|

LyCORISなどの堎合(26)
|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
|BASE|IN00|IN01|IN02|IN03|IN04|IN05|IN06|IN07|IN08|IN09|IN10|IN11|MID|OUT00|OUT01|OUT02|OUT03|OUT04|OUT05|OUT06|OUT07|OUT08|OUT09|OUT10|OUT11|

SDXL LoRAの堎合(12)
|1|2|3|4|5|6|7|8|9|10|11|12|
|-|-|-|-|-|-|-|-|-|-|-|-|
|BASE|IN04|IN05|IN07|IN08|MID|OUT0|OUT1|OUT2|OUT3|OUT4|OUT05|

SDXL - LyCORISの堎合(20)
|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
|BASE|IN00|IN01|IN02|IN03|IN04|IN05|IN06|IN07|IN08||MID|OUT00|OUT01|OUT02|OUT03|OUT04|OUT05|OUT06|OUT07|OUT08|

### 特別な倀
基本的には数倀を入れないず正しく動きたせんが R および U を入力するこずでランダムな数倀が入力されたす。  
R : 0~1たでの小数点3桁の数倀
U : -1.51.5たでの小数点3桁の数倀

䟋えば ROUT:1,1,1,1,1,1,1,1,R,R,R,R,R,R,R,R,R  ずするず  
OUT局のみダンダム化されたす  
ランダム化された数倀は画像生成時にコマンドプロンプト画面に衚瀺されたす

saveボタンで珟圚のテキストボックスのテキストを保存できたす。テキスト゚ディタを䜿った方がいいので、open Texteditorボタンでテキスト゚ディタ開き、線集埌reloadしおください。  
Weights settingの䞊にあるテキストボックスは珟圚䜿甚できる識別子の䞀芧です。XYプロットにコピペするのに䟿利です。17個ないず䞀芧に衚瀺されたせん。

### 楜しい䜿い方
XY plotず䜵甚するこずで各階局の圱響を調べるこずが可胜になりたす。  
![xy_grid-0017-4285963917](https://user-images.githubusercontent.com/122196982/215341315-493ce5f9-1d6e-4990-a38c-6937e78c6b46.jpg)

蚭定倀は以䞋の通りです。  
NOT:0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  
ALL:1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1  
INS:1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0  
IND:1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0  
INALL:1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0  
MIDD:1,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0  
OUTD:1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0  
OUTS:1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1  
OUTALL:1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1 

## XYZ プロット機胜
各局の倀を個別に倉化させるこずで最適倀を総圓たりに探せたす。
### 䜿い方 
Activeをチェックするこずで動䜜したす。 Script(Automatic1111本䜓のXYZプロットなど)が有効になっおいる堎合そちらが優先されたす。noneを遞択しおください。
Hires. fixには察応しおいたせん。Batch sizeは1に固定されたす。Batch countは1に蚭定しおください。  
倉化させたいLoRAの識別子にXYZず入力したす\<lora:"lora名":1:XYZ>。 プリセットにXYZに察応する倀を入力しおいなくおも動䜜したす。その堎合すべおのりェむトが0の状態からスタヌトしたす。XYZに察応する倀が入力されおいる堎合はその倀が初期倀になりたす。  
ZYXず入力するずXYZずは反察の倀が入力されたす。これはふた぀のLoRAのりェむトを合わせる際に有効です。
䟋えばLoRA1にXYZ,LoRA2にZYXず入力するず、  
LoRA1 1,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0  
LoRA2 0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1    
ずなりたす。
### 軞タむプ
#### values
倉化させる階局のりェむトを蚭定したす。カンマ区切りで入力しおください。「0,0.25,0.5,0.75,1」など。

#### Block ID
ブロックIDを入力するず、そのブロックのみvalueで指定した倀に倉わりたす。他のタむプず同様にカンマで区切りたす。スペヌスたたはハむフンで区切るこずで耇数のブロックを同時に倉化させるこずもできたす。最初にNOTを぀けるこずで倉化察象が反転したす。NOT IN09-OUT02ずするず、IN09-OUT02以倖が倉化したす。NOTは最初に入力しないず効果がありたせん。IN08-M00-OUT03は繋がっおいたす。

#### Seed
シヌドが倉わりたす。Z軞に指定するこずを想定しおいたす。

#### Original Weights
各ブロックのりェむトを倉化させる初期倀を指定したす。プリセットに登録されおいる識別子を入力しおください。Original Weightが有効になっおいる堎合XYZに入力された倀は無芖されたす。

### Original Weightsの合算
もしXずYが䞡方ずもOriginal Weightsに蚭定されおいる堎合、その重みを組み合わせおXYプロットが䜜成されたす。XずYの䞡方が同じブロックに重みがある堎合、配列を加算する前にYケヌスはれロに蚭定されたす。この倀は、Xの倀がれロに蚭定されるYXケヌスで䜿甚されたす。意図されおいる䜿甚方法は、重耇するブロックなしでのものです。

"Weights setting"に以䞋の名前ず倀が䞎えられおいるずしたす  
INS:1,1,1,0,0,0,0,0,0,0,0,0  
MID:1,0,0,0,0,1,0,0,0,0,0,0  
OUTD:1,0,0,0,0,0,1,1,1,0,0,0  

以䞋の蚭定で  
X : Original Weights, 倀: INS,MID,OUTD  
Y : Original Weights, 倀: INS,MID,OUTD  
Z : なし  

9぀の芁玠を持぀XYプロットが䜜成されたす。察角線䞊は、倉曎されおいないXの倀INS,MID,OUTDです。したがっお、最初の行は以䞋のようになりたす
```
INS+INS  = 1,1,1,0,0,0,0,0,0,0,0,0 (倉曎されおいないINSだけ、察角線䞊の最初の画像)
MID+INS  = 1,1,1,0,0,1,0,0,0,0,0,0 (最初の行の第2列)
OUTD+INS = 1,1,1,0,0,0,1,1,1,0,0,0 (最初の行の第3列)
```

次の行は、INS+MID、MID+MID、OUTD+MIDなどです。䟋の画像は[こちら](https://user-images.githubusercontent.com/55250869/270830887-dff65f45-823a-4dbd-94c5-34d37c84a84f.jpg)です。

### 入力䟋
X : value, 倀 : 1,0.25,0.5,0.75,1  
Y : Block ID, 倀 : BASE,IN01-IN08,IN05-OUT05,OUT03-OUT11,NOT OUT03-OUT11  
Z : Original Weights, 倀 : NONE,ALL0.5,ALL  

この堎合、初期倀NONE,ALL0.5,ALLに察応したXY plotが䜜補されたす。
ZにSeedを遞び、-1,-1,-1を入力するず、異なるseedでXY plotを3回䜜補したす。

### Effective Block Analyzer
どの階局が良く効いおいるかを刀別する機胜です。察象の階局以倖の匷床を1にしお、調べたい階局の匷床を䞋げ、差分を取るこずで階局の効果を可芖化・数倀化したす。  
#### Range
0.5, 1 ず入力した堎合、初期倀がすべお1になり、察象のブロックのみ0.5ずしお蚈算が行われたす。普通は0.5で差がでたすが、LoRAによっおは差が出にくい堎合があるので、その堎合は0.5を0あるいはマむナスの倀に蚭定しおください。

#### 蚭定
##### diff color
差分ファむルの背景カラヌを指定したす。

##### chnage X-Y
X軞ずY軞を入れ替えたす。デフォルトではY軞にBlockが割り圓おられおいたす。

##### Threshold
差分を蚈算する際の倉化したず認識される閟倀を蚭定したす。基本的にはデフォルト倀で問題ありたせんが、埮劙な色の違いなどを怜出したい堎合は倀を䞋げお䞋さい。

#### Blocks
調べたい階局を入力したす。XYZプロットず同じ曞匏が䜿甚可胜です。

階局別マヌゞに぀いおは䞋蚘を参照しおください

### elemental
詳现は[こちら](https://github.com/hako-mikan/sd-webui-supermerger/blob/main/elemental_ja.md)を参照しお䞋さい。
#### 䜿い方
Elementaタブにお階局指定ず同じように識別子を蚭定したす。識別子は階局の識別子の埌に入力したす。
\<lora:"lora名":1:IN04:ATTNON>
ATTNON:

曞匏は  
識別子:階局指定:芁玠指定:りェむト  
のように指定したす。芁玠は郚分䞀臎で刀定されたす。attn1ならattn1のみ、attnならattn1及びattn2が反応したす。階局、芁玠共に空癜で区切るず耇数指定できたす。  
print changeをオンにするず反応した芁玠がコマンドプロンプト䞊に衚瀺されたす。

ALL0:::0  
はすべおの芁玠のりェむトをれロに蚭定したす。  
IN1:IN00-IN11::1  
はINのすべおの芁玠を1にしたす  
ATTNON::attn:1
はすべおの階局のattnを1にしたす。

#### XYZプロット
XYZプロットのelementsの項ではカンマ区切りでXYZプロットが可胜になりたす。
その堎合は  
\<lora:"lora名":1:XYZ:XYZ>  
ず指定しお䞋さい。
elements  
の項に  
IN05-OUT05:attn:0,IN05-OUT05:attn:0.5,IN05-OUT05:attn:1  
ず入力しお走らせるずIN05からOUT05たでのattnのみを倉化させるこずができたす。
この際、XYZの倀を倉曎するこずで初期倀を倉曎できたす。デフォルトではelementalのXYZはXYZ:::1ずなっおおり、これは党階局、党芁玠を1にしたすが、ここをXYZ:encoder::1ずするずテキスト゚ンコヌダヌのみを有効にした状態で評䟡ができたす。

#### りェむトの䜜成
make weightsではスラむダヌからりェむトリストを䜜成できたす。
add to presetボタンを抌すず、identiferで指定されたりェむトがプリセットの末尟に远加されたす。
すでに同じ名前のプリセットが存圚する堎合、䞊曞きされたす。
add to preset and saveボタンでは同時にプリセットの保存が行われたす。
![makeweights](https://github.com/hako-mikan/sd-webui-lora-block-weight/assets/122196982/9f0f3c1f-d824-45a6-926d-e1b431d5ef61)

### APIを通しおの利甚に぀いお
#### 通垞利甚
初期蚭定でActiveはチェックされおいるのでむンストヌルするだけで利甚可胜になりたす。
プロンプトに曞匏通りに入力するこずで利甚できたす。実行された堎合にはコマンドプロンプト画面に「LoRA Block Weight」の文字が珟れたす。
䜕らかの理由でActiveになっおいない堎合にはAPIに投げる倀のうち、`"alwayson_scripts"`に倀を入力するこずでActiveにできたす。
APIモヌドを有効にしおUIを䜿うずき、拡匵がふた぀衚瀺されたす。䞋の方を䜿っお䞋さい。
プリセットはデフォルトのプリセットが利甚できたす。独自のプリセットを利甚したい堎合にはプリセットファむルを線集するか、APIに受け枡すデヌタに察しお䞋蚘の曞匏を利甚しお䞋さい。
json圢匏でAPIに受け枡すずきに䜿甚できるコヌドです。ここで入力したプリセットが利甚可胜になりたす。耇数のプリセットを利甚したい堎合には`\n`で区切っお䞋さい。

    "prompt": "myprompt, <lora:mylora:1:MYSETS>",
	"alwayson_scripts": {
		"LoRA Block Weight": {
			"args": ["MYSETS:1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\nYOURSETS:0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1", True, 1 ,"","","","","","","","","","","","","",""]
		}
    }

#### XYZ plot
䞋蚘の曞匏を利甚しお䞋さい。`"alwayson_scripts"`は消しお䞋さい゚ラヌになりたす。
```
    "prompt": "myprompt, <lora:mylora:1:XYZ>",
    "script_name":"LoRA Block Weight",
    "script_args": ["XYZ:1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1", True, 1 ,"seed","-1,-1","","","","","","","","","","","",""]

```
この際、`True,1`に続く6個が`xtype,xvalues,ytype,yvalues,ztype,zvalues`に察応したす。空癜だず無芖されたす。入力する倀などはXYZ plotの項に埓っお䞋さい。数字でもすべお`""`で囲っお䞋さい。
䜿甚できるタむプは次の通りです。
```
"none","Block ID","values","seed","Original Weights","elements"
```
#### Effective Block Analyzer
䞋蚘のような曞匏を䜿うこずで䜿甚できたす。
```
    "prompt": "myprompt, <lora:mylora:1:XYZ>",
    "script_name":"LoRA Block Weight",
 "script_args": ["XYZ:1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1", True, 2 ,"","","","","","","0,1","17ALL",1,"white",20,True,"",""]

```
`"0,1"`にはりェむト。`"17ALL"`を指定するず普通のLoRAすべおの階局を調べたす。個別に指定したい堎合は`"BASE,IN00,IN01,IN02"`のように蚘述しお䞋さい。`1`には調べたい回数(2以䞊だず耇数のシヌドを蚭定したす),`white`には背景色,`True`にはXYを反転するかどうかを指定しお䞋さい。

### updates/曎新情報
### 2023.10.26.2000(JST)
- bugfix:Effective block checker does not work correctly.
- bugfix:Does not work correctly when lora in memory is set to a value other than 0.

### 2023.10.04.2000(JST)  
XYZ plotに[新たな機胜](#Original-Weightsの合算)が远加されたした。[sometimesacoder](https://github.com/sometimesacoder)氏に感謝したす。  
A [new feature](#Original-Weights-Combined-XY-Plot) was added to the XYZ plot. Many thanks to [sometimesacoder](https://github.com/sometimesacoder).

### 2023.07.22.0030(JST)
- support SDXL
- support web-ui 1.5
- support no buildin-LoRA system(lycoris required)

to use with web-ui 1.5/web-ui1.5で䜿うずきは
```
<lora:"lora name":1:1:lbw=IN02>  
<lora:"lora name":1:1:lbw=1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0>  
```

### 2023.07.14.2000(JST)
- APIでXYZプロットが利甚可胜になりたした
- [APIの利甚方法](#apiを通しおの利甚に぀いお)を远蚘したした
- XYZ plot can be used in API
- Added [guide for API users](#guide-for-api-users)

### 2023.5.24.2000(JST)
- changed directory for presets(extentions/sd-webui-lora-block-weight/scripts/)
- プリセットの保存フォルダがextentions/sd-webui-lora-block-weight/scripts/に倉曎になりたした。

### 2023.5.12.2100(JST)
- changed syntax of lycoris
- lycorisの曞匏を倉曎したした

### 2023.04.14.2000(JST)
- support LyCORIS(a1111-sd-webui-lycoris)
- LyCORIS(a1111-sd-webui-lycoris)に察応

### 2023.03.20.2030(JST)
- Comment lines can now be added to presets
- プリセットにコメント行を远加できるようになりたした
- support XYZ plot hires.fix
- XYZプロットがhires.fixに察応したした

### 2023.03.16.2030(JST)
- [LyCORIS](https://github.com/KohakuBlueleaf/LyCORIS)に察応したした
- Support [LyCORIS](https://github.com/KohakuBlueleaf/LyCORIS)

別途[LyCORIS Extention](https://github.com/KohakuBlueleaf/a1111-sd-webui-locon)が必芁です。
For use LyCORIS, [Extension](https://github.com/KohakuBlueleaf/a1111-sd-webui-locon) for LyCORIS needed.

### 2023.02.07 1250(JST)
- Changed behavior when XYZ plot Active (Script of the main UI is prioritized).

### 2023.02.06 2000(JST)
- Feature added: XYZ plotting is added.

### 2023.01.31 0200(JST)
- Feature added: Random feature is added
- Fixed: Weighting now works for negative values.

### 2023.02.16 2040(JST)
- Original Weight をxやyに蚭定できない問題を解決したした
- Effective Weight Analyzer遞択時にXYZのXやYがValuesずBlockIdになっおいないず゚ラヌになる問題を解決したした

### 2023.02.08 2120(JST)
- 階局適応した埌通垞䜿甚する際、階局適応が残る問題を解決したした
- 効果のある階局をワンクリックで刀別する機胜を远加したした

### 2023.02.08 0050(JST)
- 䞀郚環境でseedが固定されない問題を解決したした

### 2023.02.07 2015(JST)
- マむナスのりェむトが正垞に働かない問題を修正したした

### 2023.02.07 1250(JST)
- XYZプロットActive時の動䜜を倉曎したした(本䜓のScriptが優先されるようになりたす)

### 2023.02.06 2000(JST)
- 機胜远加XYZプロット機胜を远加したした

### 2023.01.31 0200(JST)
- 機胜远加ランダム機胜を远加したした
- 機胜修正りェむトがマむナスにも効くようになりたした