MCPcopy Create free account
hub / github.com/apple/ml-pointersect / _loop_dataloader

Method _loop_dataloader

cdslib/core/script/base_train.py:861–973  ·  view source on GitHub ↗
(
            self,
            epoch: int,
            dataloader: T.Sequence[T.Any],
            mode: str,  # train, valid, test
            step_func: T.Callable,
            visualize_func: T.Callable,
            total_batch_count: int,
            max_epoch_batches: int,
            log_every_num_batch: int,
            visualize_every_num_batch: int,
    )

Source from the content-addressed store, hash-verified

859 raise NotImplementedError(f"{self.process_info['ddp_type']}")
860
861 def _loop_dataloader(
862 self,
863 epoch: int,
864 dataloader: T.Sequence[T.Any],
865 mode: str, # train, valid, test
866 step_func: T.Callable,
867 visualize_func: T.Callable,
868 total_batch_count: int,
869 max_epoch_batches: int,
870 log_every_num_batch: int,
871 visualize_every_num_batch: int,
872 ):
873
874 if dataloader is None:
875 return dict(
876 total_batch_count=total_batch_count,
877 total_epoch_batch=0,
878 epoch_time=0,
879 stats_dict=None,
880 )
881
882 # start running training loop
883 epoch_stime = timer()
884 batch_stime = timer()
885 total_epoch_batch = 0
886
887 # to compute the statistics
888 statistics = StatisticsCollector(convert_to_float=True)
889
890 for batch_idx, batch in enumerate(dataloader):
891 if max_epoch_batches >= 0 and total_epoch_batch >= max_epoch_batches:
892 break
893
894 # train one step
895 step_stime = timer()
896 out_dict = step_func(
897 epoch=epoch,
898 bidx=batch_idx,
899 batch=batch,
900 )
901 step_etime = timer()
902 # record the outputs to compute statistics
903 if out_dict is not None:
904 statistics.record(out_dict)
905
906 # print timing
907 batch_time = step_etime - batch_stime
908 step_time = step_etime - step_stime
909 epoch_time = step_etime - epoch_stime
910
911 # print loss
912 if out_dict is not None and batch_idx % log_every_num_batch == 0:
913 # print the output
914 self.logger.add_scalars(
915 main_tag=f"{mode}_",
916 tag_scalar_dict=out_dict,
917 epoch=epoch,
918 batch_idx=batch_idx,

Callers 1

runMethod · 0.95

Calls 7

recordMethod · 0.95
compute_statisticsMethod · 0.95
StatisticsCollectorClass · 0.90
add_scalarsMethod · 0.80
flushMethod · 0.80
infoMethod · 0.80
add_scalarMethod · 0.80

Tested by

no test coverage detected