Andrej Karpathy commited on
Commit
7d2c4a3
·
1 Parent(s): ad39db5

delete pandas dep in base_eval use csv instead

Browse files
Files changed (1) hide show
  1. scripts/base_eval.py +13 -8
scripts/base_eval.py CHANGED
@@ -1,5 +1,5 @@
1
  """
2
- Evlauate the CORE metric for a given model.
3
 
4
  Run on a single GPU:
5
  python base_eval.py
@@ -10,14 +10,13 @@ torchrun --nproc_per_node=8 base_eval.py
10
  The script will print the CORE metric to the console.
11
  """
12
  import os
13
- import sys
14
  import time
15
  import json
16
  import random
17
  import yaml
18
  from contextlib import nullcontext
19
 
20
- import pandas as pd
21
  import torch
22
 
23
  from nanochat.common import compute_init, compute_cleanup, print0, get_base_dir, autodetect_device_type
@@ -26,13 +25,12 @@ from nanochat.checkpoint_manager import load_model
26
  from nanochat.core_eval import evaluate_task
27
 
28
  # -----------------------------------------------------------------------------
29
- # nanoChat specific function dealing with I/O etc.
30
 
31
  def evaluate_model(model, tokenizer, device, max_per_task=-1):
32
  """
33
  Evaluate a base model on the CORE benchmark.
34
  - max_per_task: crop the data to this many examples per task for testing (-1 = disable)
35
- TODO: clean up this function, delete the need for all the files, for pandas dependency, etc.
36
  """
37
  # Load config and task metadata
38
  base_dir = get_base_dir()
@@ -43,7 +41,15 @@ def evaluate_model(model, tokenizer, device, max_per_task=-1):
43
  with open(config_path, 'r') as f:
44
  config = yaml.safe_load(f)
45
  tasks = config['icl_tasks']
46
- eval_metadata = pd.read_csv(eval_meta_data)
 
 
 
 
 
 
 
 
47
 
48
  # Evaluate each task
49
  results = {}
@@ -75,8 +81,7 @@ def evaluate_model(model, tokenizer, device, max_per_task=-1):
75
  accuracy = evaluate_task(model, tokenizer, data, device, task_meta)
76
 
77
  results[label] = accuracy
78
- row = eval_metadata[eval_metadata["Eval Task"] == label]
79
- random_baseline = row["Random baseline"].values[0]
80
  centered_result = (accuracy - 0.01 * random_baseline) / (1.0 - 0.01 * random_baseline)
81
  centered_results[label] = centered_result
82
  end_time = time.time()
 
1
  """
2
+ Evaluate the CORE metric for a given model.
3
 
4
  Run on a single GPU:
5
  python base_eval.py
 
10
  The script will print the CORE metric to the console.
11
  """
12
  import os
13
+ import csv
14
  import time
15
  import json
16
  import random
17
  import yaml
18
  from contextlib import nullcontext
19
 
 
20
  import torch
21
 
22
  from nanochat.common import compute_init, compute_cleanup, print0, get_base_dir, autodetect_device_type
 
25
  from nanochat.core_eval import evaluate_task
26
 
27
  # -----------------------------------------------------------------------------
28
+ # nanochat specific function dealing with I/O etc.
29
 
30
  def evaluate_model(model, tokenizer, device, max_per_task=-1):
31
  """
32
  Evaluate a base model on the CORE benchmark.
33
  - max_per_task: crop the data to this many examples per task for testing (-1 = disable)
 
34
  """
35
  # Load config and task metadata
36
  base_dir = get_base_dir()
 
41
  with open(config_path, 'r') as f:
42
  config = yaml.safe_load(f)
43
  tasks = config['icl_tasks']
44
+
45
+ # Load random baseline values from eval metadata
46
+ random_baselines = {}
47
+ with open(eval_meta_data, 'r', encoding='utf-8') as f:
48
+ reader = csv.DictReader(f)
49
+ for row in reader:
50
+ task_name = row['Eval Task']
51
+ random_baseline = row['Random baseline']
52
+ random_baselines[task_name] = float(random_baseline)
53
 
54
  # Evaluate each task
55
  results = {}
 
81
  accuracy = evaluate_task(model, tokenizer, data, device, task_meta)
82
 
83
  results[label] = accuracy
84
+ random_baseline = random_baselines[label]
 
85
  centered_result = (accuracy - 0.01 * random_baseline) / (1.0 - 0.01 * random_baseline)
86
  centered_results[label] = centered_result
87
  end_time = time.time()