랭킹으로 돌아가기

vietnh1009/Super-mario-bros-PPO-pytorch

Python

Proximal Policy Optimization (PPO) algorithm for Super Mario Bros

reinforcement-learningppoppo2pytorchgympython3pythondeep-learningsuper-mario-brosmarioaiproximal-policy-optimization
스타 성장
스타
1.3k
포크
239
주간 성장
이슈
16
5001k
25년 10월26년 1월26년 4월26년 7월
아티팩트PyPIpip install super-mario-bros-ppo-pytorch
README

[PYTORCH] Proximal Policy Optimization (PPO) for playing Super Mario Bros

Introduction

Here is my python source code for training an agent to play super mario bros. By using Proximal Policy Optimization (PPO) algorithm introduced in the paper Proximal Policy Optimization Algorithms paper.

Talking about performance, my PPO-trained agent could complete 31/32 levels, which is much better than what I expected at the beginning.

For your information, PPO is the algorithm proposed by OpenAI and used for training OpenAI Five, which is the first AI to beat the world champions in an esports game. Specifically, The OpenAI Five dispatched a team of casters and ex-pros with MMR rankings in the 99.95th percentile of Dota 2 players in August 2018.









Sample results

Motivation

It has been a while since I have released my A3C implementation (A3C code) for training an agent to play super mario bros. Although the trained agent could complete levels quite fast and quite well (at least faster and better than I played :sweat_smile:), it still did not totally satisfy me. The main reason is, agent trained with A3C could only complete 19/32 levels, no matter how much I fine-tuned and tested. It motivated me to look for a new approach.

Before I decided to choose PPO as my next complete implementation, I had partially implemented a couple of other algorithms, including A2C and Rainbow. While the former did not show a big jump in performance, the latter is more suitable for more randomized environments/games, like ping-pong or space invaders.

How to use my code

With my code, you can:

  • Train your model by running python train.py. For example: python train.py --world 5 --stage 2 --lr 1e-4
  • Test your trained model by running python test.py. For example: python test.py --world 5 --stage 2

Note: If you got stuck at any level, try training again with different learning rates. You could conquer 31/32 levels like what I did, by changing only learning rate. Normally I set learning rate as 1e-3, 1e-4 or 1e-5. However, there are some difficult levels, including level 1-3, in which I finally trained successfully with learning rate of 7e-5 after failed for 70 times.

Docker

For being convenient, I provide Dockerfile which could be used for running training as well as test phases

Assume that docker image's name is ppo. You only want to use the first gpu. You already clone this repository and cd into it.

Build:

sudo docker build --network=host -t ppo .

Run:

docker run --runtime=nvidia -it --rm --volume="$PWD"/../Super-mario-bros-PPO-pytorch:/Super-mario-bros-PPO-pytorch --gpus device=0 ppo

Then inside docker container, you could simply run train.py or test.py scripts as mentioned above.

Note: There is a bug for rendering when using docker. Therefore, when you train or test by using docker, please comment line env.render() on script src/process.py for training or test.py for test. Then, you will not be able to see the window pop up for visualization anymore. But it is not a big problem, since the training process will still run, and the test process will end up with an output mp4 file for visualization

Why there is still level 8-4 missing?

In world 4-4, 7-4 and 8-4, map consists of puzzles where the player must choose the correct the path in order to move forward. If you choose a wrong path, you have to go through path you visited again. With some hardcore setting for the environment, the first 2 levels are solved. But the last level has not been solved yet.

관련 저장소
Developer-Y/cs-video-courses

List of Computer Science courses with video lectures.

computer-sciencealgorithms
82.6k11.4k
unslothai/unsloth

Unsloth is a local UI for training and running Gemma 4, Qwen3.6, DeepSeek, Kimi, GLM and other models.

PythonPyPIApache License 2.0fine-tuningllama
unsloth.ai/docs
68.7k6.2k
labmlai/annotated_deep_learning_paper_implementations

🧑‍🏫 60+ Implementations/tutorials of deep learning papers with side-by-side notes 📝; including transformers (original, xl, switch, feedback, vit, ...), optimizers (adam, adabelief, sophia, ...), gans(cyclegan, stylegan2, ...), 🎮 reinforcement learning (ppo, dqn), capsnet, distillation, ... 🧠

PythonPyPIMIT Licensedeep-learningdeep-learning-tutorial
nn.labml.ai
67.2k6.7k
ray-project/ray

Ray is an AI compute engine. Ray consists of a core distributed runtime and a set of AI Libraries for accelerating ML workloads.

PythonPyPIApache License 2.0raydistributed
ray.io
43.3k7.8k
rohitg00/ai-engineering-from-scratch

Learn it. Build it. Ship it for others.

PythonPyPIMIT Licenseagentsai
aiengineeringfromscratch.com
41.6k6.9k
sgl-project/sglang

SGLang is a high-performance serving framework for large language models and multimodal models.

PythonPyPIApache License 2.0cudainference
sglang.io
30.6k7.3k
eugeneyan/applied-ml

📚 Papers & tech blogs by companies sharing their work on data science & machine learning in production.

MIT Licenseapplied-machine-learningproduction
29.9k4k
d2l-ai/d2l-en

Interactive deep learning book with multi-framework code, math, and discussions. Adopted at 500 universities from 70 countries including Stanford, MIT, Harvard, and Cambridge.

PythonPyPIOtherdeep-learningmachine-learning
d2l.ai
29.2k5.1k
AI4Finance-Foundation/FinGPT

FinGPT: Open-Source Financial Large Language Models! Revolutionize 🔥 We release the trained model on HuggingFace.

Jupyter NotebookMIT Licensechatgptfinance
fingpt.io
20.9k3k
stefan-jansen/machine-learning-for-trading

Code for Machine Learning for Trading, 3rd edition — from data sourcing to live execution.

Jupyter NotebookMIT Licensemachine-learningtrading
ml4trading.io
20k5.4k
Unity-Technologies/ml-agents

The Unity Machine Learning Agents Toolkit (ML-Agents) is an open-source project that enables games and simulations to serve as environments for training intelligent agents using deep reinforcement learning and imitation learning.

C#Otherreinforcement-learningunity3d
unity.com/products/machine-learning-agents
19.6k4.5k
tensorflow/tensor2tensor

Library of deep learning models and datasets designed to make deep learning more accessible and accelerate ML research.

PythonPyPIApache License 2.0machine-learningmachine-translation
17.4k3.8k