Skip to content

Commit

Permalink
add README and license
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmobobak committed Jun 28, 2023
1 parent ed23a41 commit b7af036
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "2.1.0"
edition = "2021"
description = "Converts marlinflow JSON networks into binary format, for use in chess engines."
authors = ["Cosmo Bobak"]
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Cosmo Bobak

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
62 changes: 61 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,64 @@
# nnue-jsontobin

A little utility for converting from [Marlinflow](https://github.com/dsekercioglu/marlinflow)'s NNUE JSON format into a binary NNUE for embedding into chess engine executables.
Currently supports relative networks and HalfKA networks.
Currently supports relative networks and HalfKA networks.

## Usage

Most typical usage is to convert a JSON file into a unified binary file, with an 8-bit output weight array.
This is achieved by running the following command:

```
nnue-jsontobin INPUT.json --unified OUTPUT.bin
```

This will produce a binary file with the following structure:

in C/C++:
```cpp
struct NetworkWeights {
std::array<std::int16_t, 768 * NEURONS * BUCKETS> feature_weights;
std::array<std::int16_t, NEURONS> feature_biases;
std::array<std::int8_t , NEURONS * 2> output_weights;
std::int16_t output_bias;
}
```
or, in Rust:
```rust
#[repr(C)]
struct NetworkWeights {
feature_weights: [i16; 768 * NEURONS * BUCKETS],
feature_biases: [i16; NEURONS],
output_weights: [i8; NEURONS * 2],
output_bias: i16,
}
```

Alternatively, you can produce split binary files, one for each field of the above struct.
This is achieved by running the following command:

```
nnue-jsontobin INPUT.json --split OUTPUT_DIR
```

The output directory will contain the following files:
```
feature_weights.bin
feature_biases.bin
output_weights.bin
output_bias.bin
```

For backwards compatibility, you can also produce a binary file with a 16-bit output weight array, by adding the `--big-out` flag.

`nnue-jsontobin` performs quantisation of the network weights during the conversion process, and by default uses 255 and 64 as the quantisation factors.

These factors are configurable with the `--qa` and `--qb` flags, respectively.

## Building

`nnue-jsontobin` is written in Rust, and can be built with `cargo build --release`.

## License

`nnue-jsontobin` is licensed under the MIT license.

0 comments on commit b7af036

Please sign in to comment.