MCPcopy Create free account
hub / github.com/algorithmicsuperintelligence/optillm / validate

Function validate

scripts/train_optillm_classifier.py:197–216  ·  view source on GitHub ↗
(model, val_dataloader)

Source from the content-addressed store, hash-verified

195 break
196
197def validate(model, val_dataloader):
198 model.eval()
199 total_val_accuracy = 0
200
201 with torch.no_grad():
202 for batch in val_dataloader:
203 input_ids = batch['input_ids'].to(device)
204 attention_mask = batch['attention_mask'].to(device)
205 approaches = batch['approaches'].to(device)
206 ranks = batch['ranks'].to(device)
207 tokens = batch['tokens'].to(device)
208
209 effort = (tokens - tokens.min()) / (tokens.max() - tokens.min())
210 best_approach_indices = ranks.argmin(dim=1)
211
212 logits = model(input_ids, attention_mask, effort[:, 0])
213 predictions = torch.argmax(logits, dim=-1)
214 total_val_accuracy += calculate_accuracy(predictions, best_approach_indices)
215
216 return total_val_accuracy / len(val_dataloader)
217
218def inference(model, tokenizer, prompt, effort_levels):
219 model.eval()

Callers 2

trainFunction · 0.85
mainFunction · 0.85

Calls 1

calculate_accuracyFunction · 0.85

Tested by

no test coverage detected