Skip to content

Handle torch.OutOfMemoryError gracefully instead of blocking the UI #8

@FRiMN

Description

@FRiMN

When a torch.OutOfMemoryError: CUDA out of memory exception occurs during generation, the application becomes blocking for new generation.

Expected behaviour:

  1. Catch the exception.
  2. Show a modal error dialog with a short message.
  3. Reset the UI state to “idle” so the user can start a new generation without restarting the program.

Relevant code locations (for context):

  • src/genui/operations.pyImageGenerationOperation.generate_image – the actual inference call.
  • src/genui/ui_widgets/window_mixins/generation_command.py – UI entry points that disable buttons and start the worker.
  • src/genui/main.pyWindow.show_error_modal_dialog – already exists, can be reused.

Exception:

torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 20.00 MiB. GPU 0 has a total capacity of 7.65 GiB of which 25.19 MiB is free. Including non-PyTorch memory, this process has 1.40 GiB memory in use. Of the allocated memory 1.19 GiB is allocated by PyTorch, and 109.31 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation.  See documentation for Memory Management  (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions