Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Subprocess Refactoring and Cancel Generate Operator #274

Merged
merged 8 commits into from Oct 15, 2022
Merged

More Subprocess Refactoring and Cancel Generate Operator #274

merged 8 commits into from Oct 15, 2022

Conversation

NullSenseStudio
Copy link
Collaborator

  • Cancel Generate operator allows for stopping without killing the subprocess and reloading everything next time
  • Added send_intent() method to GeneratorProcess that mirrors what send_action() does
  • Subprocess state is now managed by the Backend class to clean up main()
  • Subprocess now uses a background thread for reading stdin so new intents can be processed while one is already running
  • Intents are split into their own generator functions that allow for lazy loading their dependencies and models, won't have to wait on stable diffusion models if you're only starting the subprocess for upscaling
  • Includes a fix for Setting "Precision" to a value other than "Automatic" causes the generator to load every time you generate #265

main() was getting cramped so moved clutter to a new Backend class. Intents get their own generator methods that also allow for lazy loading their dependencies and models.
@carson-katri carson-katri added this to the v0.0.8 milestone Oct 8, 2022
@carson-katri
Copy link
Owner

carson-katri commented Oct 8, 2022

Subprocess now uses a background thread for reading stdin so new intents can be processed while one is already running

I assume this is meant for the stop generation action, but I also tried testing upscaling while the generator was running. This did not work:

  File "/Users/carsonkatri/Documents/Art/Add-ons/Custom/Blender/dream_textures/generator_process.py", line 518, in main
    back.main_loop()
  File "/Users/carsonkatri/Documents/Art/Add-ons/Custom/Blender/dream_textures/generator_process.py", line 480, in main_loop
    (intent, args) = self.queue.pop()

During handling of the above exception, another exception occurred:

  File "/Users/carsonkatri/Documents/Art/Add-ons/Custom/Blender/dream_textures/generator_process.py", line 255, in send_exception
    sys.exit(1)
  File "/Users/carsonkatri/Documents/Art/Add-ons/Custom/Blender/dream_textures/generator_process.py", line 522, in main
    back.send_exception()
  File "/Users/carsonkatri/Documents/Art/Add-ons/Custom/Blender/dream_textures/generator_process.py", line 525, in <module>
    main()

So perhaps we can either disable the UI for the upscaling panel while generator is running or look into a fix for this.

@NullSenseStudio
Copy link
Collaborator Author

I wasn't quite able to replicate your error case but looks like I didn't make it properly wait if it had more than one intent in the queue. That should be okay now.

There is still an issue of multiple operators polling the action queue at the same time that will need addressed. I'll see what I can do about that later. Either disabling the operator while another is running or perhaps attaching a unique id to link each action to the intent that caused it.

  File "C:\Users\NullSense\AppData\Roaming\Blender Foundation\Blender\3.3\scripts\addons\dream-textures\generator_process.py", line 147, in upscale
    callbacks[action](**tup[1])
KeyError: 4

@NullSenseStudio
Copy link
Collaborator Author

Blocking operators is the most practical for now. Intent session id tracking could be useful if the subprocess would split tasks up between multiple GPUs, but just an idea to save for later.

bpy.context.scene.dream_textures_progress = 0
bpy.context.scene.dream_textures_info = ""
if not hasattr(context,'scene'):
context = bpy.context # modal context is sometimes missing scene?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's odd, since the scene is supposed to be in the global context, so all other contexts would be built on that (i assumed)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have mixed up where it was getting context from, or completely forgetting what caused the issue in the first place. There actually seems to be a problem with the context that kill_generator() gives it, the default context argument is somehow different from bpy.context when called. It should stop being an issue if I just leave the default as None and replace with bpy.context when that is the case.
image

Copy link
Owner

@carson-katri carson-katri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@carson-katri carson-katri merged commit e3a749b into carson-katri:main Oct 15, 2022
@NullSenseStudio NullSenseStudio deleted the cancel-generator branch October 16, 2022 00:56
JasonHoku pushed a commit to JasonHoku/dream-textures that referenced this pull request Dec 20, 2022
…i#274)

* subprocess refactoring

main() was getting cramped so moved clutter to a new Backend class. Intents get their own generator methods that also allow for lazy loading their dependencies and models.

* fix non-automatic precision always reloads model

* cancel generator operator

* small changes

* prevent stopped action from being sent when it shouldn't

* move property resets out of if timer block

* clear event before waiting

* block operators while subprocess is in use
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting "Precision" to a value other than "Automatic" causes the generator to load every time you generate
2 participants