sd-scripts icon indicating copy to clipboard operation
sd-scripts copied to clipboard

Fix train controlnet

Open sdbds opened this issue 10 months ago • 5 comments

Now we can train controlnet for SD 1.5. Sample image part not change.

sdbds avatar Apr 20 '24 13:04 sdbds

Thank you for this! Is omegaconf needed? I'd like to minimize the dependencies...

kohya-ss avatar May 12 '24 12:05 kohya-ss

Thank you for this! Is omegaconf needed? I'd like to minimize the dependencies...

I think just having a method that wraps the config would be fine, but diffusers don't support the old SimpleNamespace anymore because SimpleNamespace doesn't support loops.

sdbds avatar May 13 '24 03:05 sdbds

I think just having a method that wraps the config would be fine, but diffusers don't support the old SimpleNamespace anymore because SimpleNamespace doesn't support loops.

Thank you for clarification. It's annoying...

The following code may be working. Is it fine to use this? (I'm testing this PR on my env, but I get another error currently.)

    # make unet.config iterable and accessible by attribute
    class CustomConfig:
        def __init__(self, **kwargs):
            self.__dict__.update(kwargs)

        def __getattr__(self, name):
            if name in self.__dict__:
                return self.__dict__[name]
            else:
                raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")

        def __contains__(self, name):
            return name in self.__dict__    
        
    unet.config = CustomConfig(**unet.config)

kohya-ss avatar May 13 '24 12:05 kohya-ss

I think just having a method that wraps the config would be fine, but diffusers don't support the old SimpleNamespace anymore because SimpleNamespace doesn't support loops.

Thank you for clarification. It's annoying...

The following code may be working. Is it fine to use this? (I'm testing this PR on my env, but I get another error currently.)

    # make unet.config iterable and accessible by attribute
    class CustomConfig:
        def __init__(self, **kwargs):
            self.__dict__.update(kwargs)

        def __getattr__(self, name):
            if name in self.__dict__:
                return self.__dict__[name]
            else:
                raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")

        def __contains__(self, name):
            return name in self.__dict__    
        
    unet.config = CustomConfig(**unet.config)

it seems works in my env. 2024-05-14 20-13-16 的屏幕截图

sdbds avatar May 14 '24 12:05 sdbds

it seems works in my env.

Thank you! Perhaps my dataset may have an issue. I will test further.

kohya-ss avatar May 14 '24 12:05 kohya-ss

Now it works! Some optimizer seems to be needed trainable_params = list(controlnet.parameters()). Thank you for this!

kohya-ss avatar May 19 '24 08:05 kohya-ss