-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed23a41
commit b7af036
Showing
3 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |