dolphin icon indicating copy to clipboard operation
dolphin copied to clipboard

Creating PyTorch Tensors hangs Dolphin

Open VIPTankz opened this issue 1 year ago • 3 comments

I've been playing around with the idea of having the python script that interacts with dolphin perform computation using a pytorch model. However, when doing this I found that creating a pytorch tensor hangs dolphin, but only after await event.framedrawn() or event.frameadvance() has been called. Importing Pytorch and even loading a pytorch model appears to work fine before one of the aforementioned functions are called. This is done with the --no-subinterpreters version as this uses numpy.

Here's the code for recreation:

from dolphin import event, gui, savestate, memory, controller
import sys
sys.path.append("C:\\Users\\TYLER\\AppData\\Local\\Programs\\Python\\Python38\\Lib\\site-packages")

import torch
import numpy as np

red = 0xffff0000

x = np.array([1,2,3,4])

frame_counter = 0
while True:
    frame_counter += 1
    # this first part works fine!
    tensor = torch.tensor(x, dtype=torch.float)

    

    (width, height, data) = await event.framedrawn()
    # await event.frameadvance() # no difference with this instead!

    # This line hands Dolphin!
    tens = torch.tensor(x, dtype=torch.float)
    

    gui.draw_text((10, 10), red, f"Frame: {frame_counter}")

VIPTankz avatar Nov 14 '23 15:11 VIPTankz