summaryrefslogtreecommitdiff
path: root/experiments/crossover_registry.py
blob: 638ba95231ae28dbac7405823e37dbdda025bbf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python3
"""Machine-readable registry for the complete cross-architecture panel."""
import json


METHODS = (
    "bp",
    "fa",
    "dfa",
    "pepita",
    "ff",
    "ep",
    "dualprop",
    "clean_kp",
    "sdil",
)

ARCHITECTURES = (
    {
        "id": "minicnn",
        "family": "plain_cnn",
        "scale_index": 0,
        "size": {"trainable_layers": 3},
    },
    {
        "id": "vgglike",
        "family": "plain_cnn",
        "scale_index": 1,
        "size": {"trainable_layers": 5},
    },
    {
        "id": "vgg16",
        "family": "plain_cnn",
        "scale_index": 2,
        "size": {"trainable_layers": 16},
    },
    {
        "id": "resnet20",
        "family": "residual_cnn",
        "scale_index": 0,
        "size": {"depth": 20, "base_width": 16},
    },
    {
        "id": "resnet32",
        "family": "residual_cnn",
        "scale_index": 1,
        "size": {"depth": 32, "base_width": 16},
    },
    {
        "id": "resnet56",
        "family": "residual_cnn",
        "scale_index": 2,
        "size": {"depth": 56, "base_width": 16},
    },
    {
        "id": "transformer4",
        "family": "decoder_transformer",
        "scale_index": 0,
        "size": {"blocks": 4, "width": 128, "context": 64},
    },
    {
        "id": "transformer8",
        "family": "decoder_transformer",
        "scale_index": 1,
        "size": {"blocks": 8, "width": 128, "context": 64},
    },
    {
        "id": "transformer12",
        "family": "decoder_transformer",
        "scale_index": 2,
        "size": {"blocks": 12, "width": 128, "context": 64},
    },
)


def primary_cells():
    cells = []
    for architecture in ARCHITECTURES:
        for method in METHODS:
            cells.append({
                "cell_id": f"{architecture['id']}::{method}",
                "architecture": architecture["id"],
                "family": architecture["family"],
                "scale_index": architecture["scale_index"],
                "size": architecture["size"],
                "method": method,
            })
    identifiers = [cell["cell_id"] for cell in cells]
    if len(cells) != 81 or len(set(identifiers)) != len(identifiers):
        raise AssertionError("primary crossover must contain 81 unique cells")
    for family in {row["family"] for row in ARCHITECTURES}:
        subset = [cell for cell in cells if cell["family"] == family]
        if len(subset) != 27:
            raise AssertionError(f"{family} does not contain 27 cells")
        if {cell["method"] for cell in subset} != set(METHODS):
            raise AssertionError(f"{family} is missing a method")
    return cells


def registry():
    cells = primary_cells()
    return {
        "schema_version": 1,
        "num_architecture_scale_points": len(ARCHITECTURES),
        "num_methods": len(METHODS),
        "num_primary_cells": len(cells),
        "architectures": ARCHITECTURES,
        "methods": METHODS,
        "cells": cells,
        "extension_rule":
            "Every added architecture/size must add all nine methods.",
    }


if __name__ == "__main__":
    print(json.dumps(registry(), indent=2, sort_keys=True))