Created
June 30, 2026 08:26
-
-
Save KohakuBlueleaf/184911ab63d5a4a0a48b5a6cf7134e3a to your computer and use it in GitHub Desktop.
A simple script to find and reproduce the "different are in MIG group" in Intel FloorSet training partition.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Minimal, self-contained reproduction of the FloorSet-Lite MIB inconsistency. | |
| MIB (Multiple-Instantiation Block) requires every member of a group to share IDENTICAL (w,h) | |
| dimensions -- which forces an identical area. This script proves, straight from IntelLabs' published | |
| data (no project code on the train path), that the TRAIN set assigns members of one MIB group | |
| DIFFERENT target areas, so the MIB constraint is unsatisfiable by construction. It then runs the exact | |
| same check on the VAL set, which is clean -- demonstrating the check is correct and the bug is in the | |
| train data, not the check. | |
| Raw layout tensor layout (FloorSet-Lite): ``c[0][i]`` is ``[n,6]`` with column 0 = target area and | |
| columns 1..5 = constraints ``[fixed, preplaced, mib_id, cluster_id, boundary_code]``. So the overall | |
| MIB-id column is index 3, and target area is index 0. Padding rows have area == -1. | |
| python poc/repro_mib_bug.py # uses our extracted val dir if present | |
| python poc/repro_mib_bug.py --val-tar # also re-download val tar to be fully independent | |
| """ | |
| import argparse | |
| import io | |
| import tarfile | |
| import urllib.request | |
| import numpy as np | |
| import torch | |
| HF = "https://huggingface.co/datasets/IntelLabs/FloorSet/resolve/main/" | |
| TRAIN_TAR = HF + "LiteTensorData_v2.tar.gz" # 1M-layout train set (~6.6 GB; we stream ONE file out) | |
| VAL_TAR = HF + "LiteTensorDataTest.tar.gz" # 100-case val set (~69 MB) | |
| AREA_COL = 0 # raw [n,6] column 0 | |
| MIB_COL = 3 # raw [n,6] column 3 == constraints[:,2] | |
| ROUND = 4 # official MIB rounds (w,h) to 4 decimals | |
| def _stream_first_th(url, name_filter): | |
| """Stream a .tar.gz over HTTP and return the bytes of the first matching member (no full download).""" | |
| req = urllib.request.Request(url, headers={"User-Agent": "curl/8"}) | |
| resp = urllib.request.urlopen(req, timeout=120) | |
| tf = tarfile.open(fileobj=resp, mode="r|gz") | |
| try: | |
| for m in tf: | |
| if m.isfile() and name_filter(m.name): | |
| return m.name, tf.extractfile(m).read() | |
| finally: | |
| tf.close() | |
| resp.close() | |
| raise SystemExit(f"no member matched in {url}") | |
| def _mib_report(layouts, source, max_print=8): | |
| """Per-layout MIB check over a list of raw ``[n,6]`` tensors. Returns (n_layouts, n_bad).""" | |
| n_bad = 0 | |
| printed = 0 | |
| print(f"\n========== {source}: {len(layouts)} layouts ==========") | |
| for li, raw in enumerate(layouts): | |
| raw = raw[raw[:, AREA_COL] != -1] # drop padding | |
| area = raw[:, AREA_COL].numpy().astype(np.float64) | |
| mib = raw[:, MIB_COL].numpy().astype(np.int64) | |
| bad_groups = [] | |
| for g in range(1, int(mib.max()) + 1 if mib.size else 1): | |
| idx = np.nonzero(mib == g)[0] | |
| if idx.shape[0] < 2: | |
| continue | |
| areas = np.round(area[idx], ROUND) | |
| if np.unique(areas).size > 1: | |
| bad_groups.append((g, idx.tolist(), areas.tolist())) | |
| if bad_groups: | |
| n_bad += 1 | |
| if printed < max_print: | |
| printed += 1 | |
| for g, members, areas in bad_groups: | |
| print( | |
| f" [IMPOSSIBLE] layout {li} MIB group {g}: members={members}\n" | |
| f" target areas={areas} -> {len(set(areas))} distinct " | |
| f"(MIB needs all equal)" | |
| ) | |
| print(f" -> {n_bad}/{len(layouts)} layouts have an impossible MIB group " | |
| f"({100 * n_bad / max(len(layouts), 1):.1f}%)") | |
| return len(layouts), n_bad | |
| def _load_val_layouts(use_tar): | |
| """Val raw ``[n,6]`` layouts -- from our extracted dir if present, else stream the val tar.""" | |
| if not use_tar: | |
| try: | |
| from kohakudifffs.data.paths import find_floorset_root, validation_case_path | |
| root = find_floorset_root(allow_download=True) | |
| out = [] | |
| for n in range(21, 121): | |
| data_path, _ = validation_case_path(root, n) | |
| c = torch.load(data_path, weights_only=False) | |
| out.append(c[0][0]) # one layout per val file, raw [n,6] | |
| return out, "VAL (extracted dir)" | |
| except Exception as e: # noqa: BLE001 | |
| print(f" (val dir unavailable: {e}; streaming val tar instead)") | |
| # stream every case_*.th out of the val tar | |
| req = urllib.request.Request(VAL_TAR, headers={"User-Agent": "curl/8"}) | |
| resp = urllib.request.urlopen(req, timeout=120) | |
| tf = tarfile.open(fileobj=resp, mode="r|gz") | |
| out = [] | |
| try: | |
| for m in tf: | |
| if m.isfile() and m.name.endswith(".th"): | |
| c = torch.load(io.BytesIO(tf.extractfile(m).read()), weights_only=False) | |
| out.append(c[0][0]) | |
| finally: | |
| tf.close() | |
| resp.close() | |
| return out, "VAL (streamed tar)" | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--val-tar", action="store_true", help="re-download val tar (fully independent)") | |
| args = ap.parse_args() | |
| # 1) TRAIN: stream ONE raw worker file straight from IntelLabs HF -- no project code involved. | |
| print("downloading one raw TRAIN layouts file from IntelLabs/FloorSet (streaming the tar)...") | |
| name, blob = _stream_first_th(TRAIN_TAR, lambda s: "layouts_" in s and s.endswith(".th")) | |
| print(f" got: {name}") | |
| c = torch.load(io.BytesIO(blob), weights_only=False) | |
| train_layouts = list(c[0]) # 112 raw [n,6] layouts in this file | |
| tn, tb = _mib_report(train_layouts, f"TRAIN raw {name}") | |
| # 2) VAL: same check; expected clean -> proves the check is correct. | |
| val_layouts, val_src = _load_val_layouts(args.val_tar) | |
| vn, vb = _mib_report(val_layouts, val_src) | |
| print("\n========== SUMMARY ==========") | |
| print(f" TRAIN {name}: {tb}/{tn} impossible-MIB layouts") | |
| print(f" {val_src}: {vb}/{vn} impossible-MIB layouts") | |
| if tb > 0 and vb == 0: | |
| print(" CONCLUSION: train MIB groups have mismatched member areas (unsatisfiable); val is") | |
| print(" clean -- so the check is sound and the inconsistency is in the TRAIN source data.") | |
| else: | |
| print(" (unexpected: re-examine)") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment