Skip to content

Commit

Permalink
Merge pull request #35 from hijkzzz/dev
Browse files Browse the repository at this point in the history
add option for no gui in training mode
  • Loading branch information
hijkzzz authored Jan 7, 2023
2 parents 1ff3f28 + d2f51da commit d48b3e7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 27 deletions.
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# gomoku
'n': 15, # board size
'n_in_row': 5, # n in row
'use_gui': True, # show gomoku gui in training mode

# mcts
'libtorch_use_gpu' : True, # libtorch use cuda
Expand Down
13 changes: 9 additions & 4 deletions src/learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, config):
# gomoku
self.n = config['n']
self.n_in_row = config['n_in_row']
self.use_gui = config['use_gui']
self.gomoku_gui = GomokuGUI(config['n'], config['human_color'])
self.action_size = config['action_size']

Expand Down Expand Up @@ -60,13 +61,13 @@ def __init__(self, config):
self.nnet = NeuralNetWorkWrapper(config['lr'], config['l2'], config['num_layers'],
config['num_channels'], config['n'], self.action_size, config['train_use_gpu'], self.libtorch_use_gpu)

def learn(self):
# start gui
t = threading.Thread(target=self.gomoku_gui.loop)
t.start()
if self.use_gui:
t = threading.Thread(target=self.gomoku_gui.loop)
t.start()

def learn(self):
# train the model by self play

if path.exists(path.join('models', 'checkpoint.example')):
print("loading checkpoint...")
self.nnet.load_model()
Expand Down Expand Up @@ -282,6 +283,10 @@ def get_symmetries(self, board, pi, last_action):
return l

def play_with_human(self, human_first=True, checkpoint_name="best_checkpoint"):
# gomoku gui
t = threading.Thread(target=self.gomoku_gui.loop)
t.start()

# load best model
libtorch_best = NeuralNetwork('./models/best_checkpoint.pt', self.libtorch_use_gpu, 12)
mcts_best = MCTS(libtorch_best, self.num_mcts_threads * 3, \
Expand Down
4 changes: 2 additions & 2 deletions src/neural_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import torch
import torch.nn as nn
from torch.optim import Adam
from torch.optim import AdamW
from torch.autograd import Variable
import torch.nn.functional as F

Expand Down Expand Up @@ -146,7 +146,7 @@ def __init__(self, lr, l2, num_layers, num_channels, n, action_size, train_use_g
if self.train_use_gpu:
self.neural_network.cuda()

self.optim = Adam(self.neural_network.parameters(), lr=self.lr, weight_decay=self.l2)
self.optim = AdamW(self.neural_network.parameters(), lr=self.lr, weight_decay=self.l2)
self.alpha_loss = AlphaLoss()

def train(self, example_buffer, batch_size, epochs):
Expand Down
21 changes: 0 additions & 21 deletions test/leaner_test.py

This file was deleted.

0 comments on commit d48b3e7

Please sign in to comment.