Skip to content

Commit 2a7ad9f

Browse files
Zongwei Zhouallenwang28
authored andcommitted
Fix errors in classifier trainer when there is no distribution strategy
PiperOrigin-RevId: 306495321
1 parent 26faeb5 commit 2a7ad9f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

official/vision/image_classification/classifier_trainer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def _get_dataset_builders(params: base_configs.ExperimentConfig,
109109
logging.warning('label_smoothing not applied, so datasets will not be one '
110110
'hot encoded.')
111111

112-
num_devices = strategy.num_replicas_in_sync
112+
num_devices = strategy.num_replicas_in_sync if strategy else 1
113+
113114
image_size = get_image_size_from_model(params)
114115

115116
dataset_configs = [
@@ -308,7 +309,8 @@ def train_and_eval(
308309

309310
strategy_scope = distribution_utils.get_strategy_scope(strategy)
310311

311-
logging.info('Detected %d devices.', strategy.num_replicas_in_sync)
312+
logging.info('Detected %d devices.',
313+
strategy.num_replicas_in_sync if strategy else 1)
312314

313315
label_smoothing = params.model.loss.label_smoothing
314316
one_hot = label_smoothing and label_smoothing > 0

0 commit comments

Comments
 (0)