Commit 308011ee authored by sbl1996@126.com's avatar sbl1996@126.com

Add docs for running

parent f89ac8fe
...@@ -8,29 +8,21 @@ YGO Agent is a project to create a Yu-Gi-Oh! AI using deep learning (LLMs, RL). ...@@ -8,29 +8,21 @@ YGO Agent is a project to create a Yu-Gi-Oh! AI using deep learning (LLMs, RL).
## ygoai ## ygoai
`ygoai` is a set of AI agents for playing Yu-Gi-Oh! It aims to achieve superhuman performance like AlphaGo and AlphaZero, with or without human knowledge. Currently, we focus on using reinforcement learning to train the agents. `ygoai` is a set of AI agents for playing Yu-Gi-Oh! It aims to achieve superhuman performance like AlphaGo and AlphaZero, with or without human knowledge. Currently, we focus on using reinforcement learning to train the agents.
## TODO
### Documentation
- Add documentations of building and running
### Training ## Usage
- Eval with old models during training
- MTCS-based training
### Inference ### Obtain a trained agent
- MCTS-based planning
- Support of play in YGOPro
We provide some trained agents in the [releases](https://github.com/sbl1996/ygo-agent/releases/tag/v0.1). Check these `ptj` TorchScript files and download them to your local machine. The following usage assumes you have it.
## Usage Notice that the provided `ptj` can only run on GPU, but not CPU. Actually, the agent can run in real-time on CPU, we will provide a CPU version in the future.
### Serialize agent ### Play against the agent
After training, we can serialize the trained agent model to a file for later use without keeping source code of the model. The serialized model file will end with `.ptj` (PyTorch JIT) extension. We can use `eval.py` to play against the trained agent with a MUD-like interface in the terminal.
```bash ```bash
python -u eval.py --agent --checkpoint checkpoints/1234_1000M.pt --num_embeddings 999 --convert --optimize python -u eval.py --agent --deck ../assets/deck --lang chinese --checkpoint checkpoints/1234_1000M.ptj --play
``` ```
### Battle between two agents ### Battle between two agents
...@@ -41,8 +33,31 @@ We can use `battle.py` to let two agents play against each other and find out wh ...@@ -41,8 +33,31 @@ We can use `battle.py` to let two agents play against each other and find out wh
python -u battle.py --deck ../assets/deck --checkpoint1 checkpoints/1234_1000M.ptj --checkpoint2 checkpoints/9876_100M.ptj --num-episodes=256 --num_envs=32 --seed 0 python -u battle.py --deck ../assets/deck --checkpoint1 checkpoints/1234_1000M.ptj --checkpoint2 checkpoints/9876_100M.ptj --num-episodes=256 --num_envs=32 --seed 0
``` ```
### Running You can set `--num_envs=1 --verbose --record` to generate `.yrp` replay files.
TODO
### Serialize agent
After training, we can serialize the trained agent model to a file for later use without keeping source code of the model. The serialized model file will end with `.ptj` (PyTorch JIT) extension.
```bash
python -u eval.py --agent --checkpoint checkpoints/1234_1000M.pt --num_embeddings 999 --convert --optimize
```
## TODO
### Documentation
- Add documentations of building and running
### Training
- Evaluation with old models during training
- LSTM for memory
- League training following AlphaStar and ROA-Star
### Inference
- MCTS-based planning
- Support of play in YGOPro
## Related Projects ## Related Projects
......
...@@ -142,6 +142,9 @@ if __name__ == "__main__": ...@@ -142,6 +142,9 @@ if __name__ == "__main__":
envs = RecordEpisodeStatistics(envs) envs = RecordEpisodeStatistics(envs)
if args.agent: if args.agent:
if args.checkpoint.endswith(".ptj"):
agent = torch.jit.load(args.checkpoint)
else:
# count lines of code_list # count lines of code_list
embedding_shape = args.num_embeddings embedding_shape = args.num_embeddings
if embedding_shape is None: if embedding_shape is None:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment