Open ethvedbitdesjan opened 1 year ago
Build the environment from source.
Build the environment from source.
I did run
!pip install git+https://github.com/cloneofsimo/lora.git
Is this not building from source?
You may need to lower the version of the Python package, such as using diffusers==0.11.0 and transformers==4.25.1.
query = attn.to_q(hidden_states, scale=scale)
The latest diffusers adopts LoRACompatibleLinear
module rather than nn.Linear
.
The forward method of LoRACompatibleLinear
, however, has an additional kwargs scale
which is not included in LoraInjectedLinear
.
Since LoraInjectedLinear
already has a scale
parameter as an instance variable, simply modifying the definition of the forward method of LoraInjectedLinear
will resolve the issue.
class LoraInjectedLinear(nn.Module):
...
def forward(self, input, scale: float = 1.0): # FIXED: add dummy scale argument
thanks @justin-prnd
Modification for inference
After training, I faced a similar issue for inference.
The patch_pipe
method would fail with the following error.
...
line 784, in monkeypatch_or_replace_lora_extended
_module._modules[name] = _tmp
UnboundLocalError: local variable '_tmp' referenced before assignment
I figured out that the error occurred because the monkeypatch_or_replace_lora_extended
did not handle the LoRACompatibleLinear
module properly.
There would be a better solution, but I fixed the issue by simply adding the LoRACompatibleLinear
module on the search target.
def monkeypatch_or_replace_lora_extended(
model,
loras,
target_replace_module=DEFAULT_TARGET_REPLACE,
r: Union[int, List[int]] = 4,
):
for _module, name, _child_module in _find_modules(
model,
target_replace_module,
search_class=[nn.Linear, LoraInjectedLinear, LoRACompatibleLinear, nn.Conv2d, LoraInjectedConv2d],
):
_tmp = None
if _child_module.__class__ in {nn.Linear, LoraInjectedLinear, LoRACompatibleLinear}:
...
@justin-prnd where is the LoRACompatibleLinear defined? I get module not defined error?
@justin-prnd where is the LoRACompatibleLinear defined? I get module not defined error?
Defined at https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/lora.py#L181 and can be imported as
from diffusers.models.lora import LoRACompatibleLinear
if diffusers >= v0.16.0
I got this error while running two different scripts: run_lora_db_unet_only.sh and use_face_conditioning_example.sh
I only made changes regarding my own data and output directory. Also, for the second one I set use_template to "style" but everything else remained the same.
I was running this on kaggle notebooks, so I am not sure whether that is the problem.
Below are the full error descriptions by running use_face_conditioning.sh:
The error is similar to the one I get on running run_lora_db_unet_only.sh
I am not sure how to resolve this. Thank you for your time. I am just a beginner so sorry for the trouble.