UnstableFusion icon indicating copy to clipboard operation
UnstableFusion copied to clipboard

Use my own model?

Open TheSeanLavery opened this issue 3 years ago • 15 comments

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

I don't want to use my API key

TheSeanLavery avatar Sep 23 '22 14:09 TheSeanLavery

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

ahrm avatar Sep 23 '22 15:09 ahrm

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?

ZeroCool22 avatar Sep 23 '22 15:09 ZeroCool22

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

TheSeanLavery avatar Sep 23 '22 15:09 TheSeanLavery

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

TheSeanLavery avatar Sep 23 '22 15:09 TheSeanLavery

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

ahrm avatar Sep 23 '22 16:09 ahrm

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

codefaux avatar Sep 23 '22 18:09 codefaux

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.

TheSeanLavery avatar Sep 23 '22 19:09 TheSeanLavery

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 avatar Sep 23 '22 20:09 codefaux

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.

codefaux avatar Sep 23 '22 20:09 codefaux

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

TheSeanLavery avatar Sep 23 '22 21:09 TheSeanLavery

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

codefaux avatar Sep 23 '22 21:09 codefaux

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

alexanderdutton avatar Sep 23 '22 23:09 alexanderdutton

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 avatar Sep 24 '22 00:09 codefaux

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

codefaux avatar Sep 25 '22 19:09 codefaux

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.

nerdyrodent avatar Sep 30 '22 13:09 nerdyrodent