ahrm / UnstableFusion

A Stable Diffusion desktop frontend with inpainting, img2img and more!
GNU General Public License v3.0
1.25k stars 86 forks source link

Use my own model? #7

Open TheSeanLavery opened 1 year ago

TheSeanLavery commented 1 year ago

Can you provide instructions for using this without downloading the model from hugging faces?

I don't want to use my API key

ahrm commented 1 year ago

You need to modify diffusionserver.py to create your own model.

ZeroCool22 commented 1 year ago

Can you provide instructions for using this without downloading the model from hugging faces?

I don't want to use my API key

What could happen if you use your own API key?

They can know what you create?

TheSeanLavery commented 1 year ago

I don't want to download a bunch of extra data, when I already have models locally.

TheSeanLavery commented 1 year ago

@ahrm I don't want to make my own model. I just want to know where I should put my model.ckpt file?

ahrm commented 1 year ago

I don't think it is as simple as replacing a .ckpt file.

codefaux commented 1 year ago

I'm on my phone, if this doesn't help I'll do better later. Whenever a model is initialized from a pre trained set, you can point it at a local file instead. Edit lines like this;

diffusionserver.py, line 24: self.text2img = StableDiffusionPipeline.from_pretrained( "CompVis/stable-diffusion-v1-4", revision="fp16", torch_dtype=torch.float16, use_auth_token=token).to("cuda")

The "CompVis/stable-diffusion-v1-4" is the model. Replace that with your local model file, using ideally relative paths. This works for literally any object being initialized by from_pretrained()

For bonus points, you can symlink files in Windows with mklink.

If you need more, reply and I'll get around to it when I'm at a computer because this sucks lol

TheSeanLavery commented 1 year ago

I'm on my phone, if this doesn't help I'll do better later. Whenever a model is initialized from a pre trained set, you can point it at a local file instead. Edit lines like this;

diffusionserver.py, line 24: self.text2img = StableDiffusionPipeline.from_pretrained( "CompVis/stable-diffusion-v1-4", revision="fp16", torch_dtype=torch.float16, use_auth_token=token).to("cuda")

The "CompVis/stable-diffusion-v1-4" is the model. Replace that with your local model file, using ideally relative paths. This works for literally any object being initialized by from_pretrained()

For bonus points, you can symlink files in Windows with mklink.

If you need more, reply and I'll get around to it when I'm at a computer because this sucks lol

{'safety_checker'} was not found in config. Values will be initialized to default values.
{'trained_betas'} was not found in config. Values will be initialized to default values.

 File "...Python\Python310\lib\site-packages\diffusers\pipeline_utils.py", line 391, in from_pretrained
    model = pipeline_class(**init_kwargs)
TypeError: StableDiffusionPipeline.__init__() missing 1 required positional argument: 'safety_checker'

I feel this is really close.

codefaux commented 1 year ago

Okay so I could swear I had this running someplace but now I can't find it. I'm messing with like six different Stable Diffusion iterations right now, lol, so my drive is a -mess-.

Anyway -- add safety_checker=dummy_safety_checker (*EDIT: With a comma appropriately, I assume you know how to code lol) to the from_pretrained call and it should A) Disable the worthless "safety checker" (more false positives than function, in my experience) and B) allow you to run without downloading and providing said safety checker. UnstableDiffusion actually provides that (and commented out enabling it post-activating-it) but this SHOULD allow us to skip that.

EDIT 2: Also will likely want to remove "use_auth_token=token" param given that you're trying to use local data.

If you do manage to get a working statement on that line, please paste it here to share.

codefaux commented 1 year ago

What could happen if you use your own API key? They can know what you create?

@ZeroCool22 - No, none of the Stable Diffusion packages available do any form of feedback that I'm aware of. Mostly, loading a local model is useful in the instance of so-called "fine-tuned" models -- Waifu Diffusion being one of the more popular, though I haven't used it -- to return customized results. Several UIs allow more seamless integration of custom models, those using the HuggingFace API would need to be modified to a different, public model or a local instance if one were doing homebrew work.

TheSeanLavery commented 1 year ago

Okay so I could swear I had this running someplace but now I can't find it. I'm messing with like six different Stable Diffusion iterations right now, lol, so my drive is a -mess-.

Anyway -- add safety_checker=dummy_safety_checker (*EDIT: With a comma appropriately, I assume you know how to code lol) to the from_pretrained call and it should A) Disable the worthless "safety checker" (more false positives than function, in my experience) and B) allow you to run without downloading and providing said safety checker. UnstableDiffusion actually provides that (and commented out enabling it post-activating-it) but this SHOULD allow us to skip that.

EDIT 2: Also will likely want to remove "use_auth_token=token" param given that you're trying to use local data.

If you do manage to get a working statement on that line, please paste it here to share.

No dice. Still getting the same.. {'safety_checker'} was not found in config

codefaux commented 1 year ago

Roger. Will pursue and report back if solved, I swear I saw it someplace...

alexanderdutton commented 1 year ago

Without the dots .. I don't know how to properly indent here ..

pipe = ComposableStableDiffusionPipeline.from_pretrained( ..."CompVis/stable-diffusion-v1-4", ... use_auth_token=True ).to(device)

def dummy(images, **kwargs): ... return images, False pipe.safety_checker = dummy

codefaux commented 1 year ago

Without the dots .. I don't know how to properly indent here ..

pipe = ComposableStableDiffusionPipeline.from_pretrained( ..."CompVis/stable-diffusion-v1-4", ... use_auth_token=True ).to(device)

def dummy(images, **kwargs): ... return images, False pipe.safety_checker = dummy

Does not address the issue, which is an error initiating the model in the first from_pretrained function call.

codefaux commented 1 year ago

No dice. Still getting the same.. {'safety_checker'} was not found in config Ok, got a bit more headspace and time today/tomorrow, sat down and cleaned up my sandbox(es) and got things in order again.

@TheSeanLavery -- Model config seems to be imported from a json file typically packaged with the model. I'm not sure if the safety_checker req is coming from the json or the platform, so that's where I'd start. If you can share the model you're trying to target, I'll spend a bit of time on it. I don't have much experience with this stuff explicitly, but that rarely stops me, lol

nerdyrodent commented 1 year ago

I can "sort of" use my own model like this:

        model_id = "/home/nerdy/github/Dreambooth-SD-optimized/HDD_Scratch/Diffusers/"
        self.text2img = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
        self.text2img.safety_checker = dummy_safety_checker
        self.text2img.feature_extractor = False

by not using the .custom_pipeline.pipeline_stable_diffusion imports

Generate works OK, but not reimagine.