# Dengeki

Search-less shogi AI project scaffold.

## Quickstart

```bash
uv sync
uv run python scripts/run_phase1.py
uv run python scripts/run_phase2.py
uv run python scripts/run_phase3.py
```

Smoke run (fast):

```bash
uv run python scripts/run_phase1.py train.data.num_phase1_positions=200
uv run python scripts/run_phase2.py train.epochs=1 train.max_steps_per_epoch=20 train.batch_size=8
uv run python scripts/run_phase3.py train.ppo.epochs=1 train.self_play_games=16
```

If needed, make the local YaneuraOu binary executable once:

```bash
chmod +x bin/YaneuraOuNNUE_20240624_avx2
```

Staged phase1 generation (recommended for v0 quality ramp-up):

```bash
uv run python scripts/run_phase1_curriculum.py
```

Staged phase2 distillation over stage datasets:

```bash
uv run python scripts/run_phase2_curriculum.py
```

For large datasets, increase Parquet streaming chunk size:

```bash
uv run python scripts/run_phase2.py train.parquet_batch_size=4096
```

Staged phase3 searchless RL refinement:

```bash
uv run python scripts/run_phase3_curriculum.py
```

Or run one stage manually with stronger teacher settings:

```bash
uv run python scripts/run_phase1.py \
  train.engine=local_yaneuraou_quality \
  train.data.num_phase1_positions=30000
```

Main project notes are in `docs/dengeki.md` and `docs/project_blueprint_v0.md`.

Policy label space follows cshogi dlshogi-compatible labels (`2187 = 27 * 81`).

Sequence decoder uses `mambapy` Mamba blocks.
Spatial encoder stacks long-kernel + stem-kernel mixed spatial blocks.

Decoder backend can be switched with `model.decoder_impl=mamba|mamba2`.
`mamba2` requires extra runtime deps (`einops` and `mamba_ssm` triton ops).

`smsnet_tiny` model knobs are in `configs/model/smsnet_tiny.yaml` (`encoder_blocks`, `decoder_blocks`, `hidden_dim`).
If label mapping changes, regenerate phase1 data before running phase2.

Phase1 random initialization knobs are in `configs/data/v0_local.yaml` (`initial_diversify_prob`, `initial_random_plies_min`, `initial_random_plies_max`).
CPU utilization tuning for phase1 is `data.phase1_workers` (multi-process sharded generation) and `engine.threads` (per-engine thread count).
Phase1 progress is shown with tqdm progress bars (`data.disable_progress_bar=true` to disable).

Model profiles:

- `smsnet_tiny` (baseline)
- `smsnet_small` (recommended on RTX4070)
- `smsnet_base` (recommended on A6000/5090 class)

Preset configs:

```bash
# Local 4070 (small)
uv run python scripts/run_phase1.py --config-name train/phase1_local_small
uv run python scripts/run_phase2.py --config-name train/phase2_local_small
uv run python scripts/run_phase3.py --config-name train/phase3_local_small
uv run python scripts/run_phase2_curriculum.py --config-name train/phase2_curriculum_local_small
uv run python scripts/run_phase3_curriculum.py --config-name train/phase3_curriculum_local_small

# Cloud (base)
uv run python scripts/run_phase1.py --config-name train/phase1_cloud_base
uv run python scripts/run_phase2.py --config-name train/phase2_cloud_base
uv run python scripts/run_phase3.py --config-name train/phase3_cloud_base
uv run python scripts/run_phase2_curriculum.py --config-name train/phase2_curriculum_cloud_base
uv run python scripts/run_phase3_curriculum.py --config-name train/phase3_curriculum_cloud_base
```
