official-stockfish / nnue-pytorch

Stockfish NNUE (Chess evaluation) trainer in Pytorch
GNU General Public License v3.0
332 stars 100 forks source link

serialize.py not working #239

Closed benliu961 closed 1 year ago

benliu961 commented 1 year ago

Hello,

I am trying to convert a .nnue file into a .pt file with serialize.py and it doesn't seem to be working. I'm downloading the .nnue file from this website: https://tests.stockfishchess.org/nns?

I am getting an error of the form "shape '[23296, 1024]' is invalid for input of size 23499680"

How can I fix this?

Thank you!

Sopel97 commented 1 year ago

The current networks (as stored in .nnue) have the feature set HalfKAv2_hm, but serialize.py uses HalfKAv2_hm^ by default. You need to specify --features=HalfKAv2_hm.

umgefahren commented 1 year ago

I'm having a similar issue. After reading this I changed the features value, but I still get this error:

Traceback (most recent call last):
  File "/content/nnue-pytorch/serialize.py", line 361, in <module>
    main()
  File "/content/nnue-pytorch/serialize.py", line 319, in main
    reader = NNUEReader(f, feature_set)
  File "/content/nnue-pytorch/serialize.py", line 194, in __init__
    self.read_header(feature_set, fc_hash)
  File "/content/nnue-pytorch/serialize.py", line 215, in read_header
    self.read_int32(VERSION) # version
  File "/content/nnue-pytorch/serialize.py", line 292, in read_int32
    raise Exception("Expected: %x, got %x" % (expected, v))
Exception: Expected: 7af32f20, got 30322d2d

Why is this happening?

Sopel97 commented 1 year ago

What network are you trying to load, what's the CLI invokation, and what version of nnue-pytorch

umgefahren commented 1 year ago

I'm running the master branch of nnue-pytorch. My cli invocation was:

python3 serialize.py --features=HalfKAv2_hm ../nn.nnue converted.pt

That's the NNUE I downloaded: https://tests.stockfishchess.org/api/nn/nn-5af11540bbfe.nnue

Sopel97 commented 1 year ago

I'm running the master branch of nnue-pytorch. My cli invocation was:

python3 serialize.py --features=HalfKAv2_hm ../nn.nnue converted.pt

That's the NNUE I downloaded: https://tests.stockfishchess.org/api/nn/nn-5af11540bbfe.nnue

This network has L1 size of 1536. Since then the size was changed to 2048. You'd need to modify model.py to load it with the current master nnue-pytorch. Sadly we don't have an easy way to diagnose such issues and it's hard to decide on a modification of the network format to include the necessary information.

umgefahren commented 1 year ago

Is there a model I can download that has the 2048 size? Maybe it helps to give some additional context: My intention is to convert the PyTorch model to a CoreML model, this is however harder then expected.

I changed the variable to 1536, however it doesn't help. I'm also not entirely sure that I have installed the right dependencies. Maybe a requirements.txt file could clarify.

Sopel97 commented 1 year ago

https://tests.stockfishchess.org/api/nn/nn-c38c3d8d3920.nnue

what do you need the coreML model for? Either way, I don't think it has the necessary functions.

umgefahren commented 1 year ago

This didn't work either. I still get the same option.

I'm writing a chess engine, trying to take advantage of Apple Silicon.

Sopel97 commented 1 year ago

Can't replicate, the following works:

curl -L http://tests.stockfishchess.org/api/nn/nn-c38c3d8d3920.nnue -o nn-c38c3d8d3920.nnue
python serialize.py --features=HalfKAv2_hm nn-c38c3d8d3920.nnue nn-c38c3d8d3920.nnue.pt