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

Creating PyTorch Tensors hangs Dolphin #48

Open
VIPTankz opened this issue Nov 14, 2023 · 3 comments
Open

Creating PyTorch Tensors hangs Dolphin #48

VIPTankz opened this issue Nov 14, 2023 · 3 comments

Comments

@VIPTankz
Copy link

VIPTankz commented Nov 14, 2023

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}")
@Felk
Copy link
Owner

Felk commented Nov 14, 2023

Hey, thanks for reporting this issue. Just to make sure what version of the scripting fork this happens on, I see you're importing numpy and pytorch from a Python38 directory, so this is an issue with the Python Scripting Preview 2, correct?

@VIPTankz
Copy link
Author

Yes, this is an older version. Thanks for pointing that out - I've been using the new version for some other games, but was testing a new setup on the old mario kart version

@Felk
Copy link
Owner

Felk commented Nov 17, 2023

Sounds not good, I'll take a look. But fyi maybe I won't be able to fix it this year anymore due to a large vacation, christmas, new years and stuff, just so you know.

@VIPTankz VIPTankz changed the title Creating PyTorch Tensors hands Dolphin Creating PyTorch Tensors hangs Dolphin Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants