14
14
# limitations under the License.
15
15
# ==============================================================================
16
16
"""Executes Keras benchmarks and accuracy tests."""
17
+ # pylint: disable=line-too-long
17
18
from __future__ import print_function
18
19
19
20
import json
@@ -266,7 +267,6 @@ def _run_and_report_benchmark(
266
267
dataset_num_private_threads : Optional [int ] = None ,
267
268
loss_scale : Optional [str ] = None ):
268
269
"""Runs and reports the benchmark given the provided configuration."""
269
- self ._setup ()
270
270
FLAGS .model_type = 'resnet'
271
271
FLAGS .dataset = 'imagenet'
272
272
FLAGS .mode = 'train_and_eval'
@@ -449,7 +449,6 @@ def _run_and_report_benchmark(
449
449
dataset_num_private_threads : Optional [int ] = None ,
450
450
loss_scale : Optional [str ] = None ):
451
451
"""Runs and reports the benchmark given the provided configuration."""
452
- self ._setup ()
453
452
FLAGS .model_type = 'resnet'
454
453
FLAGS .dataset = 'imagenet'
455
454
FLAGS .mode = 'train_and_eval'
@@ -490,6 +489,7 @@ def _run_and_report_benchmark(
490
489
491
490
def benchmark_1_gpu_no_dist_strat (self ):
492
491
"""Tests Keras model with 1 GPU, no distribution strategy."""
492
+ self ._setup ()
493
493
self ._run_and_report_benchmark (
494
494
experiment_name = 'benchmark_1_gpu_no_dist_strat' ,
495
495
num_gpus = 1 ,
@@ -498,6 +498,7 @@ def benchmark_1_gpu_no_dist_strat(self):
498
498
499
499
def benchmark_1_gpu_no_dist_strat_run_eagerly (self ):
500
500
"""Tests Keras model with 1 GPU, no distribution strategy, run eagerly."""
501
+ self ._setup ()
501
502
self ._run_and_report_benchmark (
502
503
experiment_name = 'benchmark_1_gpu_no_dist_strat_run_eagerly' ,
503
504
num_gpus = 1 ,
@@ -507,6 +508,7 @@ def benchmark_1_gpu_no_dist_strat_run_eagerly(self):
507
508
508
509
def benchmark_1_gpu_no_dist_strat_run_eagerly_fp16 (self ):
509
510
"""Tests with 1 GPU, no distribution strategy, fp16, run eagerly."""
511
+ self ._setup ()
510
512
self ._run_and_report_benchmark (
511
513
experiment_name = 'benchmark_1_gpu_no_dist_strat_run_eagerly_fp16' ,
512
514
num_gpus = 1 ,
@@ -517,6 +519,7 @@ def benchmark_1_gpu_no_dist_strat_run_eagerly_fp16(self):
517
519
518
520
def benchmark_1_gpu (self ):
519
521
"""Tests Keras model with 1 GPU."""
522
+ self ._setup ()
520
523
self ._run_and_report_benchmark (
521
524
experiment_name = 'benchmark_1_gpu' ,
522
525
num_gpus = 1 ,
@@ -525,16 +528,17 @@ def benchmark_1_gpu(self):
525
528
526
529
def benchmark_xla_1_gpu (self ):
527
530
"""Tests Keras model with XLA and 1 GPU."""
531
+ self ._setup ()
528
532
self ._run_and_report_benchmark (
529
533
experiment_name = 'benchmark_xla_1_gpu' ,
530
534
num_gpus = 1 ,
531
535
enable_xla = True ,
532
536
distribution_strategy = 'one_device' ,
533
537
per_replica_batch_size = 128 )
534
- self ._setup ()
535
538
536
539
def benchmark_1_gpu_fp16 (self ):
537
540
"""Tests Keras model with 1 GPU and fp16."""
541
+ self ._setup ()
538
542
self ._run_and_report_benchmark (
539
543
experiment_name = 'benchmark_1_gpu_fp16' ,
540
544
num_gpus = 1 ,
@@ -544,6 +548,7 @@ def benchmark_1_gpu_fp16(self):
544
548
545
549
def benchmark_1_gpu_fp16_dynamic (self ):
546
550
"""Tests Keras model with 1 GPU, fp16, and dynamic loss scaling."""
551
+ self ._setup ()
547
552
self ._run_and_report_benchmark (
548
553
experiment_name = 'benchmark_1_gpu_fp16_dynamic' ,
549
554
num_gpus = 1 ,
@@ -554,6 +559,7 @@ def benchmark_1_gpu_fp16_dynamic(self):
554
559
555
560
def benchmark_xla_1_gpu_fp16 (self ):
556
561
"""Tests Keras model with XLA, 1 GPU and fp16."""
562
+ self ._setup ()
557
563
self ._run_and_report_benchmark (
558
564
experiment_name = 'benchmark_xla_1_gpu_fp16' ,
559
565
num_gpus = 1 ,
@@ -564,6 +570,7 @@ def benchmark_xla_1_gpu_fp16(self):
564
570
565
571
def benchmark_xla_1_gpu_fp16_tweaked (self ):
566
572
"""Tests Keras model with XLA, 1 GPU, fp16, and manual config tuning."""
573
+ self ._setup ()
567
574
self ._run_and_report_benchmark (
568
575
experiment_name = 'benchmark_xla_1_gpu_fp16_tweaked' ,
569
576
num_gpus = 1 ,
@@ -575,6 +582,7 @@ def benchmark_xla_1_gpu_fp16_tweaked(self):
575
582
576
583
def benchmark_xla_1_gpu_fp16_dynamic (self ):
577
584
"""Tests Keras model with XLA, 1 GPU, fp16, and dynamic loss scaling."""
585
+ self ._setup ()
578
586
self ._run_and_report_benchmark (
579
587
experiment_name = 'benchmark_xla_1_gpu_fp16_dynamic' ,
580
588
num_gpus = 1 ,
@@ -586,6 +594,7 @@ def benchmark_xla_1_gpu_fp16_dynamic(self):
586
594
587
595
def benchmark_graph_1_gpu (self ):
588
596
"""Tests Keras model in legacy graph mode with 1 GPU."""
597
+ self ._setup ()
589
598
self ._run_and_report_benchmark (
590
599
experiment_name = 'benchmark_graph_1_gpu' ,
591
600
num_gpus = 1 ,
@@ -594,6 +603,7 @@ def benchmark_graph_1_gpu(self):
594
603
595
604
def benchmark_graph_xla_1_gpu (self ):
596
605
"""Tests Keras model in legacy graph mode with XLA and 1 GPU."""
606
+ self ._setup ()
597
607
self ._run_and_report_benchmark (
598
608
experiment_name = 'benchmark_graph_xla_1_gpu' ,
599
609
num_gpus = 1 ,
@@ -603,6 +613,7 @@ def benchmark_graph_xla_1_gpu(self):
603
613
604
614
def benchmark_8_gpu (self ):
605
615
"""Tests Keras model with 8 GPUs."""
616
+ self ._setup ()
606
617
self ._run_and_report_benchmark (
607
618
experiment_name = 'benchmark_8_gpu' ,
608
619
num_gpus = 8 ,
@@ -611,6 +622,7 @@ def benchmark_8_gpu(self):
611
622
612
623
def benchmark_8_gpu_tweaked (self ):
613
624
"""Tests Keras model with manual config tuning and 8 GPUs."""
625
+ self ._setup ()
614
626
self ._run_and_report_benchmark (
615
627
experiment_name = 'benchmark_8_gpu_tweaked' ,
616
628
num_gpus = 8 ,
@@ -620,6 +632,7 @@ def benchmark_8_gpu_tweaked(self):
620
632
621
633
def benchmark_xla_8_gpu (self ):
622
634
"""Tests Keras model with XLA and 8 GPUs."""
635
+ self ._setup ()
623
636
self ._run_and_report_benchmark (
624
637
experiment_name = 'benchmark_xla_8_gpu' ,
625
638
num_gpus = 8 ,
@@ -629,6 +642,7 @@ def benchmark_xla_8_gpu(self):
629
642
630
643
def benchmark_xla_8_gpu_tweaked (self ):
631
644
"""Tests Keras model with manual config tuning, 8 GPUs, and XLA."""
645
+ self ._setup ()
632
646
self ._run_and_report_benchmark (
633
647
experiment_name = 'benchmark_xla_8_gpu_tweaked' ,
634
648
num_gpus = 8 ,
@@ -640,6 +654,7 @@ def benchmark_xla_8_gpu_tweaked(self):
640
654
641
655
def benchmark_8_gpu_fp16 (self ):
642
656
"""Tests Keras model with 8 GPUs and fp16."""
657
+ self ._setup ()
643
658
self ._run_and_report_benchmark (
644
659
experiment_name = 'benchmark_8_gpu_fp16' ,
645
660
num_gpus = 8 ,
@@ -649,6 +664,7 @@ def benchmark_8_gpu_fp16(self):
649
664
650
665
def benchmark_8_gpu_fp16_tweaked (self ):
651
666
"""Tests Keras model with 8 GPUs, fp16, and manual config tuning."""
667
+ self ._setup ()
652
668
self ._run_and_report_benchmark (
653
669
experiment_name = 'benchmark_8_gpu_fp16_tweaked' ,
654
670
num_gpus = 8 ,
@@ -659,6 +675,7 @@ def benchmark_8_gpu_fp16_tweaked(self):
659
675
660
676
def benchmark_8_gpu_fp16_dynamic_tweaked (self ):
661
677
"""Tests Keras model with 8 GPUs, fp16, dynamic loss scaling, and tuned."""
678
+ self ._setup ()
662
679
self ._run_and_report_benchmark (
663
680
experiment_name = 'benchmark_8_gpu_fp16_dynamic_tweaked' ,
664
681
num_gpus = 8 ,
@@ -670,6 +687,7 @@ def benchmark_8_gpu_fp16_dynamic_tweaked(self):
670
687
671
688
def benchmark_xla_8_gpu_fp16 (self ):
672
689
"""Tests Keras model with XLA, 8 GPUs and fp16."""
690
+ self ._setup ()
673
691
self ._run_and_report_benchmark (
674
692
experiment_name = 'benchmark_xla_8_gpu_fp16' ,
675
693
dtype = 'float16' ,
@@ -680,6 +698,7 @@ def benchmark_xla_8_gpu_fp16(self):
680
698
681
699
def benchmark_xla_8_gpu_fp16_tweaked (self ):
682
700
"""Test Keras model with manual config tuning, XLA, 8 GPUs and fp16."""
701
+ self ._setup ()
683
702
self ._run_and_report_benchmark (
684
703
experiment_name = 'benchmark_xla_8_gpu_fp16_tweaked' ,
685
704
dtype = 'float16' ,
@@ -695,6 +714,7 @@ def benchmark_xla_8_gpu_fp16_tweaked_delay_measure(self):
695
714
696
715
Delay performance measurement for stable performance on 96 vCPU platforms.
697
716
"""
717
+ self ._setup ()
698
718
self ._run_and_report_benchmark (
699
719
experiment_name = 'benchmark_xla_8_gpu_fp16_tweaked_delay_measure' ,
700
720
dtype = 'float16' ,
@@ -707,6 +727,7 @@ def benchmark_xla_8_gpu_fp16_tweaked_delay_measure(self):
707
727
708
728
def benchmark_xla_8_gpu_fp16_dynamic_tweaked (self ):
709
729
"""Tests Keras model with config tuning, XLA, 8 GPUs and dynamic fp16."""
730
+ self ._setup ()
710
731
self ._run_and_report_benchmark (
711
732
experiment_name = 'benchmark_xla_8_gpu_fp16_dynamic_tweaked' ,
712
733
dtype = 'float16' ,
@@ -720,6 +741,7 @@ def benchmark_xla_8_gpu_fp16_dynamic_tweaked(self):
720
741
721
742
def benchmark_graph_8_gpu (self ):
722
743
"""Tests Keras model in legacy graph mode with 8 GPUs."""
744
+ self ._setup ()
723
745
self ._run_and_report_benchmark (
724
746
experiment_name = 'benchmark_graph_8_gpu' ,
725
747
num_gpus = 8 ,
@@ -728,6 +750,7 @@ def benchmark_graph_8_gpu(self):
728
750
729
751
def benchmark_graph_xla_8_gpu (self ):
730
752
"""Tests Keras model in legacy graph mode with XLA and 8 GPUs."""
753
+ self ._setup ()
731
754
self ._run_and_report_benchmark (
732
755
experiment_name = 'benchmark_graph_xla_8_gpu' ,
733
756
num_gpus = 8 ,
@@ -737,6 +760,7 @@ def benchmark_graph_xla_8_gpu(self):
737
760
738
761
def benchmark_2x2_tpu_fp16 (self ):
739
762
"""Test Keras model with 2x2 TPU, fp16."""
763
+ self ._setup ()
740
764
self ._run_and_report_benchmark (
741
765
experiment_name = 'benchmark_2x2_tpu_fp16' ,
742
766
dtype = 'bfloat16' ,
@@ -745,6 +769,7 @@ def benchmark_2x2_tpu_fp16(self):
745
769
746
770
def benchmark_4x4_tpu_fp16 (self ):
747
771
"""Test Keras model with 4x4 TPU, fp16."""
772
+ self ._setup ()
748
773
self ._run_and_report_benchmark (
749
774
experiment_name = 'benchmark_4x4_tpu_fp16' ,
750
775
dtype = 'bfloat16' ,
@@ -1395,8 +1420,7 @@ class Resnet50KerasBenchmarkReal(Resnet50KerasClassifierBenchmarkBase):
1395
1420
"""Resnet50 real data benchmark tests."""
1396
1421
1397
1422
def __init__ (self , output_dir = None , root_data_dir = None , tpu = None , ** kwargs ):
1398
- data_dir = ('/readahead/200M/placer/prod/home/distbelief/'
1399
- 'imagenet-tensorflow/imagenet-2012-tfrecord' )
1423
+ data_dir = os .path .join (root_data_dir , 'imagenet' )
1400
1424
def_flags = {}
1401
1425
def_flags ['log_steps' ] = 10
1402
1426
0 commit comments