Skip to content
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

Loading the next npz file while yielding the current file when training #1000

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 21 additions & 1 deletion python/data_processing_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import modelconfigs

import threading
import concurrent.futures

def read_npz_training_data(
npz_files,
batch_size: int,
Expand All @@ -24,7 +27,11 @@ def read_npz_training_data(
num_global_features = modelconfigs.get_num_global_input_features(model_config)
(h_base,h_builder) = build_history_matrices(model_config, device)

for npz_file in npz_files:
#create loading file thread
executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
future = None

def load_npz_file(npz_file):
with np.load(npz_file) as npz:
binaryInputNCHWPacked = npz["binaryInputNCHWPacked"]
globalInputNC = npz["globalInputNC"]
Expand All @@ -47,6 +54,19 @@ def read_npz_training_data(
assert binaryInputNCHW.shape[1] == num_bin_features
assert globalInputNC.shape[1] == num_global_features

return [binaryInputNCHW, globalInputNC, policyTargetsNCMove, globalTargetsNC, scoreDistrN, valueTargetsNCHW, metadataInputNC if include_meta else None]

#read the first file
future = executor.submit(load_npz_file, npz_files[0])
npz_files.append("")
npz_files=npz_files[1:]
for npz_file in npz_files:
binaryInputNCHW, globalInputNC, policyTargetsNCMove, globalTargetsNC, scoreDistrN, valueTargetsNCHW, metadataInputNC = future.result()

if npz_file != "":
future = executor.submit(load_npz_file, npz_file)


num_samples = binaryInputNCHW.shape[0]
# Just discard stuff that doesn't divide evenly
num_whole_steps = num_samples // (batch_size * world_size)
Expand Down