Coder Social home page Coder Social logo

shyamsn97 / mario-gpt Goto Github PK

View Code? Open in Web Editor NEW
1.1K 1.1K 100.0 35.67 MB

[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

Home Page: https://huggingface.co/shyamsn97/Mario-GPT2-700-context-length

License: MIT License

Makefile 0.25% Python 51.71% Jupyter Notebook 48.04%

mario-gpt's People

Contributors

chayim avatar grandpere avatar osanseviero avatar shyamsn97 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mario-gpt's Issues

How to load model after train?

After training using your training code example, I have file .bin.
Can you tell me how to load it to use generate level?
Thank you.

RuntimeError: invalid multinomial distribution

Using the prompts: many pipes, many enemies, no blocks, low elevation

shape: torch.Size([1, 673]), torch.Size([1, 1304]) first: 56, last: 88:  93%|██████████████████████████████████████████████████████████████▎    | 1303/1400 [02:43<00:12,  7.97it/s]Traceback (most recent call last):
  File "/home/me/apps/mariogpt/capturePlay.py", line 38, in <module>
    generated_level = mario_lm.sample(
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/mario_gpt/lm/gpt.py", line 54, in sample
    return sampler(
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/mario_gpt/sampler.py", line 248, in __call__
    return self.sample(*args, **kwargs)
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/mario_gpt/sampler.py", line 223, in sample
    next_tokens, encoder_hidden_states = self.step(
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/mario_gpt/sampler.py", line 172, in step
    next_tokens = torch.multinomial(probs, num_samples=1).squeeze(1)
RuntimeError: invalid multinomial distribution (sum of probabilities <= 0)

Runtime error in prompter.py

I'm trying to use it, but get the error

File "python3.9/site-packages/mario_gpt/prompter.py", line 113, in output_hidden
self.feature_extraction(prompt, return_tensors="pt")[0]
AttributeError: 'list' object has no attribute 'mean'

code:

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()

# Continue generation
generated_level_continued = mario_lm.sample(
    seed=generated_level,
    prompts=prompts,
    num_steps=1400,
    temperature=2.0,
    use_tqdm=True
)

# 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()

Can you check what's wrong with it, or I'm doing something wrong

Trained from base model output characters seem to be wrong

Hi, very interesting project! I'm trying to reproduce the results training from base and running into a problem. Using the training notebook with default parameters on 20k steps, the model is converging to a loss of ~0.05. I'm getting reasonable looking outputs sampling from this trained model but the characters look wrong:

Screenshot 2023-10-18 at 2 19 03 PM

Any ideas on what's going wrong here?

Why this mario gpt script is laggy?

This is the script:

from mario_gpt import MarioLM

mario_lm = MarioLM()

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

generated_level = mario_lm.sample(
prompts=prompts,
num_steps=100,
temperature=2.0,
use_tqdm=True
)

play in interactive

generated_level.play()

run Astar agent

generated_level.run_astar()

And I need more num_steps, but the AI lags when it reach more than 100 steps... its possible to get performance with this python library?

Some simple benchmarks

I don't see the Wiki enabled in this repo or I'd suggest putting them there. Maybe a new section at the bottom of the README so people can get a general idea of how long generation takes?

This was with the default example provided in the README

#MarioGPU Benchmarks
## CPU (Intel i7-12700K)
Execution time: 293.0745s

## CPU (AMD Ryzen 9 5950X)
Execution time: 384.3558s

## CPU (Intel Xeon E-2176G (2 cores))
Execution time: 751.6939s

## CUDA (Nvidia Quadro P620)
Execution time: 186.1026s

## CUDA (Nvidia 3070)
Execution time: 21.4382s

## CUDA (Nvidia 3090 Ti)
Execution time: 11.7694s

The poor performance of MarioBert

Thanks for your great work. I tried to implement MarioBERT myself, but the inpainting results were not good. I used the pre-trained model "shyamsn97/MarioBert-448-inpaint-context-length" you provided. I would appreciate it if you can give me some suggestions.

Error generating levels

After training the model and generating levels according to the instructions I got a level like this.
image
I wrote the code on google colab. Please help me to solve this problem, thanks a lot.

Example code from mario_gpt should possibly be mario_gpt.lm

Hi,

First of all thanks for your novel implementation! This is very cool to see.

When running the minimal code snippet provided in the readme, I got the following error:

C:\Users\Mossly\Desktop>py mariotest.py
Traceback (most recent call last):
  File "C:\Users\Mossly\Desktop\mariotest.py", line 1, in <module>
    from mario_gpt import MarioLM
ImportError: cannot import name 'MarioLM' from 'mario_gpt' (C:\Users\Mossly\AppData\Local\Programs\Python\Python310\lib\site-packages\mario_gpt\__init__.py)

I resolved it by changing the line:
from mario_gpt import MarioLM
to
from mario_gpt.lm import MarioLM

Perhaps this is just a simple syntactical mistake? Or it could be user error on my part...

Thanks for your attention!

This is cool!

Hi!
i love it!
will there be new enemies, levels and maybe midi music for it?

kind regards

Fine-tuned tokenizer

Hello,
Your project is awesome, and I'm delighted to have such a fantastic project.
When I cloned your project and trained it myself, I tried to save the tokenizer like save model, but I found the tokenizer_config.json and tokenizer.json not like your config. I don't know how to resize the vocab from 50256 to 256 and set "endoftext" token to id = 0. Could you give me some tips how to fine-tune the tokenizer? I did this because when I ran trained model, I have to use your tokenizer, if I use the tokenizer that I saved decode will go wrong.

This is my tokenizer_config.json file
image

This is my tokenizer.json file
image
image

Doesn't works

Hi, i did try to use your exemple but it doesnt works. See the message on the screenshot.
Mario-GPT

you example script

from mario_gpt.lm import MarioLM
from mario_gpt.utils import view_level, convert_level_to_png

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

mario_lm = MarioLM()

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

generate level of size 700, pump temperature up to ~2.4 for more stochastic but playable levels

generated_level = mario_lm.sample(
prompts=prompts,
num_steps=700,
temperature=2.0,
use_tqdm=True
)

show string list

view_level(generated_level, mario_lm.tokenizer)
convert_level_to_png(generated_level, "generated_level.png", mario_lm.tokenizer)

Failed to evaluate! 'TensorBoardTracker' object has no attribute 'add_image'

I think I meet one problem about evaluation.I am looking forward to your help.

tracker = self.accelerator.get_tracker("tensorboard")
        tracker.add_image(
            "image", np.array(out.img), i, dataformats="HWC"
        )
except Exception as e:
    print("Failed to evaluate!", e)

Besides,I can always see this output during the trainning process,should I deal with this problem?

REPLACING <PIL.PngImagePlugin.PngImageFile image mode=RGB size=16x16 at 0x16D2A446C10> (96, 13)
REPLACING <PIL.PngImagePlugin.PngImageFile image mode=RGB size=16x16 at 0x16D2A446C10> (97, 13)
REPLACING <PIL.PngImagePlugin.PngImageFile image mode=RGB size=16x16 at 0x16D2A446C10> (98, 13)
REPLACING <PIL.PngImagePlugin.PngImageFile image mode=RGB size=16x16 at 0x16D2A446C10> (99, 13)
REPLACING <PIL.PngImagePlugin.PngImageFile image mode=RGB size=16x16 at 0x16D2A446C10> (100, 13)

Thank you!

RuntimeError: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED

This happens randomly when generating a level.

Using the prompts: no blocks, no pipes, many goombas, fireball

shape: torch.Size([1, 678]), torch.Size([1, 1393]) first: 56, last: 51:  99%|██████████████████████████████████████████████████████████████████▌| 1392/1400 [02:58<00:01,  7.82it/s]Traceback (most recent call last):
  File "/home/me/apps/mariogpt/capturePlay.py", line 38, in <module>
    generated_level = mario_lm.sample(                                                                                                                                                File "/home/me/apps/mariogpt/lib/python3.10/site-packages/mario_gpt/lm/gpt.py", line 54, in sample
    return sampler(
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/mario_gpt/sampler.py", line 248, in __call__
    return self.sample(*args, **kwargs)
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/mario_gpt/sampler.py", line 223, in sample
    next_tokens, encoder_hidden_states = self.step(
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/mario_gpt/sampler.py", line 158, in step
    out = self.mario_lm.lm(
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/transformers/models/gpt2/modeling_gpt2.py", line 1043, in forward
    transformer_outputs = self.transformer(
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/transformers/models/gpt2/modeling_gpt2.py", line 887, in forward
    outputs = block(
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/transformers/models/gpt2/modeling_gpt2.py", line 388, in forward
    attn_outputs = self.attn(
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/transformers/models/gpt2/modeling_gpt2.py", line 329, in forward
    attn_output, attn_weights = self._attn(query, key, value, attention_mask, head_mask)
  File "/home/me/apps/mariogpt/lib/python3.10/site-packages/transformers/models/gpt2/modeling_gpt2.py", line 216, in _attn
    attn_output = torch.matmul(attn_weights, value)
RuntimeError: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED when calling `cublasSgemmStridedBatched( handle, opa, opb, m, n, k, &alpha, a, lda, stridea, b, ldb, strideb, &beta, c, ldc, stridec, num_batches)`

I'm using:

generated_level = mario_lm.sample(
    prompts=prompts,
    num_steps=1400,
    #num_steps=100,
    temperature=2.0,
    use_tqdm=True
)

This was happening less frequently in 0.1.2 it feels like. I just upgraded to 0.1.3.

colab notebook

HI!

I saw your paper; I think it's a fantastic project! I noticed that there isn't a colab notebook available for people to try out the code. So I took the liberty of creating one. Here's the link to the notebook

I am also happy to contribute via PR; just let me know how you would prefer.

How to use MarioBert?

May I ask how to use the MarioBert in this repo?
I tried to call MarioLM(mask_model=True), but MarioBert has no sample method:

    generated_level = mario_lm.sample(
AttributeError: 'MarioBert' object has no attribute 'sample'

Evaluation Model

Hello, I want to evaluate the model but i don't see the code about it, i still a student. Please give me some help

And now what?

Ok I sense this will be a very stupid question.

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

Getting this issue... TrainingConfig can't load

`ImportError Traceback (most recent call last)
in <cell line: 2>()
1 import torch
----> 2 from mario_gpt import MarioDataset, MarioLM, TrainingConfig, MarioGPTTrainer
3
4 # create basic gpt model
5 BASE = "distilgpt2"

ImportError: cannot import name 'TrainingConfig' from 'mario_gpt' (/usr/local/lib/python3.10/dist-packages/mario_gpt/init.py)`

How to get the source code of simulator?

Hi Shyam, I'm recently following this work and I want to make some extensions to the simulator. I want to know how you get the jar packages here? If the source code is not open-source, is it possible to send me a copy? Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.