Skip to content

Commit

Permalink
Error out if weights are for wrong board size.
Browse files Browse the repository at this point in the history
We currently will either crash or do strange things if we're
fed a weights file that doesn't match the board size we're compiled
for.

See issue leela-zero#2289.
  • Loading branch information
gcp committed Apr 2, 2019
1 parent e89e1a7 commit f7bf826
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ std::pair<int, int> Network::load_v1_network(std::istream& wtfile) {
if (!ok || it_line != line.cend()) {
myprintf("\nFailed to parse weight file. Error on line %d.\n",
linecount + 2); //+1 from version line, +1 from 0-indexing
return {0,0};
return {0, 0};
}
if (linecount < plain_conv_wts) {
if (linecount % 4 == 0) {
Expand All @@ -301,7 +301,14 @@ std::pair<int, int> Network::load_v1_network(std::istream& wtfile) {
begin(m_bn_pol_w1)); break;
case 3: std::copy(cbegin(weights), cend(weights),
begin(m_bn_pol_w2)); break;
case 4: std::copy(cbegin(weights), cend(weights),
case 4: if (weights.size() != OUTPUTS_POLICY
* NUM_INTERSECTIONS
* POTENTIAL_MOVES) {
myprintf("The weights file is not for %dx%d boards.\n",
BOARD_SIZE, BOARD_SIZE);
return {0, 0};
}
std::copy(cbegin(weights), cend(weights),
begin(m_ip_pol_w)); break;
case 5: std::copy(cbegin(weights), cend(weights),
begin(m_ip_pol_b)); break;
Expand Down

0 comments on commit f7bf826

Please sign in to comment.