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

chore: refactor training loop #4435

Merged
merged 5 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
26 changes: 8 additions & 18 deletions deepmd/pt/train/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,12 @@ def run(self) -> None:
prof.start()

def step(_step_id, task_key="Default") -> None:
if self.multi_task:
model_index = dp_random.choice(
np.arange(self.num_model, dtype=np.int_),
p=self.model_prob,
)
caic99 marked this conversation as resolved.
Show resolved Hide resolved
task_key = self.model_keys[model_index]
# PyTorch Profiler
if self.enable_profiler or self.profiling:
prof.step()
Expand Down Expand Up @@ -929,24 +935,8 @@ def log_loss_valid(_task_key="Default"):

self.t0 = time.time()
self.total_train_time = 0.0
for step_id in range(self.num_steps):
if step_id < self.start_step:
continue
if self.multi_task:
chosen_index_list = dp_random.choice(
np.arange(
self.num_model, dtype=np.int32
), # int32 should be enough for # models...
p=np.array(self.model_prob),
size=self.world_size,
replace=True,
)
assert chosen_index_list.size == self.world_size
model_index = chosen_index_list[self.rank]
model_key = self.model_keys[model_index]
else:
model_key = "Default"
step(step_id, model_key)
for step_id in range(self.start_step, self.num_steps):
step(step_id)
if JIT:
break

Expand Down
1 change: 1 addition & 0 deletions deepmd/pt/utils/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def setup_seed(seed) -> None:
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
np.random.seed(seed)


class DpLoaderSet(Dataset):
Expand Down
Loading