Skip to content

Crash when adding any PyTorch layer during script execution (works in terminal) #22

Description

@ilya112358

I am trying to run neural network inference by calling a Python script, but the process crashes. After narrowing the issue down, it appears that the crash happens whenever a layer is added to a PyTorch model.

import qtm
import torch.nn as nn

class SingleEventModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc = nn.Linear(18,128) # if I comment this line, it does not crash

def test_model():
    m = SingleEventModel()
    print(m)

def add_menu():
    """Function for adding custom commands and setting up the menu in QTM"""
    qtm.gui.add_command("test_model")
    qtm.gui.set_command_execute_function("test_model", test_model)
    # Add menu and button
    menu_id = qtm.gui.insert_menu_submenu(None, "My menu")
    qtm.gui.insert_menu_button(menu_id, "test_model", "test_model")
    
if __name__ == "__main__":
    clear() # qtm terminal clear
    add_menu()

Pressing test_model button crashes the application.
Image

The same code runs correctly when executed directly in a terminal.
Image

OS: Windows 11
Pip list:
Image

I tried several solutions from ChatGPT like:

os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
os.environ["OMP_NUM_THREADS"] = "1"
os.environ["MKL_NUM_THREADS"] = "1"

Didn't help.
Any guidance on what might cause a crash and how to avoid it?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions