Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions nn/learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def train_on_gpu(program_dir: str, board_size: int, batch_size: int, \
weight_decay=WEIGHT_DECAY,
nesterov=True)

scaler = torch.cuda.amp.GradScaler()
scaler = torch.amp.GradScaler(device.type)

current_lr = SL_LEARNING_RATE

Expand All @@ -166,7 +166,7 @@ def train_on_gpu(program_dir: str, board_size: int, batch_size: int, \
dual_net.train()
epoch_time = time.time()
for i in range(0, len(value_data) - batch_size + 1, batch_size):
with torch.cuda.amp.autocast(enabled=True):
with torch.amp.autocast(device.type, enabled=True):
plane = torch.tensor(plane_data[i:i+batch_size]).to(device)
policy = torch.tensor(policy_data[i:i+batch_size]).to(device)
value = torch.tensor(value_data[i:i+batch_size]).to(device)
Expand Down Expand Up @@ -339,7 +339,7 @@ def train_with_gumbel_alphazero_on_gpu(program_dir: str, board_size: int, \
weight_decay=WEIGHT_DECAY,
nesterov=True)

scaler = torch.cuda.amp.GradScaler()
scaler = torch.amp.GradScaler(device.type)

num_trained_batches = 0

Expand Down Expand Up @@ -368,7 +368,7 @@ def train_with_gumbel_alphazero_on_gpu(program_dir: str, board_size: int, \
dual_net.train()
epoch_time = time.time()
for i in range(0, len(value_data) - batch_size + 1, batch_size):
with torch.cuda.amp.autocast(enabled=True):
with torch.amp.autocast(device.type, enabled=True):
plane = torch.tensor(plane_data[i:i+batch_size]).to(device)
policy = torch.tensor(policy_data[i:i+batch_size]).to(device)
value = torch.tensor(value_data[i:i+batch_size]).to(device)
Expand Down
7 changes: 5 additions & 2 deletions nn/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ def get_torch_device(use_gpu: bool) -> torch.device:
torch.device: デバイス情報。
"""
if use_gpu:
torch.cuda.set_device(0)
return torch.device("cuda")
if torch.cuda.is_available():
torch.cuda.set_device(0)
return torch.device("cuda")
if torch.backends.mps.is_available():
return torch.device("mps")
return torch.device("cpu")


Expand Down