Reorganise: group 313 tasks into 17 families under tasks/, generators under tools/ (part 2)
Browse files
tools/factory/audit_schema.py
CHANGED
|
@@ -33,6 +33,15 @@ def const(src, name, default=None):
|
|
| 33 |
return default
|
| 34 |
for n in tree.body:
|
| 35 |
if isinstance(n, ast.Assign):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
for t in n.targets:
|
| 37 |
if isinstance(t, ast.Name) and t.id == name:
|
| 38 |
try:
|
|
@@ -79,6 +88,7 @@ def emit(task):
|
|
| 79 |
if fm:
|
| 80 |
entry = fm
|
| 81 |
break
|
|
|
|
| 82 |
graded = const(src, "GRADER_SHAPES", []) or []
|
| 83 |
correct = const(src, "CORRECT_SHAPES", []) or []
|
| 84 |
measure = const(src, "MEASURE_SHAPES", []) or []
|
|
@@ -94,14 +104,45 @@ def emit(task):
|
|
| 94 |
dims = dims_mk + ["batch", "prefill", "decode_steps"]
|
| 95 |
graded = correct = [pt]
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
cw = ""
|
| 98 |
m = re.search(r"^def canonical_work\(([^)]*)\)", src, re.M)
|
| 99 |
-
dims = [x.strip() for x in m.group(1).split(",")] if m else []
|
| 100 |
if m:
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
cw = r.group(1).strip() if r else ""
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
rec = {
|
| 106 |
"name": task,
|
| 107 |
"family": CAT.get(task, {}).get("family", "Other"),
|
|
@@ -183,6 +224,11 @@ def main():
|
|
| 183 |
w = r["workloads"]["synthetic"]
|
| 184 |
if not w["graded"] or not w["correctness"]:
|
| 185 |
bad.append((t, "workload has no graded/correctness shapes"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
recs.append(r)
|
| 187 |
(LANE / "TASKS.json").write_text(json.dumps(recs, indent=2) + "\n")
|
| 188 |
|
|
|
|
| 33 |
return default
|
| 34 |
for n in tree.body:
|
| 35 |
if isinstance(n, ast.Assign):
|
| 36 |
+
# tuple unpacking: BATCH, PREFILL, MAX_SEQ = 1, 2048, 4096
|
| 37 |
+
for t in n.targets:
|
| 38 |
+
if isinstance(t, ast.Tuple) and isinstance(n.value, ast.Tuple):
|
| 39 |
+
for tgt, val in zip(t.elts, n.value.elts):
|
| 40 |
+
if isinstance(tgt, ast.Name) and tgt.id == name:
|
| 41 |
+
try:
|
| 42 |
+
return ast.literal_eval(val)
|
| 43 |
+
except Exception:
|
| 44 |
+
pass
|
| 45 |
for t in n.targets:
|
| 46 |
if isinstance(t, ast.Name) and t.id == name:
|
| 47 |
try:
|
|
|
|
| 88 |
if fm:
|
| 89 |
entry = fm
|
| 90 |
break
|
| 91 |
+
dims = []
|
| 92 |
graded = const(src, "GRADER_SHAPES", []) or []
|
| 93 |
correct = const(src, "CORRECT_SHAPES", []) or []
|
| 94 |
measure = const(src, "MEASURE_SHAPES", []) or []
|
|
|
|
| 104 |
dims = dims_mk + ["batch", "prefill", "decode_steps"]
|
| 105 |
graded = correct = [pt]
|
| 106 |
|
| 107 |
+
def _params(fn_src):
|
| 108 |
+
"""Positional dim names of a function: drop defaulted params (chunk_size=64) and `seed`."""
|
| 109 |
+
out = []
|
| 110 |
+
for raw in fn_src.split(","):
|
| 111 |
+
nm = raw.split("=")[0].strip()
|
| 112 |
+
if not nm or "=" in raw or nm in ("seed", "self") or nm.startswith("*"):
|
| 113 |
+
continue
|
| 114 |
+
out.append(nm)
|
| 115 |
+
return out
|
| 116 |
+
|
| 117 |
cw = ""
|
| 118 |
m = re.search(r"^def canonical_work\(([^)]*)\)", src, re.M)
|
|
|
|
| 119 |
if m:
|
| 120 |
+
dims = _params(m.group(1))
|
| 121 |
+
if not dims:
|
| 122 |
+
# legacy graders name the work function differently; the input generator's signature is the
|
| 123 |
+
# authoritative list of dims either way
|
| 124 |
+
mk = re.search(r"^def _(?:mk|make)\(([^)]*)\)", src, re.M)
|
| 125 |
+
if mk:
|
| 126 |
+
dims = _params(mk.group(1))
|
| 127 |
+
if m:
|
| 128 |
+
r = re.search(r"return (.+)", src[m.start():])
|
| 129 |
cw = r.group(1).strip() if r else ""
|
| 130 |
|
| 131 |
+
# Most authoritative of all: how the grader itself unpacks a shape tuple. A legacy shape can carry
|
| 132 |
+
# config the input generator does not name as a parameter (flash-attn-backward's causal flag).
|
| 133 |
+
if graded:
|
| 134 |
+
want = len(graded[0])
|
| 135 |
+
if len(dims) != want:
|
| 136 |
+
for pat in (r"for\s+\w+,\s*\(([^)]+)\)\s+in\s+enumerate\(\s*(?:GRADER|CORRECT)_SHAPES",
|
| 137 |
+
r"for\s+\(([^)]+)\)\s+in\s+(?:GRADER|CORRECT)_SHAPES",
|
| 138 |
+
r"\(([^)]+)\)\s*=\s*shp\b"):
|
| 139 |
+
u = re.search(pat, src)
|
| 140 |
+
if u:
|
| 141 |
+
cand = [x.strip() for x in u.group(1).split(",") if x.strip()]
|
| 142 |
+
if len(cand) == want:
|
| 143 |
+
dims = cand
|
| 144 |
+
break
|
| 145 |
+
|
| 146 |
rec = {
|
| 147 |
"name": task,
|
| 148 |
"family": CAT.get(task, {}).get("family", "Other"),
|
|
|
|
| 224 |
w = r["workloads"]["synthetic"]
|
| 225 |
if not w["graded"] or not w["correctness"]:
|
| 226 |
bad.append((t, "workload has no graded/correctness shapes"))
|
| 227 |
+
elif w["dims"] and any(len(sh) != len(w["dims"]) for sh in w["graded"]):
|
| 228 |
+
n = next(len(sh) for sh in w["graded"] if len(sh) != len(w["dims"]))
|
| 229 |
+
bad.append((t, f"{len(w['dims'])} dim names for a {n}-value shape"))
|
| 230 |
+
elif not w["dims"]:
|
| 231 |
+
bad.append((t, "workload shapes have no dim names"))
|
| 232 |
recs.append(r)
|
| 233 |
(LANE / "TASKS.json").write_text(json.dumps(recs, indent=2) + "\n")
|
| 234 |
|