-
Notifications
You must be signed in to change notification settings - Fork 180
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
Use epochs instead batch_num. Log current epoch number #95
Merged
alexey-gruzdev
merged 7 commits into
securefederatedai:develop
from
maradionov:epochs_instead_batch_num
Aug 26, 2021
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8424e37
Use epochs instead batch_num. Log epoch count
maradionov 4205e9e
Fix flake8
maradionov efb2dc0
Merge branch 'develop' into epochs_instead_batch_num
maradionov f10d0e9
Merge branch 'develop' into pr/maradionov/95
itrushkin e028fee
Resolve conversations
itrushkin ef7131b
Merge branch 'develop' into pr/maradionov/95
itrushkin 38a7fc4
Fix linter
itrushkin File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,5 +61,4 @@ tasks: | |
batch_size: 32 | ||
epochs: 1 | ||
metrics: | ||
- loss | ||
num_batches: 1 | ||
- loss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,6 @@ train: | |
function : train_batches | ||
kwargs : | ||
batch_size : 32 | ||
num_batches : 1 | ||
metrics : | ||
- loss | ||
epochs : 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ train: | |
kwargs : | ||
metrics : | ||
- loss | ||
epochs : 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,7 +129,7 @@ def validate(self, col_name, round_num, input_tensor_dict, | |
return output_tensor_dict, {} | ||
|
||
def train_batches(self, col_name, round_num, input_tensor_dict, | ||
num_batches=None, use_tqdm=False, **kwargs): | ||
num_batches=None, use_tqdm=False, epochs=1, **kwargs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could |
||
"""Train batches. | ||
|
||
Train the model on the requested number of batches. | ||
|
@@ -150,10 +150,12 @@ def train_batches(self, col_name, round_num, input_tensor_dict, | |
# set to "training" mode | ||
self.train() | ||
self.to(self.device) | ||
loader = self.data_loader.get_train_loader(num_batches) | ||
if use_tqdm: | ||
loader = tqdm.tqdm(loader, desc='train epoch') | ||
metric = self.train_epoch(loader) | ||
for epoch in range(epochs): | ||
self.logger.info(f'Run {epoch} epoch of {round_num} round') | ||
loader = self.data_loader.get_train_loader(num_batches) | ||
if use_tqdm: | ||
loader = tqdm.tqdm(loader, desc='train epoch') | ||
metric = self.train_epoch(loader) | ||
# Output metric tensors (scalar) | ||
origin = col_name | ||
tags = ('trained',) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,7 @@ def rebuild_model(self, round_num, input_tensor_dict, validation=False): | |
self.set_tensor_dict(input_tensor_dict, with_opt_vars=False) | ||
|
||
def train_batches(self, col_name, round_num, input_tensor_dict, | ||
num_batches, use_tqdm=False, **kwargs): | ||
epochs=1, use_tqdm=False, **kwargs): | ||
""" | ||
Perform the training for a specified number of batches. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docstring should be updated since |
||
|
||
|
@@ -107,22 +107,17 @@ def train_batches(self, col_name, round_num, input_tensor_dict, | |
self.rebuild_model(round_num, input_tensor_dict) | ||
|
||
tf.keras.backend.set_learning_phase(True) | ||
|
||
losses = [] | ||
batch_num = 0 | ||
|
||
while batch_num < num_batches: | ||
for epoch in range(epochs): | ||
self.logger.info(f'Run {epoch} epoch of {round_num} round') | ||
# get iterator for batch draws (shuffling happens here) | ||
gen = self.data_loader.get_train_loader(batch_size) | ||
if use_tqdm: | ||
gen = tqdm.tqdm(gen, desc='training epoch') | ||
|
||
for (X, y) in gen: | ||
if batch_num >= num_batches: | ||
break | ||
else: | ||
losses.append(self.train_batch(X, y)) | ||
batch_num += 1 | ||
losses.append(self.train_batch(X, y)) | ||
|
||
# Output metric tensors (scalar) | ||
origin = col_name | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstring should be updated since
num_batches
is not specified anymore.