-
Notifications
You must be signed in to change notification settings - Fork 1k
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
A way to make 19x19 weights fit for other board sizes #2240
Comments
interesting, can you attatch the file, or upload pan.baidu |
can you play a bot on http://www.yss-aya.com/cgos/9x9/standings.html ? |
or release here, including the windows exe |
Great work, and let me congratulate on its release! To make it clear, the code modifies only the three lines in the weight file whose lengths depend on the board size: |
the compress diff is about 10%, but the gz format can be used directly
diff
|
The modified 9x9 weight is as strong as my 55th trained weight(much weaker than my 158th weight).13x13 is much stronger than the best trained weight.19x19 weight modified from trained 13x13 weight is very weak(as strong as 40th LZ weight.13x13 weight modified from 9x9 weight is weaker(about 10 to 18 kyu). |
maybe you can play against this bot |
9x9 isn't very strong(maybe as strong as the bot on CGOS).13x13 is very strong.1po can reach the top. |
here is rns 9x9 go programe |
I notice the compressed size of each weight are very small except one, indicate that the most content of them are identical, so I wrote following code to find them.
I wonder why the weight are suitable for other size? alphago papers say it can only work with 19x19?
|
@l1t1 As I said and you've found out, only three lines are changed (a very small portion of the whole 40b weights). The convolutional filters extract certain features that are common to all board sizes; the problem is just to figure out how to deal with fully-connected layers. Can you point out to me where in which AlphaGo paper it's said that "it can only work with 19x19" and what's the exact statement? |
i didnt find that in paper 1 (https://blog.csdn.net/u013390476/article/details/50925347) |
The converted weights, the corresponding leelaz engines, and a version of Lizzie that supports all these odd board sizes please upload to https://drive.google.com |
https://drive.google.com/file/d/1goxpawqozxBdbN50BKpmOhrtgSm6uqqU/view?usp=sharing All weight files modified from LZ # 205. 9x9 is only slightly stronger than Zen7 and much weaker than trained weights, so it's not included. According to @hzyhhzy, these are superhuman on 13x13, 15x15, and 17x17, but other board sizes are not tested. Lizzie shortcut keys/combinations: |
@alreadydone Thank you very much ! |
Can anyone please share 9x9 binary so we could use these trained nets ihavnoid/leelaz-ninenine#6 for this lizzie? |
@barrtgt Here you are. leelaz9.zip compiled off latest /next for 9x9 BTW we noticed leelaz compiled for even board sizes seem to be working (though I am aware that the code writing/reading training data is not OK with even size). The method of modifying the weights treat the two dimensions of the board separately and hence we can produce weights for rectangular boards (though transition between sizes with same parity may better preserve strength due to checkerboard pattern in value head), so I wonder if anyone is interested in taking up the challenge to adapt leelaz to support rectangular boards. (Note: NN code already separates width and height; symmetries down from 8 to 4; UI support not ready but should be easy to implement.) |
Yay! Thank you. |
dose the smaller board size result to shorter think time for a given weight? eg. 205-11 vs 205-19 |
at same playouts or visits |
@hzyhhzy |
I wrote a Python script board_resize.py to convert the weights based on my understanding of the methods according to discussions with @hzyhhzy and others. It's completely written in terms of matrix operations with numpy and scipy.sparse. I implemented two methods, called iterative method and rescaling method respectively. Let me explicate the details, in the hope of inspiring further work and progress. The iterative methodAs an example, to produce a 4x4 weight from a 5x5 weight, we use the following matrix (single_step_mat in the .py):
(plz ignore the boldface and coloring github put on my matrix (entered as a table)) The matrix has 4 rows and 5 columns which correspond to 4x4 and 5x5 respectively. For example, 4/5,1/5,0,0,0 means that the 1st line (line = row or column, 1st line = edge of board) of the 4x4 weight is 4/5 times the 1st line plus 1/5 times the 2nd line of the 5x5 weight. You can see that the 1st/last line gets a large contribution from the 1st/last line, so the peculiarity of the edge/corner is preserved. As we approach the center of the board, the weighting of the two adjacent lines approaches half-half. You could print out matrices (single_step_mat, iter_mat, rescale_mat) with different arguments as at the end of the .py file. To go from 5x5 to 3x3, we just first go from 5x5 to 4x4, then from 4x4 to 3x3, which corresponds to matrix multiplication/composition. This matrix is called of stride one, having many adjacent entries. Since the 256x361 weights in the value head exhibit checkerboard patterns (alternate between big and small values), stride-one can't be expected to work well on those weights, and we use a stride-two matrix to capture the even/odd parity. The following is the stride-two matrix to go from 5x5 to 3x3:
You can see the 1st and 3rd line (where 1 and 3 have the same parity) of the 5x5 weight goes into the 1st line of the 3x3 weight. To enlarge the board size, for example from 4x4 to 5x5, I use the following:
and from 4x4 to 6x6, with stride 2:
the rescaling methodThe idea is to rescale an image of mxm squares(pixels) to fit in one of nxn squares. Then, for each square x in the mxm image and each square y in the nxn image, calculate the portion of x that lies in y; then the weight at y will contribute that portion to the weight at x. Here is it in the matrix form (5x5->3x3, stride 1):
(note not only each row adds up to 1 (as we're doing weighted averaging) but also each column sums up to 3/5) and from 5x5 to 7x7 with stride 2 (splits into 3x3->4x4 for odd lines and 2x2->3x3 for even lines):
The rescale_mat function can treat "squares" on the edge as a 1x0.5 rectangle and squares in the corner as a 0.5x0.5 square, if edgewt is set to 0.5. By default, the iterative method is used for the value head weights (with stride 2) and the policy head biases (with stride 1). For the policy head weights, things are more complicated; I group together connections from i to j according to the value of (i-j) (so for nxn board there are (2n-1) groups), and apply the iterative method to each group. This is what single_step_fc_mat and iter_fc_mat are for. We could also apply the rescaling method to each group (with any stride if shrinking and stride 1 if enlarging), but I haven't implemented it. The rescaling method is implemented but not used by default; you may try the one suggested for val_w_mat in the .py. Finally, the value head weights need to be renormalized because the number of inputs change with board size; I use the quotient of the Euclidean lengths of the weight vectors as the factor (multiplier) for each filter. (Same for the policy head weights, but there the factor seems always close to 1.) However, even after these renormalization, we still observe that the policy of pass goes too low when board is shrinked and goes too high when it's enlarged. Also, for Minigo v15 weights (at least for # 990), the initial black winrate seems to increase as the board size is shrinked, from 60%+ for 17x17 to 90%+ for 13x13. I haven't got the chance to do a thorough investigation to figure out the reason and improve the methods. Maybe these problems can't be solved with modifying the weights without training with self-play games. My implementation seems to produce weights of similar strength as those produced by hzyhhzy's cpp. |
Since this approach works, albeit not perfectly, it seems very promising to freeze all weights in the residual blocks and train the policy/value heads only, starting from a converted model for self-play generation. I found that this is typically done with tf.stop_gradient or setting trainable=False in tf.Variable (I think the former is preferable), but I don't immediately see how I'd modify tfprocess.py. @Ttl: You mentioned in #1030 (comment) (March 2018) that you have the code already written (for freezing some layers); could you please share it? Thanks in advance. |
Set |
@Ttl Thanks! will look into it. BTW I forgot to say how to use the script: |
@alreadydone you could maybe tune the renormalization so that the policy of pass is kept constant. |
most likely because 9x9 is too small as compared to the original 19x19, and the 19x19 strategies do not work well to win on 9x9, and same for too big boards as compared to original 19x19 (strategies to win 50x50 are for sure very different than 19x19 for example) just a hypothesis, but the strength curve ratio as compared to the original 19x19 is probably a bell-like curve, with its peak being 19x19 in the midddle this would be because the strategies to win strongest go change when boardsize is different something like this : picture credit (totally uninteresting here) https://www.quora.com/What-percentage-of-diseases-have-unknown-pathophysiology |
Use the option --cpu-only @criptopark |
try play against rn5.5.1 |
@seopsx Thank you very much ! |
Has anyone tried 25x25 networks? elf v1 and v2 converted by ChangeBoardSizeOfWeight.cpp and board_resize.py never won against 25_205. (time parity) |
Make sure you change |
What are the strongest 9x9, 13x13 networks produced so far using this method? Can I have links please? |
@alreadydone |
@jillybob |
"of the tested 13x13 networks, probably the strongest elfv1 (converted by board_resize.py)" Running on KGS as LeelaZeroT. Enjoy :) |
can someone make leelaz37, leelaz49 and GoGui up to 52x52 (for the game and gogui-twogtp)? |
@criptopark @Marcin1960 Can you upload the Windows Leelaz 13x13 binary please? |
@jillybob link dated 02.22.19 published @alreadydone working |
@hzyhhzy thanks for the great idea and program! |
Yes,only has differences when even board sizes.Zeros depend on algorithm,not bug.But I found that 25x25 or larger boards(very obvious on 37x37 or larger)tend to avoid playing on the center of board.It would fill the corner and side rather than playing on the center of board. |
@hzyhhzy thanks for the answer! 37x37 - very interesting! Where can I download leelaz37? |
@alreadydone |
@trunterzx I don't know python. To run the script you need a python + numpy or anaconda. The startup example is: python board_resize.py.txt elf.txt 25, where elf.txt is the original network, 25 is the resulting size. If you have any questions, write. |
several matches 25x25, nets received by ChangeBoardSizeOfWeight.cpp, 10sec/move, cpuonly, gogui-twogtp: LM 192x15 GX89 - LZ 40x256 #205 25:15 |
KataGo is trained to adapt to different board sizes, and now you can get Windows binary here: KataGo GTP engine and networks (up to 37x37, arbitrary komi, handicap play). Instructions.txt included. |
several matches 25x25, nets received by board_resize.py.txt vs LM 192x15 GX89 - LZ 40x256 #205 13:27 |
minigo V17 .. ChangeBoardSizeOfWeight.cpp Is it supportable? |
https://drive.google.com/open?id=1I7LtMcuwyLUZDNjV5VL9eUwTDdyA2nIT Download your file and wanna chage 19x19 in sabaki you configruation 9x9 how to change |
https://drive.google.com/open?id=1I7LtMcuwyLUZDNjV5VL9eUwTDdyA2nIT Download your file and wanna chage 19x19 in sabaki you configruation 9x9 how to change |
They are using Transfer Learning for various board sizes. can be checked here: |
im a unfortunately mac user. is there any way for me to play 13x13 igo against leela-zero. i downloaded above 13x13 weight file and added it to my engine. but i cant step out of the "engine is loading" screen |
@mushoku-ningen leela-zero works only with a 19x19 network. for a 13x13 network, a compiled file is needed that works with a 13x13 network. |
@cryptpark thanks! really helpful! |
Here are some weights from 9x9 to 25x25.(converted from #205(85a93684) lz weight),
https://drive.google.com/open?id=1jQjCbK1xWGBglD402WpBMyeEieDG-h83
and a very rough CPP code.
https://drive.google.com/open?id=1bgkVBeCIwTgA88DG07sQE8oXHUdDuqt7
I tried many methods to modify policy head and value head.Now this is the strongest one.I‘m not very clear why it works well.
The text was updated successfully, but these errors were encountered: