GithubHelp home page GithubHelp logo

Comments (8)

justin-prnd avatar justin-prnd commented on June 8, 2024 9

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

from lora.

xwhzz avatar xwhzz commented on June 8, 2024 1

You may need to lower the version of the Python package, such as using diffusers==0.11.0 and transformers==4.25.1.

from lora.

justin-prnd avatar justin-prnd commented on June 8, 2024 1

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}:
           ...

from lora.

justin-prnd avatar justin-prnd commented on June 8, 2024 1

@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

from lora.

shohog avatar shohog commented on June 8, 2024

Build the environment from source.

from lora.

ethvedbitdesjan avatar ethvedbitdesjan commented on June 8, 2024

Build the environment from source.

I did run

!pip install git+https://github.com/cloneofsimo/lora.git

Is this not building from source?

from lora.

haodong2000 avatar haodong2000 commented on June 8, 2024

thanks @justin-prnd

from lora.

ethvedbitdesjan avatar ethvedbitdesjan commented on June 8, 2024

@justin-prnd where is the LoRACompatibleLinear defined? I get module not defined error?

from lora.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.