DrCyanide / cyanic-sd-krita

A Stable Diffusion plugin for Krita, compatible with A1111 and SD.Next
70 stars 4 forks source link

Switching to Txt2Img, Img2Img, or Inpaint spits out errors #20

Closed rexelbartolome closed 10 months ago

rexelbartolome commented 11 months ago

It spits out similar errors when:

SD.next is running and you open Krita afterwards. If you open Krita, then open SD.next, then switch to img2img or txt2img tab in the CyanicSD dropdown docker

KeyError
Python 3.8.1: C:\Program Files\Krita (x64)\bin\krita.exe
Wed Nov  8 07:28:02 2023

A problem occurred in a Python script.  Here is the sequence of
function calls leading up to the error, in the order they occurred.

 C:\Program Files\Krita (x64)\lib\krita-python-libs\krita\dockwidgetfactory.py in createDockWidget(self=<krita.dockwidgetfactory.DockWidgetFactory object>)
   14         super(DockWidgetFactory, self).__init__(_id, _dockPosition)
   15         self.klass = _klass
   16 
   17     def createDockWidget(self):
   18         return self.klass()
self = <krita.dockwidgetfactory.DockWidgetFactory object>
self.klass = <class 'cyanic.cyanic.CyanicDocker'>

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\cyanic.py in __init__(self=<cyanic.cyanic.CyanicDocker object>)
   51 
   52         # Set the initial page
   53         self.change_page()
   54 
   55     # This was part of the template, might be relevant later
self = <cyanic.cyanic.CyanicDocker object>
self.change_page = <bound method CyanicDocker.change_page of <cyanic.cyanic.CyanicDocker object>>

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\cyanic.py in change_page(self=<cyanic.cyanic.CyanicDocker object>)
   63                 self.settings_controller.set('pages.last', page['name'])
   64                 self.settings_controller.save()
   65                 page['content']()
   66         self.update()
   67 
page = {'content': <bound method CyanicDocker.show_txt2img of <cyanic.cyanic.CyanicDocker object>>, 'name': 'Txt2Img'}

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\cyanic.py in show_txt2img(self=<cyanic.cyanic.CyanicDocker object>)
   74 
   75     def show_txt2img(self):
   76         self.content_area.setWidget(Txt2ImgPage(self.settings_controller, self.api))
   77 
   78     def show_img2img(self):
self = <cyanic.cyanic.CyanicDocker object>
self.content_area = <PyQt5.QtWidgets.QScrollArea object>
self.content_area.setWidget = <built-in method setWidget of QScrollArea object>
global Txt2ImgPage = <class 'cyanic.pages.txt2img.Txt2ImgPage'>
self.settings_controller = <cyanic.settings_controller.SettingsController object>
self.api = <cyanic.sdapi_v1.SDAPI object>

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\pages\txt2img.py in __init__(self=<cyanic.pages.txt2img.Txt2ImgPage object>, settings_controller=<cyanic.settings_controller.SettingsController object>, api=<cyanic.sdapi_v1.SDAPI object>)
   35             self.layout().addWidget(hires_collapsed)
   36 
   37         self.extension_widget = ExtensionWidget(self.settings_controller, self.api)
   38         extension_collapsed = CollapsibleWidget('Extensions', self.extension_widget)
   39         if not self.settings_controller.get('hide_ui.extensions'):
self = <cyanic.pages.txt2img.Txt2ImgPage object>
self.extension_widget undefined
global ExtensionWidget = <class 'cyanic.widgets.extensions.ExtensionWidget'>
self.settings_controller = <cyanic.settings_controller.SettingsController object>
self.api = <cyanic.sdapi_v1.SDAPI object>

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\extensions.py in __init__(self=<cyanic.widgets.extensions.ExtensionWidget object>, settings_controller=<cyanic.settings_controller.SettingsController object>, api=<cyanic.sdapi_v1.SDAPI object>)
   18 
   19 
   20         self.controlnet_widget = ControlNetExtension(self.settings_controller, self.api)
   21         controlnet_collapse = CollapsibleWidget('ControlNet', self.controlnet_widget)
   22         if self.server_supported['controlnet'] and not 'controlnet' in self.settings_controller.get('hide_ui.hidden_extensions'):
self = <cyanic.widgets.extensions.ExtensionWidget object>
self.controlnet_widget undefined
global ControlNetExtension = <class 'cyanic.extension_widgets.controlnet.ControlNetExtension'>
self.settings_controller = <cyanic.settings_controller.SettingsController object>
self.api = <cyanic.sdapi_v1.SDAPI object>

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\extension_widgets\controlnet.py in __init__(self=<cyanic.extension_widgets.controlnet.ControlNetExtension object>, settings_controller=<cyanic.settings_controller.SettingsController object>, api=<cyanic.sdapi_v1.SDAPI object>)
   12         self.settings_controller = settings_controller
   13         self.api = api
   14         self.cnapi = ControlNetAPI(self.api)
   15         self.setLayout(QVBoxLayout())
   16         self.layout().setContentsMargins(0,0,0,0)
self = <cyanic.extension_widgets.controlnet.ControlNetExtension object>
self.cnapi undefined
global ControlNetAPI = <class 'cyanic.extension_widgets.controlnet.ControlNetAPI'>
self.api = <cyanic.sdapi_v1.SDAPI object>

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\extension_widgets\controlnet.py in __init__(self=<cyanic.extension_widgets.controlnet.ControlNetAPI object>, api=<cyanic.sdapi_v1.SDAPI object>)
  478         self.get_modules()
  479         self.get_control_types()
  480         self.get_settings()
  481 
  482 
self = <cyanic.extension_widgets.controlnet.ControlNetAPI object>
self.get_settings = <bound method ControlNetAPI.get_settings of <cya...tension_widgets.controlnet.ControlNetAPI object>>

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\extension_widgets\controlnet.py in get_settings(self=<cyanic.extension_widgets.controlnet.ControlNetAPI object>)
  507     def get_settings(self):
  508         self.settings = self.api.get('/controlnet/settings')
  509         self.tabs = self.settings['control_net_unit_count']
  510 
  511     def preview(self, image:str, module:str, processor_res, threshold_a, threshold_b):
self = <cyanic.extension_widgets.controlnet.ControlNetAPI object>
self.tabs = 0
self.settings = {'control_net_max_models_num': 1}
KeyError: 'control_net_unit_count'
    __cause__ = None
    __class__ = <class 'KeyError'>
    __context__ = None
    __delattr__ = <method-wrapper '__delattr__' of KeyError object>
    __dict__ = {}
    __dir__ = <built-in method __dir__ of KeyError object>
    __doc__ = 'Mapping key not found.'
    __eq__ = <method-wrapper '__eq__' of KeyError object>
    __format__ = <built-in method __format__ of KeyError object>
    __ge__ = <method-wrapper '__ge__' of KeyError object>
    __getattribute__ = <method-wrapper '__getattribute__' of KeyError object>
    __gt__ = <method-wrapper '__gt__' of KeyError object>
    __hash__ = <method-wrapper '__hash__' of KeyError object>
    __init__ = <method-wrapper '__init__' of KeyError object>
    __init_subclass__ = <built-in method __init_subclass__ of type object>
    __le__ = <method-wrapper '__le__' of KeyError object>
    __lt__ = <method-wrapper '__lt__' of KeyError object>
    __ne__ = <method-wrapper '__ne__' of KeyError object>
    __new__ = <built-in method __new__ of type object>
    __reduce__ = <built-in method __reduce__ of KeyError object>
    __reduce_ex__ = <built-in method __reduce_ex__ of KeyError object>
    __repr__ = <method-wrapper '__repr__' of KeyError object>
    __setattr__ = <method-wrapper '__setattr__' of KeyError object>
    __setstate__ = <built-in method __setstate__ of KeyError object>
    __sizeof__ = <built-in method __sizeof__ of KeyError object>
    __str__ = <method-wrapper '__str__' of KeyError object>
    __subclasshook__ = <built-in method __subclasshook__ of type object>
    __suppress_context__ = False
    __traceback__ = <traceback object>
    args = ('control_net_unit_count',)
    with_traceback = <built-in method with_traceback of KeyError object>

The above is a description of an error in a Python program.  Here is
the original traceback:

Traceback (most recent call last):
  File "C:\Program Files\Krita (x64)\lib\krita-python-libs\krita\dockwidgetfactory.py", line 18, in createDockWidget
    return self.klass()
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\cyanic.py", line 53, in __init__
    self.change_page()
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\cyanic.py", line 65, in change_page
    page['content']()
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\cyanic.py", line 76, in show_txt2img
    self.content_area.setWidget(Txt2ImgPage(self.settings_controller, self.api))
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\pages\txt2img.py", line 37, in __init__
    self.extension_widget = ExtensionWidget(self.settings_controller, self.api)
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\extensions.py", line 20, in __init__
    self.controlnet_widget = ControlNetExtension(self.settings_controller, self.api)
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\extension_widgets\controlnet.py", line 14, in __init__
    self.cnapi = ControlNetAPI(self.api)
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\extension_widgets\controlnet.py", line 480, in __init__
    self.get_settings()
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\extension_widgets\controlnet.py", line 509, in get_settings
    self.tabs = self.settings['control_net_unit_count']
KeyError: 'control_net_unit_count'
rexelbartolome commented 11 months ago

This is what shows up when I used A1111 instead.

TypeError
Python 3.8.1: C:\Program Files\Krita (x64)\bin\krita.exe
Wed Nov  8 07:39:33 2023

A problem occurred in a Python script.  Here is the sequence of
function calls leading up to the error, in the order they occurred.

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\cyanic.py in change_page(self=<cyanic.cyanic.CyanicDocker object>)
   63                 self.settings_controller.set('pages.last', page['name'])
   64                 self.settings_controller.save()
   65                 page['content']()
   66         self.update()
   67 
page = {'content': <bound method CyanicDocker.show_txt2img of <cyanic.cyanic.CyanicDocker object>>, 'name': 'Txt2Img'}

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\cyanic.py in show_txt2img(self=<cyanic.cyanic.CyanicDocker object>)
   74 
   75     def show_txt2img(self):
   76         self.content_area.setWidget(Txt2ImgPage(self.settings_controller, self.api))
   77 
   78     def show_img2img(self):
self = <cyanic.cyanic.CyanicDocker object>
self.content_area = <PyQt5.QtWidgets.QScrollArea object>
self.content_area.setWidget = <built-in method setWidget of QScrollArea object>
global Txt2ImgPage = <class 'cyanic.pages.txt2img.Txt2ImgPage'>
self.settings_controller = <cyanic.settings_controller.SettingsController object>
self.api = <cyanic.sdapi_v1.SDAPI object>

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\pages\txt2img.py in __init__(self=<cyanic.pages.txt2img.Txt2ImgPage object>, settings_controller=<cyanic.settings_controller.SettingsController object>, api=<cyanic.sdapi_v1.SDAPI object>)
   35             self.layout().addWidget(hires_collapsed)
   36 
   37         self.extension_widget = ExtensionWidget(self.settings_controller, self.api)
   38         extension_collapsed = CollapsibleWidget('Extensions', self.extension_widget)
   39         if not self.settings_controller.get('hide_ui.extensions'):
self = <cyanic.pages.txt2img.Txt2ImgPage object>
self.extension_widget undefined
global ExtensionWidget = <class 'cyanic.widgets.extensions.ExtensionWidget'>
self.settings_controller = <cyanic.settings_controller.SettingsController object>
self.api = <cyanic.sdapi_v1.SDAPI object>

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\extensions.py in __init__(self=<cyanic.widgets.extensions.ExtensionWidget object>, settings_controller=<cyanic.settings_controller.SettingsController object>, api=<cyanic.sdapi_v1.SDAPI object>)
   18 
   19 
   20         self.controlnet_widget = ControlNetExtension(self.settings_controller, self.api)
   21         controlnet_collapse = CollapsibleWidget('ControlNet', self.controlnet_widget)
   22         if self.server_supported['controlnet'] and not 'controlnet' in self.settings_controller.get('hide_ui.hidden_extensions'):
self = <cyanic.widgets.extensions.ExtensionWidget object>
self.controlnet_widget undefined
global ControlNetExtension = <class 'cyanic.extension_widgets.controlnet.ControlNetExtension'>
self.settings_controller = <cyanic.settings_controller.SettingsController object>
self.api = <cyanic.sdapi_v1.SDAPI object>

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\extension_widgets\controlnet.py in __init__(self=<cyanic.extension_widgets.controlnet.ControlNetExtension object>, settings_controller=<cyanic.settings_controller.SettingsController object>, api=<cyanic.sdapi_v1.SDAPI object>)
   12         self.settings_controller = settings_controller
   13         self.api = api
   14         self.cnapi = ControlNetAPI(self.api)
   15         self.setLayout(QVBoxLayout())
   16         self.layout().setContentsMargins(0,0,0,0)
self = <cyanic.extension_widgets.controlnet.ControlNetExtension object>
self.cnapi undefined
global ControlNetAPI = <class 'cyanic.extension_widgets.controlnet.ControlNetAPI'>
self.api = <cyanic.sdapi_v1.SDAPI object>

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\extension_widgets\controlnet.py in __init__(self=<cyanic.extension_widgets.controlnet.ControlNetAPI object>, api=<cyanic.sdapi_v1.SDAPI object>)
  477         self.get_models()
  478         self.get_modules()
  479         self.get_control_types()
  480         self.get_settings()
  481 
self = <cyanic.extension_widgets.controlnet.ControlNetAPI object>
self.get_control_types = <bound method ControlNetAPI.get_control_types of...tension_widgets.controlnet.ControlNetAPI object>>

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\extension_widgets\controlnet.py in get_control_types(self=<cyanic.extension_widgets.controlnet.ControlNetAPI object>)
  503 
  504     def get_control_types(self):
  505         self.control_types = self.api.get('/controlnet/control_types')['control_types']
  506 
  507     def get_settings(self):
self = <cyanic.extension_widgets.controlnet.ControlNetAPI object>
self.control_types = {}
self.api = <cyanic.sdapi_v1.SDAPI object>
self.api.get = <bound method SDAPI.get of <cyanic.sdapi_v1.SDAPI object>>
TypeError: 'NoneType' object is not subscriptable
    __cause__ = None
    __class__ = <class 'TypeError'>
    __context__ = None
    __delattr__ = <method-wrapper '__delattr__' of TypeError object>
    __dict__ = {}
    __dir__ = <built-in method __dir__ of TypeError object>
    __doc__ = 'Inappropriate argument type.'
    __eq__ = <method-wrapper '__eq__' of TypeError object>
    __format__ = <built-in method __format__ of TypeError object>
    __ge__ = <method-wrapper '__ge__' of TypeError object>
    __getattribute__ = <method-wrapper '__getattribute__' of TypeError object>
    __gt__ = <method-wrapper '__gt__' of TypeError object>
    __hash__ = <method-wrapper '__hash__' of TypeError object>
    __init__ = <method-wrapper '__init__' of TypeError object>
    __init_subclass__ = <built-in method __init_subclass__ of type object>
    __le__ = <method-wrapper '__le__' of TypeError object>
    __lt__ = <method-wrapper '__lt__' of TypeError object>
    __ne__ = <method-wrapper '__ne__' of TypeError object>
    __new__ = <built-in method __new__ of type object>
    __reduce__ = <built-in method __reduce__ of TypeError object>
    __reduce_ex__ = <built-in method __reduce_ex__ of TypeError object>
    __repr__ = <method-wrapper '__repr__' of TypeError object>
    __setattr__ = <method-wrapper '__setattr__' of TypeError object>
    __setstate__ = <built-in method __setstate__ of TypeError object>
    __sizeof__ = <built-in method __sizeof__ of TypeError object>
    __str__ = <method-wrapper '__str__' of TypeError object>
    __subclasshook__ = <built-in method __subclasshook__ of type object>
    __suppress_context__ = False
    __traceback__ = <traceback object>
    args = ("'NoneType' object is not subscriptable",)
    with_traceback = <built-in method with_traceback of TypeError object>

The above is a description of an error in a Python program.  Here is
the original traceback:

Traceback (most recent call last):
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\cyanic.py", line 65, in change_page
    page['content']()
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\cyanic.py", line 76, in show_txt2img
    self.content_area.setWidget(Txt2ImgPage(self.settings_controller, self.api))
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\pages\txt2img.py", line 37, in __init__
    self.extension_widget = ExtensionWidget(self.settings_controller, self.api)
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\extensions.py", line 20, in __init__
    self.controlnet_widget = ControlNetExtension(self.settings_controller, self.api)
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\extension_widgets\controlnet.py", line 14, in __init__
    self.cnapi = ControlNetAPI(self.api)
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\extension_widgets\controlnet.py", line 479, in __init__
    self.get_control_types()
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\extension_widgets\controlnet.py", line 505, in get_control_types
    self.control_types = self.api.get('/controlnet/control_types')['control_types']
TypeError: 'NoneType' object is not subscriptable
DrCyanide commented 11 months ago

Both of those exceptions look like they're being triggered by the ControlNet extension not getting what it's expecting. What version of ControlNet do you have, if any? The UI should be checking if you have ControlNet installed before trying to use it, but I'll double check the code there.

SD.Next comes with ControlNet installed and the API enabled, which might explain why that version is getting closer to running, but it crashes in the settings.

DrCyanide commented 11 months ago

I pushed some changes that I hope will fix this issue for you. If you can test it out and get back to me that'd be great. If I don't hear back in a few days/weeks I'll assume it worked and close this issue.

rexelbartolome commented 11 months ago

Using SD.Next, it successfully connects to the running instance, but nothing gets generated at least in Krita.

This is what shows up when trying to generate for Img2Img and Txt2Img, a loading bar is visible in the running instance, but it's stuck at 1% in the Cyanic SD docker.

image

AttributeError
Python 3.8.1: C:\Program Files\Krita (x64)\bin\krita.exe
Sun Nov 12 04:36:43 2023

A problem occurred in a Python script.  Here is the sequence of
function calls leading up to the error, in the order they occurred.

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py in <lambda>()
   96             if self.kc.doc is None:
   97                 self.kc.create_new_doc()
   98             self.kc.run_as_thread(lambda: self.threadable_run(data), lambda: self.threadable_return(x, y, w, h, processing_instructions))
   99             self.progress_timer = QTimer()
  100             self.progress_timer.timeout.connect(lambda: self.progress_check(x,y,w,h))
self = <cyanic.widgets.generate.GenerateWidget object>
self.kc = <cyanic.krita_controller.KritaController object>
self.kc.run_as_thread = <bound method KritaController.run_as_thread of <cyanic.krita_controller.KritaController object>>
self.threadable_run = <bound method GenerateWidget.threadable_run of <cyanic.widgets.generate.GenerateWidget object>>
data undefined
self.threadable_return = <bound method GenerateWidget.threadable_return of <cyanic.widgets.generate.GenerateWidget object>>
x = 194
y = 198
w = 544
h = 544
processing_instructions = {}

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py in threadable_return(self=<cyanic.widgets.generate.GenerateWidget object>, x=194, y=198, w=544, h=544, processing_instructions={})
  163                 kc.results_to_layers(self.results, x, y, w, h, below_layer=layer)
  164             else:
  165                 kc.results_to_layers(self.results, x, y, w, h)
  166 
  167             if self.debug:
kc = <cyanic.krita_controller.KritaController object>
kc.results_to_layers = <bound method KritaController.results_to_layers of <cyanic.krita_controller.KritaController object>>
self = <cyanic.widgets.generate.GenerateWidget object>
self.results = {'images': ['/9j/4AAQSkZJRgABAQAAAQABAAD/4QPeRXhpZgAATU0AKgAA...JyiUUtL+FADaKWloAbRTqKAG0U6k/CgBKKWloAbRTqT8KAP/Z'], 'info': {'all_negative_prompts': [''], 'all_prompts': ['black and white, monochromatic, line art, 711 convenience store'], 'all_seeds': [3579695784], 'all_subseeds': [1395529424], 'batch_size': 1, 'cfg_scale': 7.0, 'clip_skip': 1, 'denoising_strength': 0.7, 'extra_generation_params': {}, 'face_restoration_model': None, ...}, 'parameters': {'alwayson_scripts': {}, 'batch_size': 1, 'cfg_scale': 7.0, 'clip_skip': 1, 'denoising_strength': 0.7, 'diffusers_guidance_rescale': 0.7, 'do_not_save_grid': False, 'do_not_save_samples': False, 'eta': None, 'full_quality': True, ...}}
x = 194
y = 198
w = 544
h = 544

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py in results_to_layers(self=<cyanic.krita_controller.KritaController object>, results={'images': ['/9j/4AAQSkZJRgABAQAAAQABAAD/4QPeRXhpZgAATU0AKgAA...JyiUUtL+FADaKWloAbRTqKAG0U6k/CgBKKWloAbRTqT8KAP/Z'], 'info': {'all_negative_prompts': [''], 'all_prompts': ['black and white, monochromatic, line art, 711 convenience store'], 'all_seeds': [3579695784], 'all_subseeds': [1395529424], 'batch_size': 1, 'cfg_scale': 7.0, 'clip_skip': 1, 'denoising_strength': 0.7, 'extra_generation_params': {}, 'face_restoration_model': None, ...}, 'parameters': {'alwayson_scripts': {}, 'batch_size': 1, 'cfg_scale': 7.0, 'clip_skip': 1, 'denoising_strength': 0.7, 'diffusers_guidance_rescale': 0.7, 'do_not_save_grid': False, 'do_not_save_samples': False, 'eta': None, 'full_quality': True, ...}}, x=194, y=198, w=544, h=544, layer_name='', below_active=False, below_layer=None)
  212                     continue
  213                 layer = self.doc.createNode(name, 'paintLayer')
  214                 byte_array, img_w, img_h = self.base64_to_pixeldata(results['images'][i])
  215                 layer.setPixelData(byte_array, x, y, img_w, img_h)
  216                 dest = None
byte_array undefined
img_w undefined
img_h undefined
self = <cyanic.krita_controller.KritaController object>
self.base64_to_pixeldata = <bound method KritaController.base64_to_pixeldat...<cyanic.krita_controller.KritaController object>>
results = {'images': ['/9j/4AAQSkZJRgABAQAAAQABAAD/4QPeRXhpZgAATU0AKgAA...JyiUUtL+FADaKWloAbRTqKAG0U6k/CgBKKWloAbRTqT8KAP/Z'], 'info': {'all_negative_prompts': [''], 'all_prompts': ['black and white, monochromatic, line art, 711 convenience store'], 'all_seeds': [3579695784], 'all_subseeds': [1395529424], 'batch_size': 1, 'cfg_scale': 7.0, 'clip_skip': 1, 'denoising_strength': 0.7, 'extra_generation_params': {}, 'face_restoration_model': None, ...}, 'parameters': {'alwayson_scripts': {}, 'batch_size': 1, 'cfg_scale': 7.0, 'clip_skip': 1, 'denoising_strength': 0.7, 'diffusers_guidance_rescale': 0.7, 'do_not_save_grid': False, 'do_not_save_samples': False, 'eta': None, 'full_quality': True, ...}}
i = 0

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py in base64_to_pixeldata(self=<cyanic.krita_controller.KritaController object>, base64str='/9j/4AAQSkZJRgABAQAAAQABAAD/4QPeRXhpZgAATU0AKgAA...JyiUUtL+FADaKWloAbRTqKAG0U6k/CgBKKWloAbRTqT8KAP/Z', width=-1, height=-1)
  143             image = image.scaledToHeight(height)
  144         image_bits = image.bits()
  145         image_bits.setsize(image.byteCount())
  146         byte_array = QByteArray(image_bits.asstring())
  147         return byte_array, image.width(), image.height()
image_bits = None
image_bits.setsize undefined
image = <PyQt5.QtGui.QImage object>
image.byteCount = <built-in method byteCount of QImage object>
AttributeError: 'NoneType' object has no attribute 'setsize'
    __cause__ = None
    __class__ = <class 'AttributeError'>
    __context__ = None
    __delattr__ = <method-wrapper '__delattr__' of AttributeError object>
    __dict__ = {}
    __dir__ = <built-in method __dir__ of AttributeError object>
    __doc__ = 'Attribute not found.'
    __eq__ = <method-wrapper '__eq__' of AttributeError object>
    __format__ = <built-in method __format__ of AttributeError object>
    __ge__ = <method-wrapper '__ge__' of AttributeError object>
    __getattribute__ = <method-wrapper '__getattribute__' of AttributeError object>
    __gt__ = <method-wrapper '__gt__' of AttributeError object>
    __hash__ = <method-wrapper '__hash__' of AttributeError object>
    __init__ = <method-wrapper '__init__' of AttributeError object>
    __init_subclass__ = <built-in method __init_subclass__ of type object>
    __le__ = <method-wrapper '__le__' of AttributeError object>
    __lt__ = <method-wrapper '__lt__' of AttributeError object>
    __ne__ = <method-wrapper '__ne__' of AttributeError object>
    __new__ = <built-in method __new__ of type object>
    __reduce__ = <built-in method __reduce__ of AttributeError object>
    __reduce_ex__ = <built-in method __reduce_ex__ of AttributeError object>
    __repr__ = <method-wrapper '__repr__' of AttributeError object>
    __setattr__ = <method-wrapper '__setattr__' of AttributeError object>
    __setstate__ = <built-in method __setstate__ of AttributeError object>
    __sizeof__ = <built-in method __sizeof__ of AttributeError object>
    __str__ = <method-wrapper '__str__' of AttributeError object>
    __subclasshook__ = <built-in method __subclasshook__ of type object>
    __suppress_context__ = False
    __traceback__ = <traceback object>
    args = ("'NoneType' object has no attribute 'setsize'",)
    with_traceback = <built-in method with_traceback of AttributeError object>

The above is a description of an error in a Python program.  Here is
the original traceback:

Traceback (most recent call last):
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py", line 98, in <lambda>
    self.kc.run_as_thread(lambda: self.threadable_run(data), lambda: self.threadable_return(x, y, w, h, processing_instructions))
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py", line 165, in threadable_return
    kc.results_to_layers(self.results, x, y, w, h)
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py", line 214, in results_to_layers
    byte_array, img_w, img_h = self.base64_to_pixeldata(results['images'][i])
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py", line 145, in base64_to_pixeldata
    image_bits.setsize(image.byteCount())
AttributeError: 'NoneType' object has no attribute 'setsize'

I don't see inpaint actually causing a loading bar/generation progress in the cli of SD.next and this error pops up.

TypeError
Python 3.8.1: C:\Program Files\Krita (x64)\bin\krita.exe
Sun Nov 12 04:34:57 2023

A problem occurred in a Python script.  Here is the sequence of
function calls leading up to the error, in the order they occurred.

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py in handle_generate_btn_click(self=<cyanic.widgets.generate.GenerateWidget object>)
   48             self.cancel()
   49         else:
   50             self.generate()
   51         self.update()
   52 
self = <cyanic.widgets.generate.GenerateWidget object>
self.generate = <bound method GenerateWidget.generate of <cyanic.widgets.generate.GenerateWidget object>>

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py in generate(self=<cyanic.widgets.generate.GenerateWidget object>)
   82         processing_instructions = {}
   83         for widget in self.list_of_widgets:
   84             data.update(widget.get_generation_data())
   85             if 'CYANIC' in data.keys(): # Special instructions for processing results are passed through with this tag.
   86                 processing_instructions.update(data.pop('CYANIC'))
data = {'height': 544, 'width': 544}
data.update = <built-in method update of dict object>
widget = <cyanic.widgets.mask.MaskWidget object>
widget.get_generation_data = <bound method MaskWidget.get_generation_data of <cyanic.widgets.mask.MaskWidget object>>

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\mask.py in get_generation_data(self=<cyanic.widgets.mask.MaskWidget object>)
  225         if self.variables['auto_update_mask'] and self.mask_uuid is not None:
  226             # Auto-update the mask
  227             self.kc.set_layer_uuid_as_active(self.mask_uuid)
  228             if self.selection_mode is 'selection':
  229                 s_x, s_y, s_w, s_h = self.kc.get_selection_bounds()
self = <cyanic.widgets.mask.MaskWidget object>
self.kc = <cyanic.krita_controller.KritaController object>
self.kc.set_layer_uuid_as_active = <bound method KritaController.set_layer_uuid_as_...<cyanic.krita_controller.KritaController object>>
self.mask_uuid = PyQt5.QtCore.QUuid('{4776c845-4aff-4619-b734-7b424a2d0dd5}')

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py in set_layer_uuid_as_active(self=<cyanic.krita_controller.KritaController object>, uuid=PyQt5.QtCore.QUuid('{4776c845-4aff-4619-b734-7b424a2d0dd5}'))
  289     def set_layer_uuid_as_active(self, uuid):
  290         node = self.get_layer_from_uuid(uuid)
  291         self.doc.setActiveNode(node)
  292 
  293     def get_selected_layer_img(self):
self = <cyanic.krita_controller.KritaController object>
self.doc = <PyKrita.krita.Document object>
self.doc.setActiveNode = <built-in method setActiveNode of Document object>
node = <PyQt5.QtCore.QObject object>
TypeError: setActiveNode(self, Node): argument 1 has unexpected type 'QObject'
    __cause__ = None
    __class__ = <class 'TypeError'>
    __context__ = None
    __delattr__ = <method-wrapper '__delattr__' of TypeError object>
    __dict__ = {}
    __dir__ = <built-in method __dir__ of TypeError object>
    __doc__ = 'Inappropriate argument type.'
    __eq__ = <method-wrapper '__eq__' of TypeError object>
    __format__ = <built-in method __format__ of TypeError object>
    __ge__ = <method-wrapper '__ge__' of TypeError object>
    __getattribute__ = <method-wrapper '__getattribute__' of TypeError object>
    __gt__ = <method-wrapper '__gt__' of TypeError object>
    __hash__ = <method-wrapper '__hash__' of TypeError object>
    __init__ = <method-wrapper '__init__' of TypeError object>
    __init_subclass__ = <built-in method __init_subclass__ of type object>
    __le__ = <method-wrapper '__le__' of TypeError object>
    __lt__ = <method-wrapper '__lt__' of TypeError object>
    __ne__ = <method-wrapper '__ne__' of TypeError object>
    __new__ = <built-in method __new__ of type object>
    __reduce__ = <built-in method __reduce__ of TypeError object>
    __reduce_ex__ = <built-in method __reduce_ex__ of TypeError object>
    __repr__ = <method-wrapper '__repr__' of TypeError object>
    __setattr__ = <method-wrapper '__setattr__' of TypeError object>
    __setstate__ = <built-in method __setstate__ of TypeError object>
    __sizeof__ = <built-in method __sizeof__ of TypeError object>
    __str__ = <method-wrapper '__str__' of TypeError object>
    __subclasshook__ = <built-in method __subclasshook__ of type object>
    __suppress_context__ = False
    __traceback__ = <traceback object>
    args = ("setActiveNode(self, Node): argument 1 has unexpected type 'QObject'",)
    with_traceback = <built-in method with_traceback of TypeError object>

The above is a description of an error in a Python program.  Here is
the original traceback:

Traceback (most recent call last):
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py", line 50, in handle_generate_btn_click
    self.generate()
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py", line 84, in generate
    data.update(widget.get_generation_data())
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\mask.py", line 227, in get_generation_data
    self.kc.set_layer_uuid_as_active(self.mask_uuid)
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py", line 291, in set_layer_uuid_as_active
    self.doc.setActiveNode(node)
TypeError: setActiveNode(self, Node): argument 1 has unexpected type 'QObject'
rexelbartolome commented 11 months ago

Using A1111, Txt2Img and Img2Img works without issues as far as I can tell.

Inpaint produces the same error though.

I don't remember much about my controlnet installation actually. I haven't updated a lot of my extensions for a long time, I'm actually thinking of doing a clean reinstall of A1111 but I'd prefer to install it through StabilityMatrix, but I'm afraid it will cause issues as it did when I was testing poipoi300's fork.

DrCyanide commented 11 months ago

I don't have time to do much digging right now, but I tried adding some extra checks to keep SD.Next from crashing. On my own system, SD.Next runs to completion and generates a final image, but the progress bar is stuck at 1% the entire time and it doesn't show previews while generating.

Can you give more detailed steps on what you're doing to get the Mask issue to come up? I thought masks were tested pretty in depth already, so I'm a little surprised that's having issues.

Also, what version of Krita are you using? I'm currently developing with Krita 5.2, but I was doing some checking on Krita 5.1.5 earlier.


Part of what sets this plugin apart from auto-sd-paint-ext (and poipoi's fork) is that the latter relied on tapping into internal function calls in A1111 and SD.Next that were always in development and never meant to be looked at by any other program. Whenever the Web UI designer thought they needed an extra parameter to generate a better picture, it would break auto-sd-paint-ext. I wrote a partial fix for that extension, but it can only do so much, and basically guesses that whatever's new can be ignored.

In contrast, Cyanic SD Krita uses the public API - code intended for other developers to interact with - which shouldn't ever change in a way that will break it, and if it does it will break ALL extensions. This means that the only issues I'll have are slight differences between A1111 and SD.Next (like handling LoRA descriptions...) and bugs in my own code. The latest versions of A1111 and SD.Next should always be safe as a result.

rexelbartolome commented 10 months ago

Txt2Img

I updated to Krita 5.2.1 and also updated the extension, then tried testing it with SD.Next. Got a different error this time for Txt2Img

Exception
Python 3.10.7: C:\Program Files\Krita (x64)\bin\krita.exe
Wed Nov 15 14:43:42 2023

A problem occurred in a Python script.  Here is the sequence of
function calls leading up to the error, in the order they occurred.

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py in <lambda>()
   96             if self.kc.doc is None:
   97                 self.kc.create_new_doc()
   98             self.kc.run_as_thread(lambda: self.threadable_run(data), lambda: self.threadable_return(x, y, w, h, processing_instructions))
   99             self.progress_timer = QTimer()
  100             self.progress_timer.timeout.connect(lambda: self.progress_check(x,y,w,h))
self = <cyanic.widgets.generate.GenerateWidget object>
self.kc = <cyanic.krita_controller.KritaController object>
self.kc.run_as_thread = <bound method KritaController.run_as_thread of <cyanic.krita_controller.KritaController object>>
self.threadable_run = <bound method GenerateWidget.threadable_run of <cyanic.widgets.generate.GenerateWidget object>>
data undefined
self.threadable_return = <bound method GenerateWidget.threadable_return of <cyanic.widgets.generate.GenerateWidget object>>
x = 0
y = 0
w = 1080
h = 1080
processing_instructions = {}

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py in threadable_return(self=<cyanic.widgets.generate.GenerateWidget object>, x=0, y=0, w=1080, h=1080, processing_instructions={})
  163                 kc.results_to_layers(self.results, x, y, w, h, below_layer=layer)
  164             else:
  165                 kc.results_to_layers(self.results, x, y, w, h)
  166 
  167             if self.debug:
kc = <cyanic.krita_controller.KritaController object>
kc.results_to_layers = <bound method KritaController.results_to_layers of <cyanic.krita_controller.KritaController object>>
self = <cyanic.widgets.generate.GenerateWidget object>
self.results = {'images': ['/9j/4AAQSkZJRgABAQAAAQABAAD/4QSyRXhpZgAATU0AKgAA...AMUmKKKAuFGKKKBhSUUUCEpKKKBiGkNFFAEbAmiiihDP/2Q==', '/9j/4AAQSkZJRgABAQAAAQABAAD/4QSyRXhpZgAATU0AKgAA...p2KKKxM2GDRg+lFFBIYNGD6UUUAGPajB9KKKADHtRRRSGf//Z'], 'info': {'all_negative_prompts': ['', ''], 'all_prompts': ['black and white, monochromatic, line art, 711 convenience store', 'black and white, monochromatic, line art, 711 convenience store'], 'all_seeds': [4072813236, 4072813237], 'all_subseeds': [1690789238, 1690789239], 'batch_size': 2, 'cfg_scale': 7.0, 'clip_skip': 1, 'denoising_strength': 0.7, 'extra_generation_params': {}, 'face_restoration_model': None, ...}, 'parameters': {'alwayson_scripts': {}, 'batch_size': 2, 'cfg_scale': 7.0, 'clip_skip': 1, 'denoising_strength': 0.7, 'diffusers_guidance_rescale': 0.7, 'do_not_save_grid': False, 'do_not_save_samples': False, 'enable_hr': True, 'eta': None, ...}}
x = 0
y = 0
w = 1080
h = 1080

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py in results_to_layers(self=<cyanic.krita_controller.KritaController object>, results={'images': ['/9j/4AAQSkZJRgABAQAAAQABAAD/4QSyRXhpZgAATU0AKgAA...AMUmKKKAuFGKKKBhSUUUCEpKKKBiGkNFFAEbAmiiihDP/2Q==', '/9j/4AAQSkZJRgABAQAAAQABAAD/4QSyRXhpZgAATU0AKgAA...p2KKKxM2GDRg+lFFBIYNGD6UUUAGPajB9KKKADHtRRRSGf//Z'], 'info': {'all_negative_prompts': ['', ''], 'all_prompts': ['black and white, monochromatic, line art, 711 convenience store', 'black and white, monochromatic, line art, 711 convenience store'], 'all_seeds': [4072813236, 4072813237], 'all_subseeds': [1690789238, 1690789239], 'batch_size': 2, 'cfg_scale': 7.0, 'clip_skip': 1, 'denoising_strength': 0.7, 'extra_generation_params': {}, 'face_restoration_model': None, ...}, 'parameters': {'alwayson_scripts': {}, 'batch_size': 2, 'cfg_scale': 7.0, 'clip_skip': 1, 'denoising_strength': 0.7, 'diffusers_guidance_rescale': 0.7, 'do_not_save_grid': False, 'do_not_save_samples': False, 'enable_hr': True, 'eta': None, ...}}, x=0, y=0, w=1080, h=1080, layer_name='', below_active=False, below_layer=None)
  222                 img_layer_parent.addChildNode(layer, dest)
  223                 if img_w != w or img_h != h:
  224                     self.transform_to_width_height(layer, x, y, w, h)
  225                 self.doc.refreshProjection()
  226 
self = <cyanic.krita_controller.KritaController object>
self.transform_to_width_height = <bound method KritaController.transform_to_width...<cyanic.krita_controller.KritaController object>>
layer = <PyKrita.krita.Node object>
x = 0
y = 0
w = 1080
h = 1080

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py in transform_to_width_height(self=<cyanic.krita_controller.KritaController object>, layer=<PyKrita.krita.Node object>, x=0, y=0, width=1080, height=1080)
  403                 self.scale_layer(layer, x, y, width, height)
  404         except Exception as e:
  405             raise Exception('Cyanic SD - %s' % e)
  406             self.scale_layer(layer, x, y, width, height)
  407 
builtinException = <class 'Exception'>
e undefined
Exception: Cyanic SD - division by zero
    __cause__ = None
    __class__ = <class 'Exception'>
    __context__ = ZeroDivisionError('division by zero')
    __delattr__ = <method-wrapper '__delattr__' of Exception object>
    __dict__ = {}
    __dir__ = <built-in method __dir__ of Exception object>
    __doc__ = 'Common base class for all non-exit exceptions.'
    __eq__ = <method-wrapper '__eq__' of Exception object>
    __format__ = <built-in method __format__ of Exception object>
    __ge__ = <method-wrapper '__ge__' of Exception object>
    __getattribute__ = <method-wrapper '__getattribute__' of Exception object>
    __gt__ = <method-wrapper '__gt__' of Exception object>
    __hash__ = <method-wrapper '__hash__' of Exception object>
    __init__ = <method-wrapper '__init__' of Exception object>
    __init_subclass__ = <built-in method __init_subclass__ of type object>
    __le__ = <method-wrapper '__le__' of Exception object>
    __lt__ = <method-wrapper '__lt__' of Exception object>
    __ne__ = <method-wrapper '__ne__' of Exception object>
    __new__ = <built-in method __new__ of type object>
    __reduce__ = <built-in method __reduce__ of Exception object>
    __reduce_ex__ = <built-in method __reduce_ex__ of Exception object>
    __repr__ = <method-wrapper '__repr__' of Exception object>
    __setattr__ = <method-wrapper '__setattr__' of Exception object>
    __setstate__ = <built-in method __setstate__ of Exception object>
    __sizeof__ = <built-in method __sizeof__ of Exception object>
    __str__ = <method-wrapper '__str__' of Exception object>
    __subclasshook__ = <built-in method __subclasshook__ of type object>
    __suppress_context__ = False
    __traceback__ = <traceback object>
    args = ('Cyanic SD - division by zero',)
    with_traceback = <built-in method with_traceback of Exception object>

The above is a description of an error in a Python program.  Here is
the original traceback:

Traceback (most recent call last):
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py", line 401, in transform_to_width_height
    self.use_transform_mask(layer, x, y, width, height)
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py", line 421, in use_transform_mask
    scale_x = width / bounds.width() * 1.0 # 0.4
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py", line 98, in <lambda>
    self.kc.run_as_thread(lambda: self.threadable_run(data), lambda: self.threadable_return(x, y, w, h, processing_instructions))
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py", line 165, in threadable_return
    kc.results_to_layers(self.results, x, y, w, h)
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py", line 224, in results_to_layers
    self.transform_to_width_height(layer, x, y, w, h)
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py", line 405, in transform_to_width_height
    raise Exception('Cyanic SD - %s' % e)
Exception: Cyanic SD - division by zero

Inpaint

As for the Inpaint/Masking, can't really tell whats going on but it's showing the same error I think.

Here's a recording of my steps if that helps.

https://github.com/DrCyanide/cyanic-sd-krita/assets/88552647/1868349c-9e2c-4c59-89f9-6858d5dd4a98

Exception
Python 3.10.7: C:\Program Files\Krita (x64)\bin\krita.exe
Wed Nov 15 15:02:50 2023

A problem occurred in a Python script.  Here is the sequence of
function calls leading up to the error, in the order they occurred.

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py in <lambda>()
   96             if self.kc.doc is None:
   97                 self.kc.create_new_doc()
   98             self.kc.run_as_thread(lambda: self.threadable_run(data), lambda: self.threadable_return(x, y, w, h, processing_instructions))
   99             self.progress_timer = QTimer()
  100             self.progress_timer.timeout.connect(lambda: self.progress_check(x,y,w,h))
self = <cyanic.widgets.generate.GenerateWidget object>
self.kc = <cyanic.krita_controller.KritaController object>
self.kc.run_as_thread = <bound method KritaController.run_as_thread of <cyanic.krita_controller.KritaController object>>
self.threadable_run = <bound method GenerateWidget.threadable_run of <cyanic.widgets.generate.GenerateWidget object>>
data undefined
self.threadable_return = <bound method GenerateWidget.threadable_return of <cyanic.widgets.generate.GenerateWidget object>>
x = 0
y = 0
w = 1080
h = 1080
processing_instructions = {'results_below_layer_uuid': PyQt5.QtCore.QUuid('{986c8988-591f-4ed0-b4af-5be320096af1}')}

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py in threadable_return(self=<cyanic.widgets.generate.GenerateWidget object>, x=0, y=0, w=1080, h=1080, processing_instructions={'results_below_layer_uuid': PyQt5.QtCore.QUuid('{986c8988-591f-4ed0-b4af-5be320096af1}')})
  161             if 'results_below_layer_uuid' in processing_instructions:
  162                 layer = kc.get_layer_from_uuid(processing_instructions['results_below_layer_uuid'])
  163                 kc.results_to_layers(self.results, x, y, w, h, below_layer=layer)
  164             else:
  165                 kc.results_to_layers(self.results, x, y, w, h)
kc = <cyanic.krita_controller.KritaController object>
kc.results_to_layers = <bound method KritaController.results_to_layers of <cyanic.krita_controller.KritaController object>>
self = <cyanic.widgets.generate.GenerateWidget object>
self.results = {'images': ['/9j/4AAQSkZJRgABAQAAAQABAAD/4QPCRXhpZgAATU0AKgAA...2jFFFc5YYooooAKKKKACiiigAooooAKKKKACiiigAooooA//Z', '/9j/4AAQSkZJRgABAQAAAQABAAD/4QPCRXhpZgAATU0AKgAA...aMUUVzlhiiiigAooooAKKKKACiiigAooooAKKKKACiiigD//Z'], 'info': {'all_negative_prompts': ['', ''], 'all_prompts': ['dragon', 'dragon'], 'all_seeds': [3924631144, 3924631145], 'all_subseeds': [3046992059, 3046992060], 'batch_size': 2, 'cfg_scale': 7.0, 'clip_skip': 1, 'denoising_strength': 0.7, 'extra_generation_params': {}, 'face_restoration_model': None, ...}, 'parameters': {'alwayson_scripts': {}, 'batch_size': 2, 'cfg_scale': 7.0, 'clip_skip': 1, 'denoising_strength': 0.7, 'diffusers_guidance_rescale': 0.7, 'do_not_save_grid': False, 'do_not_save_samples': False, 'eta': None, 'full_quality': True, ...}}
x = 0
y = 0
w = 1080
h = 1080
below_layer undefined
layer = <PyKrita.krita.Node object>

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py in results_to_layers(self=<cyanic.krita_controller.KritaController object>, results={'images': ['/9j/4AAQSkZJRgABAQAAAQABAAD/4QPCRXhpZgAATU0AKgAA...2jFFFc5YYooooAKKKKACiiigAooooAKKKKACiiigAooooA//Z', '/9j/4AAQSkZJRgABAQAAAQABAAD/4QPCRXhpZgAATU0AKgAA...aMUUVzlhiiiigAooooAKKKKACiiigAooooAKKKKACiiigD//Z'], 'info': {'all_negative_prompts': ['', ''], 'all_prompts': ['dragon', 'dragon'], 'all_seeds': [3924631144, 3924631145], 'all_subseeds': [3046992059, 3046992060], 'batch_size': 2, 'cfg_scale': 7.0, 'clip_skip': 1, 'denoising_strength': 0.7, 'extra_generation_params': {}, 'face_restoration_model': None, ...}, 'parameters': {'alwayson_scripts': {}, 'batch_size': 2, 'cfg_scale': 7.0, 'clip_skip': 1, 'denoising_strength': 0.7, 'diffusers_guidance_rescale': 0.7, 'do_not_save_grid': False, 'do_not_save_samples': False, 'eta': None, 'full_quality': True, ...}}, x=0, y=0, w=1080, h=1080, layer_name='', below_active=False, below_layer=<PyKrita.krita.Node object>)
  222                 img_layer_parent.addChildNode(layer, dest)
  223                 if img_w != w or img_h != h:
  224                     self.transform_to_width_height(layer, x, y, w, h)
  225                 self.doc.refreshProjection()
  226 
self = <cyanic.krita_controller.KritaController object>
self.transform_to_width_height = <bound method KritaController.transform_to_width...<cyanic.krita_controller.KritaController object>>
layer = <PyKrita.krita.Node object>
x = 0
y = 0
w = 1080
h = 1080

 C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py in transform_to_width_height(self=<cyanic.krita_controller.KritaController object>, layer=<PyKrita.krita.Node object>, x=0, y=0, width=1080, height=1080)
  403                 self.scale_layer(layer, x, y, width, height)
  404         except Exception as e:
  405             raise Exception('Cyanic SD - %s' % e)
  406             self.scale_layer(layer, x, y, width, height)
  407 
builtinException = <class 'Exception'>
e undefined
Exception: Cyanic SD - division by zero
    __cause__ = None
    __class__ = <class 'Exception'>
    __context__ = ZeroDivisionError('division by zero')
    __delattr__ = <method-wrapper '__delattr__' of Exception object>
    __dict__ = {}
    __dir__ = <built-in method __dir__ of Exception object>
    __doc__ = 'Common base class for all non-exit exceptions.'
    __eq__ = <method-wrapper '__eq__' of Exception object>
    __format__ = <built-in method __format__ of Exception object>
    __ge__ = <method-wrapper '__ge__' of Exception object>
    __getattribute__ = <method-wrapper '__getattribute__' of Exception object>
    __gt__ = <method-wrapper '__gt__' of Exception object>
    __hash__ = <method-wrapper '__hash__' of Exception object>
    __init__ = <method-wrapper '__init__' of Exception object>
    __init_subclass__ = <built-in method __init_subclass__ of type object>
    __le__ = <method-wrapper '__le__' of Exception object>
    __lt__ = <method-wrapper '__lt__' of Exception object>
    __ne__ = <method-wrapper '__ne__' of Exception object>
    __new__ = <built-in method __new__ of type object>
    __reduce__ = <built-in method __reduce__ of Exception object>
    __reduce_ex__ = <built-in method __reduce_ex__ of Exception object>
    __repr__ = <method-wrapper '__repr__' of Exception object>
    __setattr__ = <method-wrapper '__setattr__' of Exception object>
    __setstate__ = <built-in method __setstate__ of Exception object>
    __sizeof__ = <built-in method __sizeof__ of Exception object>
    __str__ = <method-wrapper '__str__' of Exception object>
    __subclasshook__ = <built-in method __subclasshook__ of type object>
    __suppress_context__ = False
    __traceback__ = <traceback object>
    args = ('Cyanic SD - division by zero',)
    with_traceback = <built-in method with_traceback of Exception object>

The above is a description of an error in a Python program.  Here is
the original traceback:

Traceback (most recent call last):
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py", line 401, in transform_to_width_height
    self.use_transform_mask(layer, x, y, width, height)
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py", line 421, in use_transform_mask
    scale_x = width / bounds.width() * 1.0 # 0.4
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py", line 98, in <lambda>
    self.kc.run_as_thread(lambda: self.threadable_run(data), lambda: self.threadable_return(x, y, w, h, processing_instructions))
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\widgets\generate.py", line 163, in threadable_return
    kc.results_to_layers(self.results, x, y, w, h, below_layer=layer)
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py", line 224, in results_to_layers
    self.transform_to_width_height(layer, x, y, w, h)
  File "C:\Users\My PC\AppData\Roaming\krita\pykrita\cyanic\krita_controller.py", line 405, in transform_to_width_height
    raise Exception('Cyanic SD - %s' % e)
Exception: Cyanic SD - division by zero

and I also sometimes get this in my SD.Next cli

15:02:50-456882 ERROR    API error: POST: http://127.0.0.1:7860/sdapi/v1/img2img {'error': 'OutOfMemoryError',
                         'detail': '', 'body': '', 'errors': 'CUDA out of memory. Tried to allocate 1.11 GiB (GPU 0;
                         6.00 GiB total capacity; 4.27 GiB already allocated; 98.34 MiB free; 4.37 GiB reserved in
                         total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to
                         avoid fragmentation.  See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF'}
15:02:50-464889 ERROR    HTTP API: OutOfMemoryError
┌───────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────┐
│ D:\stable-diffusion\vladmandic\automatic\venv\lib\site-packages\anyio\streams\memory.py:98 in receive               │
│                                                                                                                     │
│ D:\stable-diffusion\vladmandic\automatic\venv\lib\site-packages\anyio\streams\memory.py:93 in receive_nowait        │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
WouldBlock

During handling of the above exception, another exception occurred:

┌───────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────┐
│ D:\stable-diffusion\vladmandic\automatic\venv\lib\site-packages\starlette\middleware\base.py:78 in call_next        │
│                                                                                                                     │
│ D:\stable-diffusion\vladmandic\automatic\venv\lib\site-packages\anyio\streams\memory.py:118 in receive              │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
EndOfStream

During handling of the above exception, another exception occurred:

┌───────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────┐
│ D:\stable-diffusion\vladmandic\automatic\modules\middleware.py:41 in log_and_time                                   │
│                                                                                                                     │
│   40 │   │   │   ts = time.time()                                                                                   │
│ > 41 │   │   │   res: Response = await call_next(req)                                                               │
│   42 │   │   │   duration = str(round(time.time() - ts, 4))                                                         │
│                                                                                                                     │
│ D:\stable-diffusion\vladmandic\automatic\venv\lib\site-packages\starlette\middleware\base.py:84 in call_next        │
│                                                                                                                     │
│ D:\stable-diffusion\vladmandic\automatic\venv\lib\site-packages\starlette\middleware\base.py:70 in coro             │
│                                                                                                                     │
│ D:\stable-diffusion\vladmandic\automatic\venv\lib\site-packages\starlette\middleware\gzip.py:26 in __call__         │
│                                                                                                                     │
│ D:\stable-diffusion\vladmandic\automatic\venv\lib\site-packages\starlette\middleware\exceptions.py:79 in __call__   │
│                                                                                                                     │
│                                              ... 24 frames hidden ...                                               │
│                                                                                                                     │
│ D:\stable-diffusion\vladmandic\automatic\venv\lib\site-packages\torch\nn\modules\module.py:1501 in _call_impl       │
│                                                                                                                     │
│   1500 │   │   │   │   or _global_forward_hooks or _global_forward_pre_hooks):                                      │
│ > 1501 │   │   │   return forward_call(*args, **kwargs)                                                             │
│   1502 │   │   # Do not call functions when jit is used                                                             │
│                                                                                                                     │
│ D:\stable-diffusion\vladmandic\automatic\repositories\ldm\modules\diffusionmodules\model.py:138 in forward          │
│                                                                                                                     │
│   137 │   │                                                                                                         │
│ > 138 │   │   h = self.norm2(h)                                                                                     │
│   139 │   │   h = nonlinearity(h)                                                                                   │
│                                                                                                                     │
│ D:\stable-diffusion\vladmandic\automatic\venv\lib\site-packages\torch\nn\modules\module.py:1501 in _call_impl       │
│                                                                                                                     │
│   1500 │   │   │   │   or _global_forward_hooks or _global_forward_pre_hooks):                                      │
│ > 1501 │   │   │   return forward_call(*args, **kwargs)                                                             │
│   1502 │   │   # Do not call functions when jit is used                                                             │
│                                                                                                                     │
│ D:\stable-diffusion\vladmandic\automatic\venv\lib\site-packages\torch\nn\modules\normalization.py:273 in forward    │
│                                                                                                                     │
│   272 │   def forward(self, input: Tensor) -> Tensor:                                                               │
│ > 273 │   │   return F.group_norm(                                                                                  │
│   274 │   │   │   input, self.num_groups, self.weight, self.bias, self.eps)                                         │
│                                                                                                                     │
│ D:\stable-diffusion\vladmandic\automatic\venv\lib\site-packages\torch\nn\functional.py:2530 in group_norm           │
│                                                                                                                     │
│   2529 │   _verify_batch_size([input.size(0) * input.size(1) // num_groups, num_groups] + list(                     │
│ > 2530 │   return torch.group_norm(input, num_groups, weight, bias, eps, torch.backends.cudnn.e                     │
│   2531                                                                                                              │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
OutOfMemoryError: CUDA out of memory. Tried to allocate 1.11 GiB (GPU 0; 6.00 GiB total capacity; 4.27 GiB already
allocated; 98.34 MiB free; 4.37 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting
max_split_size_mb to avoid fragmentation.  See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF
DrCyanide commented 10 months ago

That video gave a very interesting insight - SD.Next had ValueError: height and width must be > 0 listed in the console. That would line up with why Krita was throwing errors as well, a width of 0 was being passed around somehow.

The SD.Next OutOfMemoryError should be from trying to generate more than your GPU can handle in one go. While trying to track this down, I fixed a bug that was keeping Batch Size from updating correctly (you might have had Batch Size 2 even though the UI showed 1), and observed a bug that passed the whole image to Inpaint instead of just selection (which would be a 1080x1080 image in your case, instead of the 704x620 you selected). Since both of those would result in more GPU being used than expected, it might be something like that causing the OOM.

I'm still trying to track down where the 0 originated, but I pushed a change that could help track down this issue. It creates a log.json file in your \pykrita\cyanic directory (you can check the install guide if you're having troubles finding it). Could you pull that change, reproduce the error, and upload that log file?

DrCyanide commented 10 months ago

Added a fix for SD.Next's progress bar, and fixed an auto-update mask issue with Use Selection (which was causing my tests to upload the whole image instead of just the selected part)

rexelbartolome commented 10 months ago

Here's the json :) log.json

Speaking of masks, it might interest you that someone developed a krita plugin for automatic object detection (quite fast too!) kind of like object select in Photoshop. https://github.com/Acly/krita-ai-tools

DrCyanide commented 10 months ago

Here's the json :) log.json

Was this the log immediately after the error was generated? To try and keep the log readable and not too personal I've written it so it only saves 1 entry. This log shows an image of 643x932 was requested, and the server gave this image back:

debug

Speaking of masks, it might interest you that someone developed a krita plugin for automatic object detection (quite fast too!) kind of like object select in Photoshop. https://github.com/Acly/krita-ai-tools

That is super cool! I knew Acly had written another Stable Diffusion plugin for Krita, but I didn't know about this quick selector.

rexelbartolome commented 10 months ago

Yup, seems about right, I've prompted a monochromatic, lineart, convenience store or something along those lines. And also low steps

DrCyanide commented 10 months ago

I just pushed another change to hopefully prevent these errors coming back. Can you test it and let me know if you're still having errors?

rexelbartolome commented 10 months ago

No errors popped up but the image isn't getting passed on to Krita unfortunately. It's just a fully transparent layer. I also tested out on a normal local installation of SD.Next instead of through StabilityMatrix but the same thing happens. This also happens for Img2Img

log-broken-SDNext.json Here's a video of it, it's a bit long since I haven't loaded the model yet. Krita also crashes if I cancel the ongoing generation then generate again afterwards. No errors pop up in the cli though.

https://github.com/DrCyanide/cyanic-sd-krita/assets/88552647/bc03af96-4e49-46eb-9609-58de7fd5089f

For comparison, I also tested out A1111 and it works fine.

log-success-A1111.json

https://github.com/DrCyanide/cyanic-sd-krita/assets/88552647/3acf098e-ea6f-4daa-b0f2-0749f6add9c1

DrCyanide commented 10 months ago

Well, 2x good news for you - I was finally able to reproduce your error on my computer, and I've got a fix now!

The problem wasn't SD.Next vs A1111 - both servers gave perfect responses. The problem was that I assumed every image I got back from the server would be a PNG, and at some point had changed my local copy of SD.Next to spit out PNG images. Your copy of SD.Next was returning JPEG images, which I was then telling Krita were PNGs, but they weren't valid PNGs so they were converted into an empty response.

TL;DR: Pull and try again, it should be fixed now!

rexelbartolome commented 10 months ago

wow, thanks so much! :D just tried it out and it works 😊