Download scripts/schema.py from Cross-Mergeability/model-merging-benchmark: direct link, hf CLI and curl.
- Browser
- Download file 6.16 kB
-
https://huggingface.co/datasets/Cross-Mergeability/model-merging-benchmark/resolve/main/scripts/schema.py
- Command line
-
hf download hf://datasets/Cross-Mergeability/model-merging-benchmark/scripts/schema.py
-
curl -L -o schema.py https://huggingface.co/datasets/Cross-Mergeability/model-merging-benchmark/resolve/main/scripts/schema.py
6.16 kB
| """Schema for the model-merging dataset: three linked tables plus a derived summary. | |
| models.csv one row per unique checkpoint (parent, merged, control) | |
| merges.csv one row per merge experiment (pair x method x alignment x config) | |
| evaluations.csv long format: one row per model x task x config x metric, in one experiment | |
| Comparisons are made only *within* an experiment_id. A parent's score is joined to a merge's | |
| score when the two rows share experiment_id, task_name, dataset_config, split and metric_name, | |
| so a parent evaluated under a different protocol is never used as a merge's baseline. | |
| Every row records the result file it came from (source_file). Values that no file records are | |
| left empty, never inferred. | |
| """ | |
| MODELS = [ | |
| "model_id", # HF repo id when one exists, else "local:<family>/<name>" | |
| "model_role", # parent | merged | control | reference (ensemble, oracle) | |
| "experiment_family", | |
| "model_architecture", # pico | gpt_neox | llama | gemma | ... | unknown | |
| "parameters", # integer count, or empty | |
| "tokenizer", | |
| "initialisation", # seed / init id as recorded, or empty | |
| "training_data", # corpus / language / curriculum as recorded | |
| "training_steps", | |
| "checkpoint_uri", # hf://<id>[@rev] | path | empty | |
| "is_published", # True if the checkpoint exists on the Hub | |
| "source_file", | |
| ] | |
| MERGES = [ | |
| "merge_id", # stable, see make_merge_id | |
| "experiment_id", # the evaluation context comparisons are made in | |
| "experiment_family", # beetle_published | beetle_controlled | polypythia | toksuite | | |
| # cross_architecture | llama_forks | mergebench | humanscale | |
| "parent_a", | |
| "parent_b", | |
| "merged_model_id", # checkpoint id if materialised/published, else empty | |
| "merge_method", # canonical names: METHODS | |
| "alignment_method", # canonical names: ALIGNMENTS | |
| "vocabulary_transport", # True | False | |
| "model_architecture", | |
| "parameters", | |
| "initialisation_relationship", # shared | independent | unknown | |
| "training_relationship", # shared_history | divergent_history | independent | unknown | |
| "tokenizer_relationship", # shared | different | unknown | |
| "merge_alpha", | |
| "merge_config", # JSON string with every recorded hyperparameter | |
| "checkpoint_uri", | |
| "experiment_seed", | |
| "is_control", # True for shuffled/permuted/random controls | |
| "copies_parent", # True when the operator output is (effectively) one parent's tensors | |
| "evaluation_status", # complete | partial | failed | unverified | |
| "notes", | |
| "source_file", | |
| ] | |
| EVALUATIONS = [ | |
| "experiment_id", | |
| "merge_id", # empty for parent / reference rows | |
| "model_id", | |
| "model_role", # parent_a | parent_b | merged | control | reference | |
| "merge_method", # empty for parents | |
| "alignment_method", | |
| "task_name", # canonical: TASKS keys | |
| "task_category", # TASKS values | |
| "eval_group", # core | family_specific | exploratory | |
| "dataset_name", | |
| "dataset_config", # subset / language / eval_langs as recorded | |
| "split", | |
| "metric_name", # accuracy | nll | perplexity | exact_match | strict_acc | loose_acc ... | |
| "metric_value", | |
| "metric_direction", # higher | lower | |
| "n_examples", | |
| "evaluation_seed", | |
| "evaluation_status", # verified | provisional | failed | |
| "evaluation_notes", | |
| "source_file", | |
| ] | |
| SUMMARY = [ | |
| "merge_id", "experiment_id", "experiment_family", "merge_method", "alignment_method", | |
| "vocabulary_transport", "initialisation_relationship", "tokenizer_relationship", "parameters", | |
| "task_name", "dataset_config", "split", "metric_name", "metric_direction", | |
| "parent_a_value", "parent_b_value", "best_parent_value", "naive_value", "method_value", | |
| "naive_merge_loss", # NLL: L_naive - min(L_A, L_B); accuracy: max(A, B) - acc_naive | |
| "method_merge_loss", # same, for this method (positive = worse than best parent) | |
| "merge_gain", # naive_merge_loss - method_merge_loss (positive = method helped) | |
| "merge_success", # method beats the best parent (strictly) | |
| "beats_parent_a", "beats_parent_b", | |
| "task_retention", # method_value / best_parent_value (accuracy only) | |
| "alignment_gain", # unaligned-twin loss - aligned loss, same method and pair | |
| "copies_parent", "is_control", "evaluation_status", | |
| ] | |
| METHODS = { # canonical merge_method values | |
| "average", "task_arithmetic", "ties", "dare", "qmd", "slerp", "csp", "svc", "opcm", | |
| "ot_fusion", "chat_vector", "interpolation", "ensemble", "other", | |
| } | |
| ALIGNMENTS = {"none", "permutation", "ot", "procrustes", "vocab_transport", "other"} | |
| TASKS = { # task_name -> task_category | |
| "blimp": "linguistic", "multiblimp": "multilingual", "xblimp": "multilingual", | |
| "wikitext": "language_modelling", "fineweb": "language_modelling", "lm_nll": "language_modelling", | |
| "flores": "multilingual", "ifeval": "instruction_following", "pythia_suite": "general", | |
| "arc_easy": "general", "arc_challenge": "general", "piqa": "general", "hellaswag": "general", | |
| "lambada": "general", "sciq": "general", "winogrande": "general", | |
| "gsm8k": "reasoning", "math": "reasoning", "mmlu": "general", "other": "other", | |
| } | |
| CORE_TASKS = {"blimp", "wikitext", "lm_nll", "pythia_suite", "arc_easy", "piqa", "lambada", "sciq"} | |
| LOWER_IS_BETTER = {"nll", "perplexity", "loss", "bits_per_byte"} | |
| def make_merge_id(family, parent_a, parent_b, method, alignment, config=""): | |
| """Stable id: two merges differing in any config value are different experiments.""" | |
| import hashlib | |
| key = "|".join(map(str, (family, parent_a, parent_b, method, alignment, config))) | |
| return f"{family}:{hashlib.sha1(key.encode()).hexdigest()[:12]}" | |
| def direction(metric_name): | |
| return "lower" if metric_name in LOWER_IS_BETTER else "higher" | |