Input planes for neural network

984 views
Skip to first unread message

Marek Balaz

unread,
Sep 28, 2020, 8:38:49 AM9/28/20
to LCZero
Hello guys,

I want to ask you about input planes that neural network obtains. I know, input consists of 112 planes with shape 8x8 (exactly 8x8x112), but I can't find out indexing in these planes. Chess board is defined by indicies A-H (from left to right)  for horizontal axis and 1-8 (from bottom to top) for vertical axis, but I need to know plane's indicies. For example, which indes corresponds for A1 - is it (0 - height, 0 - width)? or (7, 0)? Which index coressponds for H1? etc... :)

My second question is about rotation of planes between changing of players. AlphaZero has rule in which board is rotated after each move. So, when first player takes move, then chess board executes mirror rotation of board and in input are changed planes with figures of players (white figures become black and black figures become white). I think it's better for neural network. Do LC0 equal rotation after each move like AlphaZero?

My third question is about initialization of input at the begining of the game. What are values of planes that keep last 7 moves? Are their values set on zero? 

Thnaks for your answers! :)


brian.p.r...@gmail.com

unread,
Sep 28, 2020, 10:47:25 AM9/28/20
to LCZero
#1) You will have to read the code.
Here is one place to start:

#2) Yes, the Leela nets are trained always from white's perspective, so when black is on move things are switched.

#3) see #1 look for "history".  There are several options.

Trevor G

unread,
Sep 28, 2020, 11:06:07 AM9/28/20
to Marek Balaz, LCZero
I'd personally suggest looking at the training code. I think tfprocess.py and train.py

Looking at the training data itself might help. I think the input planes basically stay in the same structure that they are in the training data. I don't know if this will still work with the latest training data, but the TarTrainingFile class in lcztools was (when it was written) able to read training data, separate out the games and individual training records (positions) which can be inspected, and convert it back to a pychess game.
Example usage to load a training file and show a game here:

--
You received this message because you are subscribed to the Google Groups "LCZero" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lczero+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lczero/44397ea5-5e47-45a5-a3a0-89692678023en%40googlegroups.com.

brian.p.r...@gmail.com

unread,
Sep 28, 2020, 12:27:15 PM9/28/20
to LCZero
By the time the training code reads the input planes in the chunk files the contents are already done.
Moreover, there are many different formats and versions.
so-much-meta was great, but sadly out of date.

Trevor G

unread,
Sep 28, 2020, 1:13:14 PM9/28/20
to brian.p.r...@gmail.com, LCZero
Yes, very much out of date. Ultimately, the point is that I think there are two ways to make sense of the network architecture and input layers and encoding (past whatever high level documentation exists): (1) look at lczero’s c++ engine/evaluator code. (2) look at lczero’s training code and training data.

I personally felt it was easier to start with the training code and training data than the engine... However, maybe that’s not feasible anymore? I just saw that the links to the training data seem to be down.

Another place to look for pytorch implementations is dkappe’s repos;

Marek Balaz

unread,
Sep 29, 2020, 4:04:18 AM9/29/20
to LCZero
Thanks for your quick answers! 

Yes, I read class encoder.cc and some other files in LCZero's project, but positions are coded by bitwise coding and unfortunately I don't know how to understand it and I can't find method that converts bit code to matricies (or tensors). 

It's good idea to start code for training and show data from input. I will try it! 

Dátum: pondelok 28. septembra 2020, čas: 19:13:14 UTC+2, odosielateľ: Trevor

dka...@gmail.com

unread,
Oct 1, 2020, 7:48:39 PM10/1/20
to LCZero
So have a look at https://github.com/dkappe/badgyal/blob/master/badgyal/board2planes.py

This is the neural net code for a0lite. I ignore history, as you can tell and just duplicate the current board. But if you want to know indexing and so on, it’s in there.

One thing to note is that a position with black to move is first mirrored with colors flipped, then the policy needs to be flipped back.

Niko Grupen

unread,
Feb 24, 2021, 7:54:31 PM2/24/21
to LCZero
Hi All,

I'm interested in writing my own RL loop to do self-play training, so that I can examine how the features in different layers of the network evolve throughout training.

I don't necessarily need to port the pretrained lc0 weights to pytorch (tf is ok), but I do need to have access to the RL training loop. From what I have gathered so far, everything related to RL training with lc0 is boxed up in lc0.exe. I am ideally looking for a clean training loop like what python-chess offers -- see this link: https://python-chess.readthedocs.io/en/latest/engine.html

Will the repos mentioned here (a0lite, badgyal) support training/testing of lc0-scale networks in this way? The closest thing I have found is a0lite -- link here: https://github.com/dkappe/a0lite/blob/master/engine.py -- but I am not sure if this will support loading in weights from the lc0 best networks page, or if training a network in this sort of loop would just take way too long to converge.

Any thoughts would be greatly appreciated. 

Thank you!
Niko

brian.p.r...@gmail.com

unread,
Feb 25, 2021, 9:53:12 AM2/25/21
to LCZero
The self-play and RL training scripts from here worked for me.



dka...@gmail.com

unread,
Mar 16, 2021, 12:07:50 AM3/16/21
to LCZero
A0lite uses a pytorch training pipeline and produces torchscript format nets.

Dariouch Babaï

unread,
Mar 16, 2021, 3:54:50 AM3/16/21
to lcz...@googlegroups.com
Analyzing Representations inside Convolutional Neural Networks
https://api.semanticscholar.org/CorpusID:229363763

Cross posting, as I had confused your thread with the "from scratch one". you may have seen that ref. anyways. but I might be useful tools, when your 2 eyes will struggle in the non-2D tower space (many 2D planes).

Also, I hope that your RL loops you will share here, and that the starpos, could be an legal position, not having the starpos hardwired.
Thank you for updating this thread with your progress. I am curious about it. if i can be any help at bouncing ideas that the non-programming level (i can decrypt when motivated).  math.

Are you intending to do the RL pipeline non-distributed?  if that makes sense?
You received this message because you are subscribed to a topic in the Google Groups "LCZero" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lczero/2ZpnZqLAgaM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lczero+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lczero/944c7c8e-056c-42c5-93c8-e77655126828n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages