(args)
| 93 | |
| 94 | |
| 95 | def evaluate(args): |
| 96 | batch_size = args.batch_size |
| 97 | context_length = args.context_length |
| 98 | prediction_length = args.prediction_length |
| 99 | |
| 100 | master_addr = os.getenv('MASTER_ADDR', '127.0.0.1') |
| 101 | master_port = os.getenv('MASTER_PORT', 9899) |
| 102 | world_size = int(os.getenv('WORLD_SIZE') or 1) |
| 103 | rank = int(os.getenv('RANK') or 0) |
| 104 | local_rank = int(os.getenv('LOCAL_RANK') or 0) |
| 105 | if torch.cuda.is_available(): |
| 106 | try: |
| 107 | setup_nccl(rank=rank, world_size=world_size, master_addr=master_addr, master_port=master_port) |
| 108 | device = f"cuda:{local_rank}" |
| 109 | is_dist = True |
| 110 | except Exception as e: |
| 111 | print('Error: ', f'Setup nccl fail, so set device to cpu: {e}') |
| 112 | device = 'cpu' |
| 113 | is_dist = False |
| 114 | else: |
| 115 | device = 'cpu' |
| 116 | is_dist = False |
| 117 | |
| 118 | # evaluation |
| 119 | metric_list = [ |
| 120 | MSEMetric(name='mse'), |
| 121 | MAEMetric(name='mae'), |
| 122 | ] |
| 123 | |
| 124 | model = TimeMoE( |
| 125 | args.model, |
| 126 | device, |
| 127 | context_length=context_length, |
| 128 | prediction_length=prediction_length |
| 129 | ) |
| 130 | if args.data.endswith('.csv'): |
| 131 | dataset = BenchmarkEvalDataset( |
| 132 | args.data, |
| 133 | context_length=context_length, |
| 134 | prediction_length=prediction_length, |
| 135 | ) |
| 136 | else: |
| 137 | dataset = GeneralEvalDataset( |
| 138 | args.data, |
| 139 | context_length=context_length, |
| 140 | prediction_length=prediction_length, |
| 141 | ) |
| 142 | |
| 143 | if torch.cuda.is_available() and dist.is_initialized(): |
| 144 | sampler = DistributedSampler(dataset=dataset, shuffle=False) |
| 145 | else: |
| 146 | sampler = None |
| 147 | test_dl = DataLoader( |
| 148 | dataset=dataset, |
| 149 | batch_size=batch_size, |
| 150 | sampler=sampler, |
| 151 | shuffle=False, |
| 152 | num_workers=2, |
no test coverage detected