Skip to content

Creating PyTorch Tensors hangs Dolphin #48

@VIPTankz

Description

@VIPTankz

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}")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions