shyamsn97 / mario-gpt

[Neurips 2023] Generating Mario Levels with GPT2. Code for the paper "MarioGPT: Open-Ended Text2Level Generation through Large Language Models" https://arxiv.org/abs/2302.05981
https://huggingface.co/shyamsn97/Mario-GPT2-700-context-length
MIT License
1.11k stars 103 forks source link

And now what? #10

Closed fares57 closed 1 year ago

fares57 commented 1 year ago

Ok I sense this will be a very stupid question.

so we generate AI Mario levels. perfect! How do we play them? :p

shyamsn97 commented 1 year ago

Hey great timing haha. I've just updated the main branch README with instructions. Gonna update the pip package as well :)

shyamsn97 commented 1 year ago

now you can do:

from mario_gpt import MarioLM, SampleOutput
mario_lm = MarioLM()

# use cuda to speed stuff up
# import torch
# device = torch.device('cuda')
# mario_lm = mario_lm.to(device)

prompts = ["many pipes, many enemies, some blocks, high elevation"]

# generate level of size 1400, pump temperature up to ~2.4 for more stochastic but playable levels
generated_level = mario_lm.sample(
    prompts=prompts,
    num_steps=1400,
    temperature=2.0,
    use_tqdm=True
)

# play in interactive
generated_level.play()

Also, you can check out the lovely demo on huggingface: https://huggingface.co/spaces/multimodalart/mariogpt

fares57 commented 1 year ago

VScode (after 35' of waiting) warnings.warn( Using shyamsn97/Mario-GPT2-700-context-length tokenizer shape: torch.Size([1, 672]), torch.Size([1, 1401]) first: 56, last: 56: 100%|███████████| 1400/1400 [35:25<00:00, 1.52s/it] Traceback (most recent call last): File "c:/Users/ikout/Documents/DEVELOPMENT/pythonjams/mariogpt.py", line 15, in generated_level.play() AttributeError: 'Tensor' object has no attribute 'play'

the colab that a fan made is not working either.

huggingface works only with the examples . it gives error when I try to generate mine

shyamsn97 commented 1 year ago

Seems like you’re using an older version? Try uninstalling and installing it from the GitHub repo again

shyamsn97 commented 1 year ago

And yeah the huggingface demo needs to be updated with the newer version of the code.

fares57 commented 1 year ago

Seems like you’re using an older version? Try uninstalling and installing it from the GitHub repo again

Cloning into 'mario-gpt'... git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

shyamsn97 commented 1 year ago

Looks like you probably have to configure git: https://docs.github.com/en/get-started/quickstart/set-up-git

asi-9 commented 1 year ago

Facing this error -> RuntimeError: shape '[-1, 14]' is invalid for input of size 701.

image

shyamsn97 commented 1 year ago

Looks like you may be running an older version so the examples have changed slightly:

Can you run this in python?

from importlib.metadata import version
print(version('mario-gpt'))

it should print '0.1.2'

asi-9 commented 1 year ago

its 0.1.1, how do I install the newer version. I just downloaded then why was 0.1.1 installed ? image

shyamsn97 commented 1 year ago

Yeah looks like it says 0.1.1, so you should re install it either with:

pip install mario-gpt --upgrade

or by cloning the repo

git clone git@github.com:shyamsn97/mario-gpt.git
python setup.py install
asi-9 commented 1 year ago

I can't get it to run :( image

shyamsn97 commented 1 year ago

Actually it is working 🙂! Now you don’t have to use the view_level method. You can do generated_level.level to view the strings, generated_level.img to view the image, and generated_level.play() to actually play the level

shyamsn97 commented 1 year ago

Full example from README


from mario_gpt import MarioLM, SampleOutput

# pretrained_model = shyamsn97/Mario-GPT2-700-context-length

mario_lm = MarioLM()

# use cuda to speed stuff up
# import torch
# device = torch.device('cuda')
# mario_lm = mario_lm.to(device)

prompts = ["many pipes, many enemies, some blocks, high elevation"]

# generate level of size 1400, pump temperature up to ~2.4 for more stochastic but playable levels
generated_level = mario_lm.sample(
    prompts=prompts,
    num_steps=1400,
    temperature=2.0,
    use_tqdm=True
)

# show string list
generated_level.level

# show PIL image
generated_level.img

# save image
generated_level.img.save("generated_level.png")

# save text level to file
generated_level.save("generated_level.txt")

# play in interactive
generated_level.play()

# run Astar agent
generated_level.run_astar()

# load from text file
loaded_level = SampleOutput.load("generated_level.txt")

# play from loaded (should be the same level that we generated)
loaded_level.play()
...
asi-9 commented 1 year ago

Worked, thank you!

shyamsn97 commented 1 year ago

Awesome!

shyamsn97 commented 1 year ago

Closing this as we added ways to play / run an astar agent on a level.