---
license: apache-2.0
base_model: haor/Mortal-S42
library_name: onnx
tags:
- onnx
- mahjong
- riichi-mahjong
- mortal
---

# Mortal-S42 (ONNX)

An ONNX export of the decision model [haor/Mortal-S42](https://huggingface.co/haor/Mortal-S42), a
[Mortal](https://github.com/Equim-chan/Mortal) v4 model for four-player riichi mahjong.
Hosted here because the original repository only has PyTorch weights; it is used by
[mahjong-copilot](https://github.com/jason1yuan/mahjong-copilot), an offline mahjong study
aid that reads the game window and never touches the game.

## Changes from the original

- Exported from revision `524981f21a929e3c3b269f65af79b84163bd02ca`, file `weights/s42-inference.pth`, with `torch.onnx.export`
  (opset 18, dynamic batch axis). The encoder ("brain", 40 residual blocks, 192
  channels) and the Q head ("dqn") are exported together as one graph. The weights are
  not changed, retrained or quantized.
- On 605 decision points taken from game logs, the ONNX model and the original
  PyTorch model pick the same best action every time; the largest difference in a legal
  action's Q value is 9.5e-6.

## Input and output

- `obs`: float32 `[batch, 1012, 34]`, Mortal's v4 observation, as encoded by
  libriichi's `obs_repr`.
- `mask`: bool `[batch, 46]`, the legal actions.
- `q`: float32 `[batch, 46]`, the Q value of each action; illegal actions are `-inf`.
  Mortal plays the action with the highest Q.

## Files

| File | SHA-256 |
|---|---|
| `model.onnx` | `30381bf21389e2d25d3edf48fed11bf772336ef3daeee67d1bdae7fb9dd30cb4` |
| `NOTICE` | `23724aa97bcab1e29695616c0a0ac1bdd1b28517751211c4766b9a8ea0dbf9a9` |
| `model-identity.json` | `18b6cee4a6b6a4a7152fa19360dd19cbc6190293851519cebbb87cad3eaf6a7f` |

## License

- The weights are under the Apache License 2.0, as stated by the original repository;
  see `LICENSE` and the upstream `NOTICE`, kept as it is. `model-identity.json` is the
  upstream description of the weights, also kept as it is.
- The network structure in the graph was traced from Mortal's `mortal/model.py`
  (commit `0cff2b52982be5b1163aa9a62fb01f03ce91e0d2`), which is under the GNU Affero General Public License v3.0 or
  later; see `LICENSE.AGPL`. Mortal's source code is at
  https://github.com/Equim-chan/Mortal.
