Spaces:
Sleeping
Sleeping
harmonizing function name and signature changes
Browse files
dashboards/dashboard_utils.py
CHANGED
|
@@ -53,7 +53,6 @@ def ensure_offline_available(path: Path):
|
|
| 53 |
def get_available_datasets(campaign: str = "step-analysis_001") -> list[str]:
|
| 54 |
"""Scan Drive for available datasets matching pattern."""
|
| 55 |
drive_path = Path(get_data_path()) / campaign
|
| 56 |
-
|
| 57 |
if not drive_path.exists():
|
| 58 |
return []
|
| 59 |
|
|
@@ -65,6 +64,19 @@ def get_available_datasets(campaign: str = "step-analysis_001") -> list[str]:
|
|
| 65 |
datasets.append(ds_name)
|
| 66 |
return sorted(datasets, key=model_size_from_name)
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
@st.cache_data
|
| 69 |
def load_dataset_with_metadata(ds_name: str, campaign: str, hf_version: str=None):
|
| 70 |
"""Load dataset after ensuring offline availability."""
|
|
|
|
| 53 |
def get_available_datasets(campaign: str = "step-analysis_001") -> list[str]:
|
| 54 |
"""Scan Drive for available datasets matching pattern."""
|
| 55 |
drive_path = Path(get_data_path()) / campaign
|
|
|
|
| 56 |
if not drive_path.exists():
|
| 57 |
return []
|
| 58 |
|
|
|
|
| 64 |
datasets.append(ds_name)
|
| 65 |
return sorted(datasets, key=model_size_from_name)
|
| 66 |
|
| 67 |
+
def get_available_campaigns(campaign_pattern: str = "ana-") -> list[str]:
|
| 68 |
+
"""Scan Drive for available datasets matching pattern."""
|
| 69 |
+
drive_path = Path(get_data_path())
|
| 70 |
+
if not drive_path.exists():
|
| 71 |
+
return []
|
| 72 |
+
|
| 73 |
+
datasets = []
|
| 74 |
+
for item in drive_path.iterdir():
|
| 75 |
+
if item.is_dir() and item.name.startswith(campaign_pattern):
|
| 76 |
+
# Extract DS_NAME by removing suffix
|
| 77 |
+
datasets.append(item.name)
|
| 78 |
+
return sorted(datasets, key=model_size_from_name)
|
| 79 |
+
|
| 80 |
@st.cache_data
|
| 81 |
def load_dataset_with_metadata(ds_name: str, campaign: str, hf_version: str=None):
|
| 82 |
"""Load dataset after ensuring offline availability."""
|
dashboards/pages/weights_dashboard.py
CHANGED
|
@@ -9,7 +9,19 @@ def weights_dashboard_app():
|
|
| 9 |
plot_display = {"P(W)": "P_w", "P(λ)": "P_sv", "SVD": "SVD"}
|
| 10 |
|
| 11 |
# Load data
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
model_names = get_unique_values(df_full, "model")
|
| 15 |
model_selected = st.sidebar.selectbox("Model", model_names)
|
|
@@ -115,6 +127,7 @@ def weights_dashboard_app():
|
|
| 115 |
# Section 2: Across layers/heads
|
| 116 |
########################################################################
|
| 117 |
st.header("Statistics Across Architecture")
|
|
|
|
| 118 |
|
| 119 |
# Multi-select for statistics
|
| 120 |
selected_stats = st.multiselect(
|
|
@@ -134,7 +147,6 @@ def weights_dashboard_app():
|
|
| 134 |
)
|
| 135 |
|
| 136 |
# Prepare data
|
| 137 |
-
df_sorted = df.sort_values(["layer", "head"])
|
| 138 |
|
| 139 |
# Color palette
|
| 140 |
colors = px.colors.qualitative.Plotly[:len(selected_stats)]
|
|
@@ -166,7 +178,7 @@ def weights_dashboard_app():
|
|
| 166 |
# Style the corresponding y-axis
|
| 167 |
axis_config = dict(
|
| 168 |
title=stat_display_name,
|
| 169 |
-
|
| 170 |
tickfont=dict(color=colors[idx])
|
| 171 |
)
|
| 172 |
if use_secondary:
|
|
|
|
| 9 |
plot_display = {"P(W)": "P_w", "P(λ)": "P_sv", "SVD": "SVD"}
|
| 10 |
|
| 11 |
# Load data
|
| 12 |
+
available_datasets = get_available_campaigns('ana-')
|
| 13 |
+
if not available_datasets:
|
| 14 |
+
st.error(f"No datasets found.")
|
| 15 |
+
st.stop()
|
| 16 |
+
|
| 17 |
+
# Dataset dropdown
|
| 18 |
+
campaign_name = st.sidebar.selectbox(
|
| 19 |
+
"Campaign",
|
| 20 |
+
available_datasets,
|
| 21 |
+
index=0
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
df_full, metadata = load_dataset_with_metadata(ds_name='weight_study', campaign=campaign_name, hf_version='ana-003')
|
| 25 |
|
| 26 |
model_names = get_unique_values(df_full, "model")
|
| 27 |
model_selected = st.sidebar.selectbox("Model", model_names)
|
|
|
|
| 127 |
# Section 2: Across layers/heads
|
| 128 |
########################################################################
|
| 129 |
st.header("Statistics Across Architecture")
|
| 130 |
+
df_sorted = df.sort_values(["layer", "head"])
|
| 131 |
|
| 132 |
# Multi-select for statistics
|
| 133 |
selected_stats = st.multiselect(
|
|
|
|
| 147 |
)
|
| 148 |
|
| 149 |
# Prepare data
|
|
|
|
| 150 |
|
| 151 |
# Color palette
|
| 152 |
colors = px.colors.qualitative.Plotly[:len(selected_stats)]
|
|
|
|
| 178 |
# Style the corresponding y-axis
|
| 179 |
axis_config = dict(
|
| 180 |
title=stat_display_name,
|
| 181 |
+
title_font=dict(color=colors[idx]),
|
| 182 |
tickfont=dict(color=colors[idx])
|
| 183 |
)
|
| 184 |
if use_secondary:
|
notebooks/low_rank_SVD_systematics.ipynb
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
scripts/diff_datasets.py
CHANGED
|
@@ -56,9 +56,9 @@ def diff_datasets(name1, name2, path=None, topN=20):
|
|
| 56 |
if stats1 != stats2:
|
| 57 |
print(f"stats columns DIFFER:")
|
| 58 |
if stats1 - stats2:
|
| 59 |
-
print(f" Only in
|
| 60 |
if stats2 - stats1:
|
| 61 |
-
print(f" Only in
|
| 62 |
exclude_cols.update(stats1 ^ stats2) # exclude non-common stats columns
|
| 63 |
|
| 64 |
# Compare remaining metadata
|
|
|
|
| 56 |
if stats1 != stats2:
|
| 57 |
print(f"stats columns DIFFER:")
|
| 58 |
if stats1 - stats2:
|
| 59 |
+
print(f" Only in reference: {stats1 - stats2}")
|
| 60 |
if stats2 - stats1:
|
| 61 |
+
print(f" Only in target: {stats2 - stats1}")
|
| 62 |
exclude_cols.update(stats1 ^ stats2) # exclude non-common stats columns
|
| 63 |
|
| 64 |
# Compare remaining metadata
|
scripts/merge_datasets.py
CHANGED
|
@@ -1,39 +1,76 @@
|
|
| 1 |
import json
|
| 2 |
from tqdm import tqdm
|
| 3 |
from datasets import concatenate_datasets, load_from_disk
|
| 4 |
-
from
|
| 5 |
|
| 6 |
-
SUFFIX = "all_checkpoints"
|
| 7 |
META_FILE = "metadata.json"
|
|
|
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
ds_list = []
|
| 11 |
-
|
| 12 |
for rev in tqdm(get_model_versions(model_name), desc=f'Processing {model_name}'):
|
| 13 |
pattern = f"{model_name}_{rev}"
|
| 14 |
ds = load_from_disk(f"{path}/{pattern}")
|
| 15 |
ds_list.append(ds)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
mf = f"{path}/{pattern}/{ds.info.description}"
|
| 17 |
with open(mf) as f:
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
|
|
|
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
if __name__ == '__main__' :
|
| 32 |
import argparse
|
| 33 |
parser = argparse.ArgumentParser()
|
| 34 |
-
parser.add_argument("--model", type=str, default=
|
| 35 |
parser.add_argument("--path", type=str, default='histos')
|
|
|
|
|
|
|
| 36 |
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import json
|
| 2 |
from tqdm import tqdm
|
| 3 |
from datasets import concatenate_datasets, load_from_disk
|
| 4 |
+
from transformer_analysis.histogram_utils import get_model_versions
|
| 5 |
|
|
|
|
| 6 |
META_FILE = "metadata.json"
|
| 7 |
+
META_MERGE_KEY = "merged"
|
| 8 |
|
| 9 |
+
|
| 10 |
+
def write_dataset_and_metadata(ds_list, metadata, ds_name):
|
| 11 |
+
combined_ds = concatenate_datasets(ds_list)
|
| 12 |
+
combined_ds.info.description = META_FILE
|
| 13 |
+
combined_ds.save_to_disk(ds_name)
|
| 14 |
+
with open(f"{ds_name}/{META_FILE}", "w") as f:
|
| 15 |
+
json.dump(metadata, f, indent=2)
|
| 16 |
+
|
| 17 |
+
def merge_versions(model_name = 'pythia-70m-deduped', path = 'histos', suffix = 'all_checkpoints'):
|
| 18 |
ds_list = []
|
| 19 |
+
metadata = None
|
| 20 |
for rev in tqdm(get_model_versions(model_name), desc=f'Processing {model_name}'):
|
| 21 |
pattern = f"{model_name}_{rev}"
|
| 22 |
ds = load_from_disk(f"{path}/{pattern}")
|
| 23 |
ds_list.append(ds)
|
| 24 |
+
if metadata is None:
|
| 25 |
+
with open(f"{path}/{pattern}/{ds.info.description}") as f:
|
| 26 |
+
metadata = json.load(f)
|
| 27 |
+
write_dataset_and_metadata(ds_list, metadata,f"{path}/{model_name}_{suffix}")
|
| 28 |
+
|
| 29 |
+
def merge_datasets(model_name_list, path = 'histos', out_name = 'merged', suffix=None):
|
| 30 |
+
ds_list = []
|
| 31 |
+
combined_metadata = None
|
| 32 |
+
merged_dict = {}
|
| 33 |
+
for model_name in tqdm(model_name_list, desc=f'Processing {model_name}'):
|
| 34 |
+
pattern = model_name
|
| 35 |
+
if suffix isinstance(str):
|
| 36 |
+
pattern += '_' + suffix
|
| 37 |
+
ds = load_from_disk(f"{path}/{pattern}")
|
| 38 |
+
ds_list.append(ds)
|
| 39 |
+
|
| 40 |
+
#now the metadata
|
| 41 |
mf = f"{path}/{pattern}/{ds.info.description}"
|
| 42 |
with open(mf) as f:
|
| 43 |
+
metadata = json.load(f)
|
| 44 |
+
if combined_metadata is None:
|
| 45 |
+
combined_metadata = {k: v for k, v in metadata.items() if k != merge_key}
|
| 46 |
+
if META_MERGE_KEY in metadata: # Flatten
|
| 47 |
+
for k, v in metadata[META_MERGE_KEY].items():
|
| 48 |
+
key = k
|
| 49 |
+
while key in merged_dict: #make key name unique
|
| 50 |
+
key = f'{model_name}_{key}'
|
| 51 |
+
merged_dict[key] = v
|
| 52 |
+
else:
|
| 53 |
+
merged_dict[model_name] = metadata
|
| 54 |
|
| 55 |
+
combined_metadata.update(META_MERGE_KEY, merged_dict)
|
| 56 |
+
write_dataset_and_metadata(ds_list, combined_metadata, f"{path}/{out_name}")
|
| 57 |
|
| 58 |
|
| 59 |
if __name__ == '__main__' :
|
| 60 |
import argparse
|
| 61 |
parser = argparse.ArgumentParser()
|
| 62 |
+
parser.add_argument("--model", type=str, default=None)
|
| 63 |
parser.add_argument("--path", type=str, default='histos')
|
| 64 |
+
parser.add_argument("--out-name", type=str, default='weight_study')
|
| 65 |
+
parser.add_argument("--suffix", type=str, default='all_checkpoints')
|
| 66 |
args = parser.parse_args()
|
| 67 |
+
|
| 68 |
+
if args.model is not None:
|
| 69 |
+
merge_versions(model_name=args.model, path=args.path, suffix=args.suffix):
|
| 70 |
|
| 71 |
+
else:
|
| 72 |
+
import os
|
| 73 |
+
from pathlib import Path
|
| 74 |
+
path = Path(args.path)
|
| 75 |
+
model_list = [d.name for d in path.glob("*/") if args.out_name not in d.name]
|
| 76 |
+
merge_datasets(model_list, path=args.path, out_name=args.out_name)
|
scripts/run_model_sweep.py
CHANGED
|
@@ -1,21 +1,21 @@
|
|
| 1 |
import os
|
| 2 |
-
from
|
| 3 |
-
from
|
| 4 |
-
from transformer_analaysisrun_weight_analysis import process_model, create_versioned_dir
|
| 5 |
-
from transformer_analaysismodel_registry import MODEL_CONFIGS
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
hf_logging.set_verbosity_error()
|
| 11 |
import warnings
|
| 12 |
warnings.filterwarnings('ignore')
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
for model_name in tqdm(models):
|
| 19 |
target_dir = os.path.join(out_dir, model_name)
|
| 20 |
if os.path.exists(target_dir):
|
| 21 |
if clobber:
|
|
@@ -24,6 +24,10 @@ def main(out_dir='Drive/ana-002', clobber=False):
|
|
| 24 |
print(f'Model = {model_name} output exists as {target_dir}. SKIPPING.')
|
| 25 |
continue
|
| 26 |
process_model(model_name=model_name, cache_dir='./downloads', revision=None, out_dir=out_dir,cleanup_downloads=True)
|
|
|
|
| 27 |
|
| 28 |
if __name__ == "__main__":
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
from transformer_analysis.run_weight_analysis import process_model, create_versioned_dir
|
| 3 |
+
from transformer_analysis.model_registry import MODEL_CONFIGS
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
def model_sweep(model_list, out_dir='Drive/ana-002', clobber=False):
|
| 6 |
+
from tqdm import tqdm
|
| 7 |
+
from transformers import logging as hf_logging
|
| 8 |
|
| 9 |
hf_logging.set_verbosity_error()
|
| 10 |
import warnings
|
| 11 |
warnings.filterwarnings('ignore')
|
| 12 |
|
| 13 |
+
for model_name in tqdm(model_list):
|
| 14 |
+
|
| 15 |
+
print('\n' + '-'*40 + '\n')
|
| 16 |
+
print(f'Processing Model = {model_name}')
|
| 17 |
+
print('\n' + '-'*40 + '\n')
|
| 18 |
|
|
|
|
| 19 |
target_dir = os.path.join(out_dir, model_name)
|
| 20 |
if os.path.exists(target_dir):
|
| 21 |
if clobber:
|
|
|
|
| 24 |
print(f'Model = {model_name} output exists as {target_dir}. SKIPPING.')
|
| 25 |
continue
|
| 26 |
process_model(model_name=model_name, cache_dir='./downloads', revision=None, out_dir=out_dir,cleanup_downloads=True)
|
| 27 |
+
print('\n' + '-'*40 + '\n')
|
| 28 |
|
| 29 |
if __name__ == "__main__":
|
| 30 |
+
|
| 31 |
+
models=[k for k in MODEL_CONFIGS.keys() if 'tral-' in k] #mistral and mixtral
|
| 32 |
+
models.extend([k for k in MODEL_CONFIGS.keys() if 'llama-' in k])
|
| 33 |
+
model_sweep(model_list=models, out_dir='Drive/ana-002', clobber=False):
|
src/transformer_analysis/run_weight_analysis.py
CHANGED
|
@@ -166,34 +166,22 @@ def process_model(
|
|
| 166 |
logging.info(f"Performance saved to {out_dir}/logs/perf_{job_id}.json")
|
| 167 |
|
| 168 |
|
| 169 |
-
def
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
|
| 173 |
-
base_dir = os.path.join(path, f"{name}_{timestamp}")
|
| 174 |
-
else:
|
| 175 |
-
base_dir = os.path.join(path, name)
|
| 176 |
|
| 177 |
if not os.path.exists(base_dir):
|
| 178 |
os.makedirs(base_dir)
|
|
|
|
| 179 |
return base_dir
|
| 180 |
|
| 181 |
elif clobber:
|
| 182 |
shutil.rmtree(base_dir)
|
| 183 |
os.makedirs(base_dir)
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
if not increment:
|
| 187 |
return base_dir
|
| 188 |
|
| 189 |
-
|
| 190 |
-
for i in range(1, 1000):
|
| 191 |
-
versioned_dir = f"{base_dir}_{i:03d}"
|
| 192 |
-
if not os.path.exists(versioned_dir):
|
| 193 |
-
os.makedirs(versioned_dir)
|
| 194 |
-
return versioned_dir
|
| 195 |
-
|
| 196 |
-
raise RuntimeError("Could not find available directory suffix")
|
| 197 |
|
| 198 |
|
| 199 |
|
|
@@ -212,10 +200,8 @@ if __name__ == "__main__":
|
|
| 212 |
print('='*20 + 'Test option selected' + '='*20)
|
| 213 |
print('\t\t' + 'output and clobber options will be overwritten')
|
| 214 |
args.out, args.clobber = 'test', True
|
| 215 |
-
|
| 216 |
cwd = os.getcwd()
|
| 217 |
-
out_dir =
|
| 218 |
-
log_dir = create_versioned_dir(path=out_dir, name='logs', clobber=args.clobber)
|
| 219 |
model_name = args.model
|
| 220 |
|
| 221 |
model_config = get_model_config(args.model)
|
|
|
|
| 166 |
logging.info(f"Performance saved to {out_dir}/logs/perf_{job_id}.json")
|
| 167 |
|
| 168 |
|
| 169 |
+
def create_campaign(path, name, clobber=False, logs=True):
|
| 170 |
+
base_dir = os.path.join(path, name)
|
| 171 |
+
log_dir = os.path.join(base_dir,'logs')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
if not os.path.exists(base_dir):
|
| 174 |
os.makedirs(base_dir)
|
| 175 |
+
os.makedirs(log_dir)
|
| 176 |
return base_dir
|
| 177 |
|
| 178 |
elif clobber:
|
| 179 |
shutil.rmtree(base_dir)
|
| 180 |
os.makedirs(base_dir)
|
| 181 |
+
os.makedirs(log_dir)
|
|
|
|
|
|
|
| 182 |
return base_dir
|
| 183 |
|
| 184 |
+
raise RuntimeError(f"Project directory exists, rename or clobber:\n{base_dir}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
|
| 187 |
|
|
|
|
| 200 |
print('='*20 + 'Test option selected' + '='*20)
|
| 201 |
print('\t\t' + 'output and clobber options will be overwritten')
|
| 202 |
args.out, args.clobber = 'test', True
|
|
|
|
| 203 |
cwd = os.getcwd()
|
| 204 |
+
out_dir = create_campaign(path=cwd, name=args.out, clobber=args.clobber, logs=True)
|
|
|
|
| 205 |
model_name = args.model
|
| 206 |
|
| 207 |
model_config = get_model_config(args.model)
|