Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualizing chess position embeddings #276

Open
bastiansg opened this issue Mar 2, 2024 · 7 comments
Open

Visualizing chess position embeddings #276

bastiansg opened this issue Mar 2, 2024 · 7 comments

Comments

@bastiansg
Copy link

Hello,

I am currently working on a project where I aim to visualize embeddings of various chess positions. My goal is to appreciate some form of semantic segmentation for these positions.

I want to use nnue-pytorch for that, and I would like to know how I can, given a chess position, input it into the PyTorch network and extract some intermediate layer representation to be used as an embedding.

Thank you in advance for your time and assistance.

@Sopel97
Copy link
Member

Sopel97 commented Mar 2, 2024

input it into the PyTorch network

The simplest example would be here https://github.com/official-stockfish/nnue-pytorch/blob/master/cross_check_eval.py

and extract some intermediate layer representation

You need to make modifications to model.py to pass the intermediate layer outputs down the stack. The intermediate computations are not saved anywhere currently

@bastiansg
Copy link
Author

input it into the PyTorch network

The simplest example would be here https://github.com/official-stockfish/nnue-pytorch/blob/master/cross_check_eval.py

and extract some intermediate layer representation

You need to make modifications to model.py to pass the intermediate layer outputs down the stack. The intermediate computations are not saved anywhere currently

Great, I'll look into it, thank you very much!

@bastiansg
Copy link
Author

Is there any place from where I can download the already trained torch model used in Stockfish 16.1?

@Sopel97
Copy link
Member

Sopel97 commented Mar 5, 2024

would have to ask @linrock

you can also convert any .nnue network back to a pytorch model (though of course it will be lossy compared to the original model).

python serialize.py --features=HalfKAv2_hm from.nnue to.pt

though you should be able to just just .nnue models

@linrock
Copy link
Contributor

linrock commented Mar 5, 2024

Is there any place from where I can download the already trained torch model used in Stockfish 16.1?

that's long gone. i stopped keeping trained .ckpt files around since they're huge and i never use them.

using .nnue files should accomplish what you want.

@bastiansg
Copy link
Author

bastiansg commented Mar 10, 2024

Is there any place from where I can download the already trained torch model used in Stockfish 16.1?

that's long gone. i stopped keeping trained .ckpt files around since they're huge and i never use them.

using .nnue files should accomplish what you want.

You mean using the serialize.py script mentioned by @Sopel97 ? what about what he mentioned about that the .nnue will be lossy compared to the original model?

@vondele
Copy link
Member

vondele commented Mar 11, 2024

The lossy part is very minimal, can definitely be ignored for visualization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants