Skip to content

Commit

Permalink
A custom kernel for the feature transformer.
Browse files Browse the repository at this point in the history
A semi-sparse matrix multiplication with dense matrix. "Semi-sparse" because the indices are stored in a 2d array, with the first dimension being the position id, and the values being the row.
  • Loading branch information
Sopel97 committed Apr 26, 2021
1 parent fae9b9c commit 0764091
Show file tree
Hide file tree
Showing 7 changed files with 701 additions and 110 deletions.
20 changes: 17 additions & 3 deletions README.md
@@ -1,12 +1,26 @@
# Setup

#### Install PyTorch
```
python3 -m venv env
source env/bin/activate
pip install python-chess==0.31.4 pytorch-lightning torch matplotlib
```

# Build the fast DataLoader
This requires a C++17 compiler.
#### Install CuPy
First check what version of cuda is being used by pytorch.
```
import torch
torch.version.cuda
```
Then install CuPy with the matching CUDA version.
```
pip install cupy-cudaXXX
```
where XXX corresponds to the first 3 digits of the CUDA version. For example `cupy-cuda112` for CUDA 11.2.

#### Build the fast DataLoader
This requires a C++17 compiler and cmake.

Windows:
```
Expand Down Expand Up @@ -50,7 +64,7 @@ python train.py ... --features="HalfKP^"
## Current recommended training invocation

```
python train.py --smart-fen-skipping --random-fen-skipping 10 --batch-size 16384 --threads 8 --num-workers 8 --gpus 1 trainingdata validationdata
python train.py --smart-fen-skipping --random-fen-skipping 10 --batch-size 16384 --threads 8 --num-workers 8 --gpus 1 trainingdata validationdata
```
best nets have been trained with 16B d9-scored nets, training runs >200 epochs

Expand Down
4 changes: 2 additions & 2 deletions cross_check_eval.py
Expand Up @@ -16,9 +16,9 @@ def make_data_reader(data_path, feature_set):
return nnue_bin_dataset.NNUEBinData(data_path, feature_set)

def eval_model_batch(model, batch):
us, them, white, black, outcome, score = batch.contents.get_tensors('cpu')
us, them, white_indices, white_values, black_indices, black_values, outcome, score = batch.contents.get_tensors('cpu')

evals = [v.item() for v in model.forward(us, them, white, black) * 600.0]
evals = [v.item() for v in model.forward(us, them, white_indices, white_values, black_indices, black_values) * 600.0]
for i in range(len(evals)):
if them[i] > 0.5:
evals[i] = -evals[i]
Expand Down

0 comments on commit 0764091

Please sign in to comment.