(args, pipe, device, train_data_loader, test_data_loader)
| 71 | |
| 72 | |
| 73 | def train_loop(args, pipe, device, train_data_loader, test_data_loader): |
| 74 | |
| 75 | print('training starts......') |
| 76 | |
| 77 | pipe.model.train() # Flag .training to True to enable Dropout |
| 78 | |
| 79 | use_dp = (args.world_size != args.pipeline_group_size) |
| 80 | if use_dp: |
| 81 | # dp_comm = get_data_parallel_comm() |
| 82 | dp_rank = get_data_parallel_rank() |
| 83 | dp_size = get_data_parallel_world_size() |
| 84 | else: |
| 85 | dp_rank = 0 |
| 86 | dp_size = 1 |
| 87 | pp_comm = get_pipeline_parallel_comm() |
| 88 | |
| 89 | stop_flag = torch.zeros(1, dtype=torch.int64).to(device) |
| 90 | |
| 91 | input_ids = torch.zeros( |
| 92 | [args.batch_size, args.seq_length], |
| 93 | dtype=torch.int64 |
| 94 | ).to(device) |
| 95 | |
| 96 | do_sync_before_save = (args.dp_mode in ['local'] and use_dp) |
| 97 | |
| 98 | if get_pipeline_parallel_rank() == 0 and dp_rank == 0: |
| 99 | |
| 100 | for i, data in enumerate(train_data_loader): |
| 101 | # if i < pipe.global_step: |
| 102 | # continue |
| 103 | |
| 104 | if use_dp: |
| 105 | get_data_parallel_comm().broadcast(stop_flag, 0) |
| 106 | pp_comm.broadcast(stop_flag, 0) |
| 107 | |
| 108 | if stop_flag.item() == 1: |
| 109 | break |
| 110 | |
| 111 | input_ids_global = data['input_ids'].to(torch.int64).to(device) |
| 112 | |
| 113 | input_ids_list = input_ids_global.chunk(dp_size) |
| 114 | |
| 115 | if use_dp: |
| 116 | for j in range(1, dp_size): |
| 117 | get_data_parallel_comm().send( |
| 118 | input_ids_list[j], j, |
| 119 | ) |
| 120 | |
| 121 | input_ids = input_ids_list[0] |
| 122 | |
| 123 | pp_comm.broadcast(input_ids, 0) |
| 124 | |
| 125 | labels = input_ids.clone() |
| 126 | current_iter_time = pipe.sgd_iter(input_ids, labels, loss_func=gpt_loss_func) |
| 127 | |
| 128 | if args.evaluation_steps > 0 and pipe.global_step % args.evaluation_steps == 0: |
| 129 | test_loop(args, pipe, device, test_data_loader) |
| 130 |
no test coverage detected