Download hyperparameter/c2/tabddpm/tabddpm-c2-20260504_181749/_tabddpm_sample_r0.py from TabQueryBench2026/server: direct link, hf CLI and curl.
- Browser
- Download file 2.78 kB
-
https://huggingface.co/datasets/TabQueryBench2026/server/resolve/main/hyperparameter/c2/tabddpm/tabddpm-c2-20260504_181749/_tabddpm_sample_r0.py
- Command line
-
hf download hf://datasets/TabQueryBench2026/server/hyperparameter/c2/tabddpm/tabddpm-c2-20260504_181749/_tabddpm_sample_r0.py
-
curl -L -o _tabddpm_sample_r0.py https://huggingface.co/datasets/TabQueryBench2026/server/resolve/main/hyperparameter/c2/tabddpm/tabddpm-c2-20260504_181749/_tabddpm_sample_r0.py
2.78 kB
| import os, sys, subprocess, json | |
| import numpy as np | |
| import pandas as pd | |
| tabddpm_root = "/workspace/tabddpm/code" | |
| assert os.path.isdir(tabddpm_root), f"TabDDPM source not mounted: {tabddpm_root}" | |
| env = os.environ.copy() | |
| env["PYTHONPATH"] = tabddpm_root + (os.pathsep + env.get("PYTHONPATH", "")) | |
| # Reuse the compat wrapper (patches collections.Sequence for skorch) | |
| wrapper = os.path.join(tabddpm_root, "_compat_run.py") | |
| if not os.path.exists(wrapper): | |
| with open(wrapper, "w") as f: | |
| f.write( | |
| "import collections, collections.abc\n" | |
| "for _a in ('Sequence','MutableSequence','MutableMapping','Mapping'," | |
| "'MutableSet','Set','Callable','Iterable','Iterator'):\n" | |
| " if not hasattr(collections, _a): setattr(collections, _a, getattr(collections.abc, _a, None))\n" | |
| "import sys, runpy\n" | |
| "sys.argv = sys.argv[1:]\n" | |
| "runpy.run_path(sys.argv[0], run_name='__main__')\n" | |
| ) | |
| print(f"[TabDDPM] Sampling 1382 rows") | |
| ret = subprocess.run( | |
| [sys.executable, wrapper, "scripts/pipeline.py", | |
| "--config", "/work/output-Benchmark-trainonly-v1/c2/tabddpm/tabddpm-c2-20260504_181749/config_sample_20260504_182010_r0.toml", | |
| "--sample"], | |
| cwd=tabddpm_root, | |
| env=env | |
| ) | |
| if ret.returncode != 0: | |
| sys.exit(ret.returncode) | |
| # 将 .npy 输出转为 CSV(npy 在 TabDDPM 的 parent_dir,即 npy_dir) | |
| info_path = "/work/output-Benchmark-trainonly-v1/c2/tabddpm/tabddpm-c2-20260504_181749/data/info.json" | |
| with open(info_path) as f: | |
| info = json.load(f) | |
| output_dir = "/work/output-Benchmark-trainonly-v1/c2/tabddpm/tabddpm-c2-20260504_181749/output" | |
| col_names = info.get("column_names", []) | |
| parts = [] | |
| x_num_path = os.path.join(output_dir, "X_num_train.npy") | |
| x_cat_path = os.path.join(output_dir, "X_cat_train.npy") | |
| y_path = os.path.join(output_dir, "y_train.npy") | |
| if os.path.exists(x_num_path): | |
| parts.append(np.load(x_num_path, allow_pickle=True)) | |
| if os.path.exists(x_cat_path): | |
| parts.append(np.load(x_cat_path, allow_pickle=True).astype(float)) | |
| if os.path.exists(y_path): | |
| y = np.load(y_path, allow_pickle=True) | |
| parts.append(y.reshape(-1, 1) if y.ndim == 1 else y) | |
| if parts: | |
| combined = np.concatenate(parts, axis=1) | |
| if col_names and len(col_names) == combined.shape[1]: | |
| df = pd.DataFrame(combined, columns=col_names) | |
| else: | |
| df = pd.DataFrame(combined) | |
| df.to_csv("/work/output-Benchmark-trainonly-v1/c2/tabddpm/tabddpm-c2-20260504_181749/tabddpm-c2-1382-20260504_182010.csv", index=False) | |
| print(f"[TabDDPM] Saved {len(df)} rows -> /work/output-Benchmark-trainonly-v1/c2/tabddpm/tabddpm-c2-20260504_181749/tabddpm-c2-1382-20260504_182010.csv") | |
| else: | |
| print("[TabDDPM] WARNING: No output .npy files found") | |
| sys.exit(1) | |