rdiehlmartinez commited on
Commit
ebfb4b3
·
1 Parent(s): 33a4030

including model size into subconfig name

Browse files
Files changed (1) hide show
  1. pythia-training-metrics.py +71 -71
pythia-training-metrics.py CHANGED
@@ -10,54 +10,56 @@ class PythiaTrainingMetrics(datasets.GeneratorBasedBuilder):
10
  MODEL_SIZES = [
11
  "70m",
12
  "160m",
13
- #"410m",
14
  "1.4b",
15
  #"2.8b",
16
  ]
17
 
18
  _GRADIENTS_DESCRIPTION = """\
19
- Dataset for storing gradients of pythia models
20
  """
21
 
22
  _WEIGHTS_DESCRIPTION = """\
23
- Dataset for storing weights of pythia models
24
  """
25
 
26
  _WEIGHTS_MINI_DESCRIPTION = """\
27
  Dataset for storing weights of pythia models (minimizes the amount of gradients per
28
- checkpoint to only 2)
29
  """
30
 
31
  _ACTIVATIONS_DESCRIPTION = """\
32
- Dataset for storing activations of pythia models
33
  """
34
 
35
- BUILDER_CONFIGS = [
36
- datasets.BuilderConfig(
37
- name="gradients",
38
- description=_WEIGHTS_DESCRIPTION,
39
- version="1.0.0",
40
- ),
41
- datasets.BuilderConfig(
42
- name="gradients_mini",
43
- description=_WEIGHTS_MINI_DESCRIPTION,
44
- version="1.0.0",
45
- ),
46
- datasets.BuilderConfig(
47
- name="activations",
48
- description=_ACTIVATIONS_DESCRIPTION,
49
- version="1.0.0",
50
- ),
51
- datasets.BuilderConfig(
52
- name="weights",
53
- description=_WEIGHTS_DESCRIPTION,
54
- version="1.0.0",
55
- ),
56
- ]
 
 
57
 
58
  def _info(self):
59
  """
60
- NOTE: we might want to specify features, but since the featuers are different for each
61
  model size it's annoying and kind of pointless since hf does it automatically
62
  """
63
 
@@ -71,7 +73,7 @@ class PythiaTrainingMetrics(datasets.GeneratorBasedBuilder):
71
  Returns data for different splits - we define a split as a model size.
72
  """
73
 
74
- model_size_to_fp = { model_size: [] for model_size in self.MODEL_SIZES }
75
 
76
  kwargs_checkpoint_steps = []
77
  kwargs_gradient_steps = []
@@ -85,45 +87,40 @@ class PythiaTrainingMetrics(datasets.GeneratorBasedBuilder):
85
  """
86
  return list(range(max(0, step-5), min(step+6, 143_000)))
87
 
88
- for _idx, model_size in enumerate(self.MODEL_SIZES):
89
- for checkpoint_step in checkpoint_steps:
90
-
91
- directory_path = f"./models/{model_size}/checkpoint_{checkpoint_step}"
92
-
93
- if self.config.name == "activations":
94
- model_size_to_fp[model_size].append(f"{directory_path}/checkpoint_activations.pickle")
95
- if _idx == 0:
96
- kwargs_checkpoint_steps.append(checkpoint_step)
97
- elif self.config.name == "weights":
98
- model_size_to_fp[model_size].append(f"{directory_path}/checkpoint_weights.pickle")
99
- if _idx == 0:
100
- kwargs_checkpoint_steps.append(checkpoint_step)
101
- elif self.config.name == "gradients":
102
- for gradient_step in get_gradient_step(checkpoint_step):
103
- model_size_to_fp[model_size].append(f"{directory_path}/checkpoint_gradients_{gradient_step}.pickle")
104
- if _idx == 0:
105
- kwargs_checkpoint_steps.append(checkpoint_step)
106
- kwargs_gradient_steps.append(gradient_step)
107
- elif self.config.name == "gradients_mini":
108
- for gradient_step in get_gradient_step(checkpoint_step)[:2]:
109
- model_size_to_fp[model_size].append(f"{directory_path}/checkpoint_gradients_mini_{gradient_step}.pickle")
110
- if _idx == 0:
111
- kwargs_checkpoint_steps.append(checkpoint_step)
112
- kwargs_gradient_steps.append(gradient_step)
113
- else:
114
- raise Exception("Invalid config name")
115
-
116
- downloaded_files = dl_manager.download_and_extract(model_size_to_fp)
117
 
118
  return [
119
  datasets.SplitGenerator(
120
- name=model_size_name,
121
  gen_kwargs={
122
- "filepaths": downloaded_fps,
123
  "checkpoint_steps": kwargs_checkpoint_steps,
124
- **({"gradient_steps": kwargs_gradient_steps} if self.config.name in ["gradients", "gradients_mini"] else {}),
125
  }
126
- ) for model_size_name, downloaded_fps in downloaded_files.items()
127
  ]
128
 
129
  def _generate_examples(self, filepaths, checkpoint_steps, **kwargs):
@@ -132,7 +129,7 @@ class PythiaTrainingMetrics(datasets.GeneratorBasedBuilder):
132
  if isinstance(filepaths, str):
133
  filepaths = [filepaths]
134
 
135
- if self.config.name in ["gradients", "gradients_mini"]:
136
  gradient_steps = kwargs["gradient_steps"]
137
 
138
  global_idx = 0 # the unique identifier for the example
@@ -140,12 +137,15 @@ class PythiaTrainingMetrics(datasets.GeneratorBasedBuilder):
140
  for idx, filepath in enumerate(filepaths):
141
  with open(filepath, 'rb') as f:
142
  data = pickle.load(f)
 
 
 
 
 
 
 
 
 
143
 
144
- if self.config.name in ["activations", "weights"]:
145
- for layer_name, layer_data in data.items():
146
- yield global_idx, {"checkpoint_step": checkpoint_steps[idx], "layer_name": layer_name, "data": layer_data}
147
- global_idx += 1
148
- elif self.config.name in ["gradients", "gradients_mini"]:
149
- for layer_name, layer_data in data.items():
150
- yield global_idx, {"checkpoint_step": checkpoint_steps[idx], "layer_name": layer_name, "gradient_step": gradient_steps[idx], "data": layer_data}
151
- global_idx += 1
 
10
  MODEL_SIZES = [
11
  "70m",
12
  "160m",
13
+ "410m",
14
  "1.4b",
15
  #"2.8b",
16
  ]
17
 
18
  _GRADIENTS_DESCRIPTION = """\
19
+ Dataset for storing gradients of pythia models of the requested model size
20
  """
21
 
22
  _WEIGHTS_DESCRIPTION = """\
23
+ Dataset for storing weights of pythia models of the requested model size
24
  """
25
 
26
  _WEIGHTS_MINI_DESCRIPTION = """\
27
  Dataset for storing weights of pythia models (minimizes the amount of gradients per
28
+ checkpoint to only 2) of the requested model size
29
  """
30
 
31
  _ACTIVATIONS_DESCRIPTION = """\
32
+ Dataset for storing activations of pythia models of the requested model size
33
  """
34
 
35
+ BUILDER_CONFIGS = []
36
+ for model_size in MODEL_SIZES:
37
+ BUILDER_CONFIGS.extend([
38
+ datasets.BuilderConfig(
39
+ name=f"{model_size}__gradients",
40
+ description=_WEIGHTS_DESCRIPTION,
41
+ version="1.0.0",
42
+ ),
43
+ datasets.BuilderConfig(
44
+ name=f"{model_size}__gradients_mini",
45
+ description=_WEIGHTS_MINI_DESCRIPTION,
46
+ version="1.0.0",
47
+ ),
48
+ datasets.BuilderConfig(
49
+ name=f"{model_size}__activations",
50
+ description=_ACTIVATIONS_DESCRIPTION,
51
+ version="1.0.0",
52
+ ),
53
+ datasets.BuilderConfig(
54
+ name=f"{model_size}__weights",
55
+ description=_WEIGHTS_DESCRIPTION,
56
+ version="1.0.0",
57
+ ),
58
+ ])
59
 
60
  def _info(self):
61
  """
62
+ NOTE: we might want to specify features, but since the features are different for each
63
  model size it's annoying and kind of pointless since hf does it automatically
64
  """
65
 
 
73
  Returns data for different splits - we define a split as a model size.
74
  """
75
 
76
+ to_download_files = []
77
 
78
  kwargs_checkpoint_steps = []
79
  kwargs_gradient_steps = []
 
87
  """
88
  return list(range(max(0, step-5), min(step+6, 143_000)))
89
 
90
+ model_size = self.config.name.split("__")[0]
91
+
92
+ for checkpoint_step in checkpoint_steps:
93
+
94
+ directory_path = f"./models/{model_size}/checkpoint_{checkpoint_step}"
95
+
96
+ if "activations" in self.config.name:
97
+ to_download_files.append(f"{directory_path}/checkpoint_activations.pickle")
98
+ kwargs_checkpoint_steps.append(checkpoint_step)
99
+ elif "weights" in self.config.name:
100
+ to_download_files.append(f"{directory_path}/checkpoint_weights.pickle")
101
+ kwargs_checkpoint_steps.append(checkpoint_step)
102
+ elif "gradients" in self.config.name:
103
+ gradient_steps = get_gradient_step(checkpoint_step)
104
+ if "mini" in self.config.name:
105
+ gradient_steps = gradient_steps[:2]
106
+ for gradient_step in gradient_steps:
107
+ to_download_files.append(f"{directory_path}/checkpoint_gradients_{gradient_step}.pickle")
108
+ kwargs_checkpoint_steps.append(checkpoint_step)
109
+ kwargs_gradient_steps.append(gradient_step)
110
+ else:
111
+ raise Exception("Invalid config name")
112
+
113
+ downloaded_files = dl_manager.download_and_extract(to_download_files)
 
 
 
 
 
114
 
115
  return [
116
  datasets.SplitGenerator(
117
+ name='default',
118
  gen_kwargs={
119
+ "filepaths": downloaded_files,
120
  "checkpoint_steps": kwargs_checkpoint_steps,
121
+ **({"gradient_steps": kwargs_gradient_steps} if "gradients" in self.config.name else {}),
122
  }
123
+ )
124
  ]
125
 
126
  def _generate_examples(self, filepaths, checkpoint_steps, **kwargs):
 
129
  if isinstance(filepaths, str):
130
  filepaths = [filepaths]
131
 
132
+ if "gradients" in self.config.name:
133
  gradient_steps = kwargs["gradient_steps"]
134
 
135
  global_idx = 0 # the unique identifier for the example
 
137
  for idx, filepath in enumerate(filepaths):
138
  with open(filepath, 'rb') as f:
139
  data = pickle.load(f)
140
+
141
+ for layer_name, layer_data in data.items():
142
+ record = {
143
+ "checkpoint_step": checkpoint_steps[idx],
144
+ "layer_name": layer_name,
145
+ "data": layer_data,
146
+ }
147
+ if "gradients" in self.config.name:
148
+ record['gradient_step'] = gradient_steps[idx]
149
 
150
+ yield global_idx, record
151
+ global_idx += 1