mojo-tabular: tiny CPU tabular classifiers
Browse filesFiles changed (41)
- .gitignoreAdded+10
- README.mdAdded+53
- artifacts/.gitkeepAdded
- artifacts/adult.joblibAdded+3
- artifacts/bank-marketing.joblibAdded+3
- artifacts/credit-g.joblibAdded+3
- artifacts/diabetes.joblibAdded+3
- artifacts/phoneme.joblibAdded+3
- cog/.cog/cog.lockAdded
- cog/.cog/openapi_schema.jsonAdded+1
- cog/.dockerignoreAdded+3
- cog/DockerfileAdded+10
- cog/models/adult.joblibAdded+3
- cog/models/bank-marketing.joblibAdded+3
- cog/models/credit-g.joblibAdded+3
- cog/models/diabetes.joblibAdded+3
- cog/models/phoneme.joblibAdded+3
- cog/predict.pyAdded+29
- cog/requirements.txtAdded+4
- cog/server.pyAdded+53
- cog/tests/test_predict.pyAdded+36
- configs/.gitkeepAdded
- configs/project.jsonAdded+20
- prompts/.gitkeepAdded
- prompts/implement.txtAdded+9
- prompts/kernel.txtAdded+50
- prompts/review.txtAdded+124
- results/.gitkeepAdded
- results/baselines.jsonAdded+169
- results/smoke.jsonAdded+14
- results/tuned-adult.jsonAdded+44
- results/tuned-bank-marketing.jsonAdded+50
- results/tuned-credit-g.jsonAdded+40
- results/tuned-diabetes.jsonAdded+36
- results/tuned-phoneme.jsonAdded+24
- results/tuned.jsonAdded+151
- src/.gitkeepAdded
- tests/.gitkeepAdded
- train/fetch_tabular.pyAdded+17
- train/tabular_bench.pyAdded+75
- train/tabular_tune.pyAdded+89
12345678910artifacts/artifacts-gb/__pycache__/*.pyc.env**.pem*.keyprompts/REVIEW.mdcog/.cog/1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253---license: mitlibrary_name: scikit-learnpipeline_tag: tabular-classificationtags: [tabular, cpu, tiny, cog, app-nz]---
# mojo-tabular
Tiny CPU tabular classifiers (one per dataset), total 12 MB, no GPU. Trained with scikit-learn;`mojo-` is the planned optimization path, not a Mojo implementation yet.
## Results (ROC-AUC, seed 42, 60/20/20 stratified split, selection on validation only)
| dataset (OpenML) | val | test | untuned best baseline test | MB ||---|---|---|---|---|| adult | 0.929 | 0.9282 | 0.9272 | 2.64 || credit-g | 0.8294 | 0.7986 | 0.7958 | 0.00 || bank-marketing | 0.9354 | 0.9384 | 0.9375 | 2.67 || phoneme | 0.9523 | 0.9546 | 0.9554 | 5.50 || diabetes | 0.8528 | 0.8001 | 0.8031 | 1.09 |
Search: 16 random HistGradientBoosting configs + logistic regression + extra trees; top-3 averagedwhen validation improves. Single split, single seed: small sets (credit-g n=1000, diabetes n=768) havelarge validation/test gaps and are noisy. No comparison against XGBoost/CatBoost/TabPFN has been run,so **no frontier claim is made**. Adding tuned XGBoost 3.4.1 and LightGBM 4.7.0 (6 configs each) to the pool changed test AUC by at most +0.001 (adult 0.929, bank-marketing 0.9386), i.e. these results sit at the plateau of strong boosted trees; the shipped models use sklearn only to keep the image small. CatBoost and TabPFN were not compared (CatBoost hung under the 4 GiB address-space limit). Data: public OpenML sets (license listed as Public).Reproduce: `train/fetch_tabular.py`, `train/tabular_tune.py` (`--gbdt` needs xgboost/lightgbm), artifact hashes in `results/tuned.json`.
## Use
```pythonimport joblib, pandas as pdb = joblib.load("models/adult.joblib") # needs scikit-learn==1.8.0p = sum(m.predict_proba(df[b["columns"]])[:, 1] for m in b["members"]) / len(b["members"])```
## Deploy on app.nz (Cog, CPU)
```bashcd cog && python3 -m unittest discover -s tests # contract test, no networkdocker build -t ghcr.io/lee101/mojo-tabular:latest . # 381 MB (python:3.12-slim), weights bakeddocker run --rm -p 5000:5000 --memory 512m ghcr.io/lee101/mojo-tabular:latest # ~80 MB RSS, ready in <10 s```
[](https://app.nz/deploy?image=ghcr.io/lee101/mojo-tabular:latest&name=mojo-tabular&hardware=cpu&idleSeconds=60)
`POST /predictions {"input": {"dataset": "adult", "rows": "[{...}]"}}` returns a JSON list of probabilities(max 1000 rows). Do not use the default `cog build` image: its apt layer alone is 1.78 GB (2.33 GB total).Links: GitHub `lee101/mojo-tabular`, Hugging Face `lee101/mojo-tabular`.
## Limitations
Trained on public benchmark data only; not validated for credit, hiring or medical decisions.123version https://git-lfs.github.com/spec/v1oid sha256:a28557fc9992cefa1eaaf2308964baa93b1c7e78f266c1a349fd64cdb1b246a7size 2639714123version https://git-lfs.github.com/spec/v1oid sha256:ec72f430d51f216a15d3a611e6ff1ed279ecc022759160354cb821a6077f29easize 2670481123version https://git-lfs.github.com/spec/v1oid sha256:240366785f1e95fa3749b741747be6d4bb258d5be362e03cc5dec768b10d0496size 3369123version https://git-lfs.github.com/spec/v1oid sha256:50b5ecc4afc5e291dc45c7ce504a40fe2d5f735d3c86157a6c10a95407a9691fsize 1085047123version https://git-lfs.github.com/spec/v1oid sha256:e37ac3db2ba7bd9839833d8e0ac8a0a537467ddcf58b098d6550af47485fd683size 54963191{"components":{"schemas":{"Input":{"properties":{"dataset":{"title":"Dataset","type":"string","x-order":0},"rows":{"title":"Rows","type":"string","x-order":1}},"required":["dataset","rows"],"title":"Input","type":"object"},"Output":{"title":"Output","type":"string"},"PredictionRequest":{"properties":{"id":{"title":"Id","type":"string"},"input":{"$ref":"#/components/schemas/Input"}},"title":"PredictionRequest","type":"object"},"PredictionResponse":{"properties":{"completed_at":{"format":"date-time","title":"Completed At","type":"string"},"created_at":{"format":"date-time","title":"Created At","type":"string"},"error":{"title":"Error","type":"string"},"id":{"title":"Id","type":"string"},"input":{"$ref":"#/components/schemas/Input"},"logs":{"title":"Logs","type":"string"},"metrics":{"title":"Metrics","type":"object"},"output":{"$ref":"#/components/schemas/Output"},"started_at":{"format":"date-time","title":"Started At","type":"string"},"status":{"title":"Status","type":"string"},"version":{"title":"Version","type":"string"}},"title":"PredictionResponse","type":"object"},"Status":{"description":"An enumeration.","enum":["starting","processing","succeeded","canceled","failed"],"title":"Status","type":"string"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"title":"Detail","type":"array"}},"title":"HTTPValidationError","type":"object"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"title":"Location","type":"array"},"msg":{"title":"Message","type":"string"},"type":{"title":"Error Type","type":"string"}},"required":["loc","msg","type"],"title":"ValidationError","type":"object"}}},"info":{"title":"Cog","version":"0.1.0"},"openapi":"3.0.2","paths":{"/":{"get":{"operationId":"root__get","responses":{"200":{"content":{"application/json":{"schema":{}}},"description":"Successful Response"}},"summary":"Root"}},"/health-check":{"get":{"operationId":"healthcheck_health_check_get","responses":{"200":{"content":{"application/json":{"schema":{}}},"description":"Successful Response"}},"summary":"Healthcheck"}},"/predictions":{"post":{"description":"Run a single prediction on the model","operationId":"predict_predictions_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PredictionRequest"}}}},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PredictionResponse"}}},"description":"Successful Response"},"422":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}},"description":"Validation Error"}},"summary":"Predict"}},"/predictions/{prediction_id}/cancel":{"post":{"operationId":"cancel_predictions__prediction_id__cancel_post","parameters":[{"in":"path","name":"prediction_id","required":true,"schema":{"title":"Prediction Id","type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{}}},"description":"Successful Response"},"422":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}},"description":"Validation Error"}},"summary":"Cancel"}}}}123tests__pycache__*.md12345678910FROM python:3.12-slimENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 OMP_NUM_THREADS=1WORKDIR /appCOPY requirements.txt .RUN pip install --no-cache-dir -r requirements.txt && find /usr/local -name '__pycache__' -prune -exec rm -rf {} +COPY predict.py server.py ./COPY models modelsUSER nobodyEXPOSE 5000CMD ["python", "server.py"]123version https://git-lfs.github.com/spec/v1oid sha256:a28557fc9992cefa1eaaf2308964baa93b1c7e78f266c1a349fd64cdb1b246a7size 2639714123version https://git-lfs.github.com/spec/v1oid sha256:ec72f430d51f216a15d3a611e6ff1ed279ecc022759160354cb821a6077f29easize 2670481123version https://git-lfs.github.com/spec/v1oid sha256:240366785f1e95fa3749b741747be6d4bb258d5be362e03cc5dec768b10d0496size 3369123version https://git-lfs.github.com/spec/v1oid sha256:50b5ecc4afc5e291dc45c7ce504a40fe2d5f735d3c86157a6c10a95407a9691fsize 1085047123version https://git-lfs.github.com/spec/v1oid sha256:e37ac3db2ba7bd9839833d8e0ac8a0a537467ddcf58b098d6550af47485fd683size 54963191234567891011121314151617181920212223242526272829import jsonfrom pathlib import Pathimport joblibimport numpy as npimport pandas as pd
MODELS = Path(__file__).parent / 'models'MAX_ROWS = 1000
class Predictor: def setup(self): self.models = {p.stem: joblib.load(p) for p in sorted(MODELS.glob('*.joblib'))}
def predict(self, dataset: str, rows: str) -> str: if dataset not in self.models: raise ValueError(f'dataset must be one of {sorted(self.models)}') data = json.loads(rows) if isinstance(data, dict): data = [data] if not isinstance(data, list) or not data or len(data) > MAX_ROWS: raise ValueError(f'rows must be 1..{MAX_ROWS} JSON objects') bundle = self.models[dataset] missing = [c for c in bundle['columns'] if c not in data[0]] if missing: raise ValueError(f'missing columns: {missing}') df = pd.DataFrame(data).reindex(columns=bundle['columns']) p = np.mean([m.predict_proba(df)[:, 1] for m in bundle['members']], axis=0) return json.dumps([round(float(x), 6) for x in p])1234scikit-learn==1.8.0joblib==1.5.3numpy==2.3.5pandas==3.0.11234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import jsonfrom http.server import BaseHTTPRequestHandler, ThreadingHTTPServerfrom predict import Predictor
MAX_BODY = 4 * 1024 * 1024P = Predictor()STATE = {'status': 'SETUP'}SCHEMA = {'outputKind': 'json', 'inputs': [ {'name': 'dataset', 'type': 'string', 'required': True, 'order': 0, 'choices': ['adult', 'bank-marketing', 'credit-g', 'diabetes', 'phoneme'], 'description': 'Model to use (OpenML dataset schema)'}, {'name': 'rows', 'type': 'string', 'required': True, 'order': 1, 'description': 'JSON object or list of up to 1000 objects with the dataset columns'}]}
class H(BaseHTTPRequestHandler): def send(self, code, obj): b = json.dumps(obj).encode() self.send_response(code) self.send_header('content-type', 'application/json') self.send_header('content-length', str(len(b))) self.end_headers() self.wfile.write(b)
def do_GET(self): if self.path == '/health-check': self.send(200, {'status': STATE['status']}) elif self.path == '/openapi.json': self.send(200, SCHEMA) else: self.send(404, {'error': 'not found'})
def do_POST(self): if self.path != '/predictions': return self.send(404, {'error': 'not found'}) n = int(self.headers.get('content-length') or 0) if n > MAX_BODY: return self.send(413, {'status': 'failed', 'error': 'body too large'}) try: inp = json.loads(self.rfile.read(n))['input'] out = P.predict(inp['dataset'], inp['rows']) self.send(200, {'status': 'succeeded', 'output': json.loads(out)}) except Exception as e: self.send(200, {'status': 'failed', 'error': f'{type(e).__name__}: {e}'[:300]})
def log_message(self, *a): pass
if __name__ == '__main__': P.setup() STATE['status'] = 'READY' ThreadingHTTPServer(('0.0.0.0', 5000), H).serve_forever()123456789101112131415161718192021222324252627282930313233343536import json, sys, unittestfrom pathlib import Pathsys.path.insert(0, str(Path(__file__).resolve().parents[1]))import pandas as pdfrom predict import Predictor
DATA = Path('/nvme0n1-disk/cache/foundry/tabular')
class T(unittest.TestCase): @classmethod def setUpClass(cls): cls.p = Predictor() cls.p.setup()
def test_all_models(self): for name, target in [('adult', 'class'), ('credit-g', 'class'), ('bank-marketing', 'Class'), ('phoneme', 'Class'), ('diabetes', 'class')]: f = DATA / f'{name}.parquet' if not f.exists(): self.skipTest('dataset cache absent') df = pd.read_parquet(f).drop(columns=[target]).head(5) rows = df.astype(object).where(df.notna(), None).to_json(orient='records') out = json.loads(self.p.predict(name, rows)) self.assertEqual(len(out), 5) self.assertTrue(all(0 <= x <= 1 for x in out))
def test_errors(self): with self.assertRaises(ValueError): self.p.predict('nope', '[]') with self.assertRaises(ValueError): self.p.predict('adult', '[{"age": 1}]')
if __name__ == '__main__': unittest.main()1234567891011121314151617181920{ "name": "mojo-tabular", "task": "Structured-data classification and regression", "priority": 1, "status": "scaffold", "backend": "pytorch-first; mojo after parity tests", "max_parameters": 50000000, "device": "cpu", "dataset": null, "objective": null, "hf_model": null, "hf_revision": null, "profiles": [ "tiny", "fast", "balanced", "max", "robust" ]}123456789Work only in projects/mojo-tabular. Read AGENTS.md and configs/project.json.Task: Structured-data classification and regression. Implement ONE small, reviewable baseline or improvement, with tests.First inspect existing code and state your assumptions. Do not invent benchmark results.Do not download data/models, install packages, use a GPU, launch background jobs,change resource limits, access credentials, publish, or edit other projects.Use synthetic fixtures for tests. Keep the hidden test split untouched.For an HF candidate, propose its ID, immutable revision, license, parameter count,estimated RAM and dataset suitability; stop for review before any download.Finish with SUMMARY: files changed, tests run and outcomes, limitations, next step.1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950CONTEXTA small-model foundry at /sdb-disk/code/modelopt ports neural-network andfeature-transform inference kernels to Mojo. A pinned Mojo toolchain isinstalled and verified working. An existing, parity-tested example of therequired pattern is in /sdb-disk/code/modelopt/src/kernels.mojo, its Pythonbridge in /sdb-disk/code/modelopt/foundry/mojo_kernels.py and its tests in/sdb-disk/code/modelopt/tests/test_kernels.py. READ ALL THREE FIRST and copytheir exact idioms. Do not invent Mojo syntax; a wrong guess wastes your steps.
VERIFIED MOJO RECIPE (Mojo 1.2.0.dev2026092605; all known-good)- Build: export PATH=/nvme0n1-disk/code/mojo-numpy/.pixi/envs/default/bin:$PATH export MODULAR_HOME=/nvme0n1-disk/code/mojo-numpy/.pixi/envs/default/share/max mojo build --emit shared-lib <file>.mojo -o <out>.so MODULAR_HOME is mandatory or every import fails with "unable to locate module 'std'".- `--emit shared-lib` is required; a bare `mojo build` demands a main() and fails.- `def` only; `fn` is removed. `comptime W = simd_width_of[DType.float32]()`.- Pointer from an integer address: `comptime F32 = UnsafePointer[Float32, AnyOrigin[mut=True]]` then `F32(unsafe_from_address=addr)`.- @export REQUIRES an explicit abi effect: `@export("name")` on the line above `def f(a_addr: Int) abi("C"):`. Pass buffer addresses as Int, never as pointers.- SIMD: `acc += w.unsafe_load[width=W](i) * x.unsafe_load[width=W](i)`, then `total = acc.reduce_add()` plus a scalar tail loop.- Widening cast int8->float32 works as SIMD[DType.float32, W](int8_simd_value).- Traps: SIMD[DType.float32, W](bias[o]) SPLATS into every lane so reduce_add() counts the bias W times; add bias to the scalar total instead. `fn` is gone. Multi-thread Mojo builtins used by other repos turned out to be serial stubs.
YOUR TASKCreate mojo-tabular/src/kernels.mojo (do NOT edit the shared/sdb-disk/code/modelopt/src/kernels.mojo; another agent owns it) implementing: 1. quantile_rank - map each row's values to their within-row rank scaled to [0,1] 2. histogram_bin - bin each value into one of `bins` equal-width buckets, with out-of-range values clamped 3. gini_impurity - Gini impurity of a class-count vector, returning 0.0 for an empty vectorAlso create mojo-tabular/src/bridge.py (ctypes bridge that enforces float32C-contiguous inputs and raises rather than silently narrowing) andmojo-tabular/tests/test_kernels.py comparing EVERY kernel against a NumPyreference. Cover sizes that are not multiples of the SIMD width, and anydegenerate case noted above.
HARD RULES- CPU only. No GPU, no downloads, no package installs, no network access.- Synthetic fixtures only. Never fabricate accuracy, throughput or benchmark numbers.- Do not modify AGENTS.md, scripts/, pixi.toml, or any file outside mojo-tabular/.- A kernel that does not match its NumPy reference is a FAILURE, not a caveat. Actually run the tests and paste the verbatim output.
FINISH WITHSUMMARY: files created, exact test command, verbatim pass/fail counts, measuredmedian latency for one realistic shape (or "Not measured"), known limitations,and the single next step.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124Review this small-model foundry scaffold. This is a text-only task: DO NOT call tools, read files, run commands, edit code, use the network, or access credentials. Use only the supplied excerpts. Return at most 450 words, ending with SUMMARY and the three highest-impact concrete improvements. Do not claim you ran tests. Focus on resource limitations, logging/token accounting, and repeatable experimentation. The scaffold contains 21 project dirs, PyTorch-first then Mojo parity ports; no real datasets/models selected. Six runner/catalog tests and a synthetic 577-parameter tabular smoke run passed.
#!/usr/bin/env python3"""Bound a local CPU task and retain its complete transcript."""import argparseimport datetimeimport fcntlimport jsonimport osfrom pathlib import Pathimport resourceimport subprocessimport time
ROOT = Path(__file__).resolve().parents[1]
def constrain(): os.nice(10) cores = sorted(os.sched_getaffinity(0))[:2] os.sched_setaffinity(0, cores) resource.setrlimit(resource.RLIMIT_AS, (4 * 1024**3, 4 * 1024**3)) resource.setrlimit(resource.RLIMIT_FSIZE, (16 * 1024**2, 16 * 1024**2)) resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--seconds', type=int, default=120) parser.add_argument('--cwd', type=Path, default=ROOT) parser.add_argument('command', nargs=argparse.REMAINDER) args = parser.parse_args() command = args.command[1:] if args.command[:1] == ['--'] else args.command if not command or not 1 <= args.seconds <= 600: parser.error('provide a command and a wall limit of 1..600 seconds') env = os.environ.copy() env.update(CUDA_VISIBLE_DEVICES='', HIP_VISIBLE_DEVICES='', ROCR_VISIBLE_DEVICES='', OMP_NUM_THREADS='2', MKL_NUM_THREADS='2', OPENBLAS_NUM_THREADS='2', NUMEXPR_NUM_THREADS='2', HF_HUB_OFFLINE='1', TRANSFORMERS_OFFLINE='1', PYTHONPATH=str(ROOT)) logs = ROOT / 'logs' logs.mkdir(exist_ok=True) with (logs / 'research.lock').open('w') as lock: try: fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB) except BlockingIOError: parser.exit(2, 'Another foundry task is running.\n') name = datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%S') output = logs / f'{name}-{os.getpid()}.log' start = time.monotonic() timed_out = False with output.open('wb') as transcript: # GNU timeout owns a process group and kills descendants on expiry. proc = subprocess.run(['timeout', '--signal=TERM', '--kill-after=5s', f'{args.seconds}s', *command], cwd=args.cwd, env=env, preexec_fn=constrain, stdout=transcript, stderr=subprocess.STDOUT) code = proc.returncode timed_out = code in (124, 137) result = dict(command=command, cwd=str(args.cwd.resolve()), exit_code=code, timed_out=timed_out, elapsed_seconds=round(time.monotonic()-start, 3), log=str(output), limits=dict(cpu_cores=2, address_space_gib=4, wall_seconds=args.seconds, gpu=False)) output.with_suffix('.json').write_text(json.dumps(result, indent=2)+'\n') print(json.dumps(result, indent=2)) print(''.join(output.read_text(errors='replace').splitlines(keepends=True)[-100:])) return code
if __name__ == '__main__': raise SystemExit(main())
#!/usr/bin/env python3"""Run a small Bunny request, retaining input, output and reported usage."""import argparseimport datetimeimport jsonimport osfrom pathlib import Pathimport subprocess
ROOT = Path(__file__).resolve().parents[1]
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('prompt', type=Path) args = parser.parse_args() prompt = args.prompt.read_text() if not prompt.strip() or len(prompt.encode()) > 16_384: parser.error('prompt must be nonempty and at most 16 KiB') wrapper = Path.home() / 'code/dotfiles/subagents/di-bunny.sh' if not wrapper.is_file() or not os.environ.get('OPENROUTER_API_KEY'): parser.exit(2, 'Bunny wrapper or OPENROUTER_API_KEY unavailable.\n') tag = datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%S') job = ROOT / 'logs' / f'bunny-{tag}-{os.getpid()}' job.mkdir(parents=True) (job / 'input.txt').write_text(prompt) env = os.environ.copy() env.update(DI_BUNNY_TIMEOUT_SECONDS='90', FX_MAX_AGENT_STEPS='6') with (job / 'output.json').open('wb') as stdout, (job / 'stderr.log').open('wb') as stderr: result = subprocess.run([str(wrapper), '--no-additional-dirs', 'ask', '--json', '--no-save', '--no-color'], input=prompt.encode(), stdout=stdout, stderr=stderr, env=env, cwd=ROOT) usage = None summary = '' try: data = json.loads((job / 'output.json').read_text()) usage = data.get('usage') summary = data.get('final_output') or data.get('output') or '' except (ValueError, AttributeError): summary = 'No parseable response. Inspect stderr.log and output.json.' (job / 'summary.txt').write_text(summary if isinstance(summary, str) else json.dumps(summary)) (job / 'metadata.json').write_text(json.dumps(dict( exit_code=result.returncode, prompt_bytes=len(prompt.encode()), reported_usage=usage, note='Usage is provider-reported, may be incomplete, and is not a hard token cap.', timeout_seconds=90, max_agent_steps=6), indent=2)+'\n') print(f'Bunny logs: {job}') print(''.join((job / 'summary.txt').read_text().splitlines(keepends=True)[-100:])) return result.returncode
if __name__ == '__main__': raise SystemExit(main())123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169{ "kind": "real_data_baselines", "seed": 42, "split": "60/20/20 stratified", "metric": "roc_auc", "source_sha256": "28a06cd9c7078da72f3dd951c8b05845a026a045071d015dcad5efb234c7bdd3", "datasets": { "adult": { "rows": 48842, "sha256": "cacdc745358d0b11edfb5625cc041a0cdb2c12550a55e52593abc32c64441d59", "results": { "prior": { "val_auc": 0.5, "test_auc": 0.5, "fit_s": 0.01 }, "logreg": { "val_auc": 0.907, "test_auc": 0.9066, "fit_s": 1.49 }, "rf": { "val_auc": 0.9002, "test_auc": 0.9034, "fit_s": 3.16 }, "hgb": { "val_auc": 0.9283, "test_auc": 0.9272, "fit_s": 2.24 }, "mlp": { "val_auc": 0.9113, "test_auc": 0.9083, "fit_s": 8.27 } }, "selected_by_val": "hgb" }, "credit-g": { "rows": 1000, "sha256": "48b757fe48bd0b5c5ce2dbc84fabe20554bea43ce5b7157c6b5dbe8089107c0e", "results": { "prior": { "val_auc": 0.5, "test_auc": 0.5, "fit_s": 0.0 }, "logreg": { "val_auc": 0.8221, "test_auc": 0.7942, "fit_s": 0.09 }, "rf": { "val_auc": 0.7961, "test_auc": 0.7958, "fit_s": 0.32 }, "hgb": { "val_auc": 0.7806, "test_auc": 0.7423, "fit_s": 0.74 }, "mlp": { "val_auc": 0.7986, "test_auc": 0.7777, "fit_s": 0.2 } }, "selected_by_val": "logreg" }, "bank-marketing": { "rows": 45211, "sha256": "2afe41dfb060eb46aeecb5c105085b1c9d5b0c522bba9185063d3a879d6fc5ba", "results": { "prior": { "val_auc": 0.5, "test_auc": 0.5, "fit_s": 0.01 }, "logreg": { "val_auc": 0.9047, "test_auc": 0.9101, "fit_s": 0.77 }, "rf": { "val_auc": 0.9268, "test_auc": 0.9267, "fit_s": 2.71 }, "hgb": { "val_auc": 0.9338, "test_auc": 0.9375, "fit_s": 1.52 }, "mlp": { "val_auc": 0.9253, "test_auc": 0.929, "fit_s": 7.08 } }, "selected_by_val": "hgb" }, "phoneme": { "rows": 5404, "sha256": "986b259a8a108905122b32640c6241f2616fd3078c789c0e606930ebb48a5e40", "results": { "prior": { "val_auc": 0.5, "test_auc": 0.5, "fit_s": 0.0 }, "logreg": { "val_auc": 0.8013, "test_auc": 0.8095, "fit_s": 0.02 }, "rf": { "val_auc": 0.9497, "test_auc": 0.9554, "fit_s": 0.51 }, "hgb": { "val_auc": 0.9422, "test_auc": 0.9489, "fit_s": 0.71 }, "mlp": { "val_auc": 0.8776, "test_auc": 0.888, "fit_s": 0.59 } }, "selected_by_val": "rf" }, "diabetes": { "rows": 768, "sha256": "4790da1f2df7137251f2076f8702565aa69046c26452728ed8f07cf44d466d9b", "results": { "prior": { "val_auc": 0.5, "test_auc": 0.5, "fit_s": 0.0 }, "logreg": { "val_auc": 0.8463, "test_auc": 0.8031, "fit_s": 0.05 }, "rf": { "val_auc": 0.8084, "test_auc": 0.7657, "fit_s": 0.27 }, "hgb": { "val_auc": 0.8126, "test_auc": 0.7334, "fit_s": 0.39 }, "mlp": { "val_auc": 0.7233, "test_auc": 0.7571, "fit_s": 0.08 } }, "selected_by_val": "logreg" } }}1234567891011121314{ "kind": "synthetic_smoke_only", "seed": 42, "device": "cpu", "parameters": 577, "train_rows": 384, "validation_rows": 128, "initial_loss": 0.6864046454429626, "final_loss": 0.04011068865656853, "validation_accuracy": 0.921875, "elapsed_seconds": 1.5753, "torch_version": "2.10.0+cpu", "source_sha256": "8f21c7d1778a77dfa47b772b1488d8791df9b6b8a3e49ba6ae4429479c9a844e"}1234567891011121314151617181920212223242526272829303132333435363738394041424344{ "kind": "tuned_ensemble", "seed": 42, "metric": "roc_auc", "trials": 16, "source_sha256": "43fb693e0248c9210f496bb4e592ab35756c835eb2db93d259efdc1b76200d08", "datasets": { "adult": { "val_auc": 0.9296, "test_auc": 0.929, "ensemble": true, "best_single_kind": "xgb", "members": [ { "kind": "xgb", "params": { "learning_rate": 0.057981034777209596, "n_estimators": 584, "max_depth": 4 } }, { "kind": "xgb", "params": { "learning_rate": 0.09491392939374098, "n_estimators": 320, "max_depth": 4 } }, { "kind": "lgbm", "params": { "learning_rate": 0.035153719464910554, "n_estimators": 437, "num_leaves": 32 } } ], "artifact_bytes": 1017649, "artifact_sha256": "c57ccbdbc6b9854c1118eaeccebfbe8d8f90444a7a678f3272d2fbcf81c19076", "search_s": 206.2 } }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950{ "kind": "tuned_ensemble", "seed": 42, "metric": "roc_auc", "trials": 16, "source_sha256": "43fb693e0248c9210f496bb4e592ab35756c835eb2db93d259efdc1b76200d08", "datasets": { "bank-marketing": { "val_auc": 0.9357, "test_auc": 0.9386, "ensemble": true, "best_single_kind": "hgb", "members": [ { "kind": "hgb", "params": { "learning_rate": 0.03850363389390532, "max_iter": 350, "max_leaf_nodes": 28, "min_samples_leaf": 15, "l2_regularization": 0.37623611419432557, "max_features": 0.911380806635415 } }, { "kind": "hgb", "params": { "learning_rate": 0.03770843066456067, "max_iter": 563, "max_leaf_nodes": 33, "min_samples_leaf": 17, "l2_regularization": 0.1653252347575385, "max_features": 0.5319086280520877 } }, { "kind": "lgbm", "params": { "learning_rate": 0.035153719464910554, "n_estimators": 437, "num_leaves": 32 } } ], "artifact_bytes": 2062973, "artifact_sha256": "5a31f5eb6b4c6fc1f44d72ae0f804554bc62e35cf1ac7a979525001890503c18", "search_s": 129.5 } }}12345678910111213141516171819202122232425262728293031323334353637383940{ "kind": "tuned_ensemble", "seed": 42, "metric": "roc_auc", "trials": 16, "source_sha256": "43fb693e0248c9210f496bb4e592ab35756c835eb2db93d259efdc1b76200d08", "datasets": { "credit-g": { "val_auc": 0.8325, "test_auc": 0.7894, "ensemble": true, "best_single_kind": "logreg", "members": [ { "kind": "logreg", "params": { "C": 0.1 } }, { "kind": "logreg", "params": { "C": 1.0 } }, { "kind": "xgb", "params": { "learning_rate": 0.07046752877748709, "n_estimators": 330, "max_depth": 3 } } ], "artifact_bytes": 75788, "artifact_sha256": "64a01b461750a3bea41f4752977186dc5be4a0615d0c84b08b8e0b2751115e2f", "search_s": 24.1 } }}123456789101112131415161718192021222324252627282930313233343536{ "kind": "tuned_ensemble", "seed": 42, "metric": "roc_auc", "trials": 16, "source_sha256": "43fb693e0248c9210f496bb4e592ab35756c835eb2db93d259efdc1b76200d08", "datasets": { "diabetes": { "val_auc": 0.8528, "test_auc": 0.8001, "ensemble": true, "best_single_kind": "logreg", "members": [ { "kind": "logreg", "params": { "C": 1.0 } }, { "kind": "logreg", "params": { "C": 0.1 } }, { "kind": "et", "params": {} } ], "artifact_bytes": 1085047, "artifact_sha256": "50b5ecc4afc5e291dc45c7ce504a40fe2d5f735d3c86157a6c10a95407a9691f", "search_s": 14.8 } }}123456789101112131415161718192021222324{ "kind": "tuned_ensemble", "seed": 42, "metric": "roc_auc", "trials": 16, "source_sha256": "43fb693e0248c9210f496bb4e592ab35756c835eb2db93d259efdc1b76200d08", "datasets": { "phoneme": { "val_auc": 0.9523, "test_auc": 0.9546, "ensemble": false, "best_single_kind": "et", "members": [ { "kind": "et", "params": {} } ], "artifact_bytes": 5496319, "artifact_sha256": "e37ac3db2ba7bd9839833d8e0ac8a0a537467ddcf58b098d6550af47485fd683", "search_s": 39.4 } }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151{ "kind": "tuned_ensemble", "seed": 42, "metric": "roc_auc", "trials": 16, "source_sha256": "cf0c3d1191b0d15d1425aacb6e663f7e06abf721c2f01756cd653b2857dc0dd5", "datasets": { "adult": { "val_auc": 0.929, "test_auc": 0.9282, "ensemble": true, "members": [ { "kind": "hgb", "params": { "learning_rate": 0.03850363389390532, "max_iter": 350, "max_leaf_nodes": 28, "min_samples_leaf": 15, "l2_regularization": 0.37623611419432557, "max_features": 0.911380806635415 } }, { "kind": "hgb", "params": { "learning_rate": 0.03770843066456067, "max_iter": 563, "max_leaf_nodes": 33, "min_samples_leaf": 17, "l2_regularization": 0.1653252347575385, "max_features": 0.5319086280520877 } }, { "kind": "hgb", "params": { "learning_rate": 0.026519966160905902, "max_iter": 441, "max_leaf_nodes": 58, "min_samples_leaf": 25, "l2_regularization": 0.07554804756926672, "max_features": 0.5947356795421428 } } ], "artifact_bytes": 2639714, "artifact_sha256": "a28557fc9992cefa1eaaf2308964baa93b1c7e78f266c1a349fd64cdb1b246a7", "search_s": 154.7 }, "credit-g": { "val_auc": 0.8294, "test_auc": 0.7986, "ensemble": false, "members": [ { "kind": "logreg", "params": { "C": 0.1 } } ], "artifact_bytes": 3369, "artifact_sha256": "240366785f1e95fa3749b741747be6d4bb258d5be362e03cc5dec768b10d0496", "search_s": 20.6 }, "bank-marketing": { "val_auc": 0.9354, "test_auc": 0.9384, "ensemble": true, "members": [ { "kind": "hgb", "params": { "learning_rate": 0.03850363389390532, "max_iter": 350, "max_leaf_nodes": 28, "min_samples_leaf": 15, "l2_regularization": 0.37623611419432557, "max_features": 0.911380806635415 } }, { "kind": "hgb", "params": { "learning_rate": 0.03770843066456067, "max_iter": 563, "max_leaf_nodes": 33, "min_samples_leaf": 17, "l2_regularization": 0.1653252347575385, "max_features": 0.5319086280520877 } }, { "kind": "hgb", "params": { "learning_rate": 0.026519966160905902, "max_iter": 441, "max_leaf_nodes": 58, "min_samples_leaf": 25, "l2_regularization": 0.07554804756926672, "max_features": 0.5947356795421428 } } ], "artifact_bytes": 2670481, "artifact_sha256": "ec72f430d51f216a15d3a611e6ff1ed279ecc022759160354cb821a6077f29ea", "search_s": 101.4 }, "phoneme": { "val_auc": 0.9523, "test_auc": 0.9546, "ensemble": false, "members": [ { "kind": "et", "params": {} } ], "artifact_bytes": 5496319, "artifact_sha256": "e37ac3db2ba7bd9839833d8e0ac8a0a537467ddcf58b098d6550af47485fd683", "search_s": 35.2 }, "diabetes": { "val_auc": 0.8528, "test_auc": 0.8001, "ensemble": true, "members": [ { "kind": "logreg", "params": { "C": 1.0 } }, { "kind": "logreg", "params": { "C": 0.1 } }, { "kind": "et", "params": {} } ], "artifact_bytes": 1085047, "artifact_sha256": "50b5ecc4afc5e291dc45c7ce504a40fe2d5f735d3c86157a6c10a95407a9691f", "search_s": 16.5 } }}1234567891011121314151617import json, hashlib, sysfrom pathlib import Pathfrom sklearn.datasets import fetch_openmlOUT = Path('/nvme0n1-disk/cache/foundry/tabular')OUT.mkdir(parents=True, exist_ok=True)SETS = {'adult': 1590, 'credit-g': 31, 'bank-marketing': 1461, 'phoneme': 1489, 'diabetes': 37}meta = {}for name, did in SETS.items(): b = fetch_openml(data_id=did, as_frame=True, parser='auto', data_home=str(OUT / 'openml')) df = b.frame p = OUT / f'{name}.parquet' df.to_parquet(p) meta[name] = dict(openml_id=did, rows=len(df), cols=df.shape[1], target=b.target.name, sha256=hashlib.sha256(p.read_bytes()).hexdigest(), license=b.details.get('licence'), version=b.details.get('version')) print(name, meta[name], flush=True)(OUT / 'manifest.json').write_text(json.dumps(meta, indent=2))123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475import argparse, hashlib, json, timefrom pathlib import Pathimport numpy as np, pandas as pdfrom sklearn.compose import ColumnTransformerfrom sklearn.dummy import DummyClassifierfrom sklearn.ensemble import HistGradientBoostingClassifier, RandomForestClassifierfrom sklearn.linear_model import LogisticRegressionfrom sklearn.metrics import roc_auc_scorefrom sklearn.model_selection import train_test_splitfrom sklearn.neural_network import MLPClassifierfrom sklearn.pipeline import make_pipelinefrom sklearn.preprocessing import OneHotEncoder, StandardScaler
DATA = Path('/nvme0n1-disk/cache/foundry/tabular')SEED = 42
def load(name, target): df = pd.read_parquet(DATA / f'{name}.parquet').dropna(subset=[target]) y = df[target] y = (y == sorted(y.astype(str).unique())[-1]).astype(int).to_numpy() if y.nunique() == 2 else None X = df.drop(columns=[target]) return X, y
def prep(X): cat = [c for c in X.columns if X[c].dtype.name in ('category', 'object')] num = [c for c in X.columns if c not in cat] return ColumnTransformer([ ('n', make_pipeline(__import__('sklearn.impute', fromlist=['x']).SimpleImputer(strategy='median'), StandardScaler()), num), ('c', make_pipeline(__import__('sklearn.impute', fromlist=['x']).SimpleImputer(strategy='most_frequent'), OneHotEncoder(handle_unknown='ignore', min_frequency=5, sparse_output=False)), cat)])
def zoo(X): return { 'prior': lambda: DummyClassifier(strategy='prior'), 'logreg': lambda: make_pipeline(prep(X), LogisticRegression(max_iter=300)), 'rf': lambda: make_pipeline(prep(X), RandomForestClassifier(100, n_jobs=2, random_state=SEED)), 'hgb': lambda: make_pipeline(prep(X), HistGradientBoostingClassifier(max_iter=200, learning_rate=0.1, random_state=SEED)), 'mlp': lambda: make_pipeline(prep(X), MLPClassifier((128, 64), early_stopping=True, max_iter=60, random_state=SEED)), }
def main(): ap = argparse.ArgumentParser() ap.add_argument('--output', type=Path, required=True) a = ap.parse_args() manifest = json.loads((DATA / 'manifest.json').read_text()) out = dict(kind='real_data_baselines', seed=SEED, split='60/20/20 stratified', metric='roc_auc', source_sha256=hashlib.sha256(Path(__file__).read_bytes()).hexdigest(), datasets={}) for name, m in manifest.items(): X, y = load(name, m['target']) if y is None: continue idx = np.arange(len(y)) tr, rest = train_test_split(idx, test_size=0.4, stratify=y, random_state=SEED) va, te = train_test_split(rest, test_size=0.5, stratify=y[rest], random_state=SEED) res = {} for k, mk in zoo(X).items(): t = time.monotonic() mdl = mk().fit(X.iloc[tr], y[tr]) fit = time.monotonic() - t p = lambda i: mdl.predict_proba(X.iloc[i])[:, 1] res[k] = dict(val_auc=round(roc_auc_score(y[va], p(va)), 4), test_auc=round(roc_auc_score(y[te], p(te)), 4), fit_s=round(fit, 2)) print(name, k, res[k], flush=True) best = max((k for k in res if k != 'prior'), key=lambda k: res[k]['val_auc']) out['datasets'][name] = dict(rows=len(y), sha256=m['sha256'], results=res, selected_by_val=best) a.output.parent.mkdir(parents=True, exist_ok=True) a.output.write_text(json.dumps(out, indent=2) + '\n')
if __name__ == '__main__': main()1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889import argparse, hashlib, json, timefrom pathlib import Pathimport joblib, numpy as npfrom sklearn.ensemble import HistGradientBoostingClassifier, ExtraTreesClassifierfrom sklearn.linear_model import LogisticRegressionfrom sklearn.metrics import roc_auc_scorefrom sklearn.model_selection import train_test_splitfrom sklearn.pipeline import make_pipelinefrom tabular_bench import DATA, SEED, load, prep
TRIALS = 16GB_TRIALS = 6
def gbdt(rng): from xgboost import XGBClassifier from lightgbm import LGBMClassifier for _ in range(GB_TRIALS): lr = float(10 ** rng.uniform(-2, -0.7)); n = int(rng.integers(150, 600)); d = int(rng.integers(3, 9)) yield 'xgb', dict(learning_rate=lr, n_estimators=n, max_depth=d), XGBClassifier( learning_rate=lr, n_estimators=n, max_depth=d, subsample=0.8, colsample_bytree=0.8, n_jobs=2, random_state=SEED, verbosity=0) yield 'lgbm', dict(learning_rate=lr, n_estimators=n, num_leaves=2 ** d), LGBMClassifier( learning_rate=lr, n_estimators=n, num_leaves=2 ** d, subsample=0.8, subsample_freq=1, colsample_bytree=0.8, n_jobs=2, random_state=SEED, verbose=-1)
def hgb(rng): return dict(learning_rate=float(10 ** rng.uniform(-2, -0.7)), max_iter=int(rng.integers(100, 600)), max_leaf_nodes=int(rng.integers(8, 64)), min_samples_leaf=int(rng.integers(5, 60)), l2_regularization=float(10 ** rng.uniform(-3, 1)), max_features=float(rng.uniform(0.5, 1.0)))
def main(): ap = argparse.ArgumentParser() ap.add_argument('--output', type=Path, required=True) ap.add_argument('--datasets', nargs='*') ap.add_argument('--gbdt', action='store_true') ap.add_argument('--artifacts', type=Path, required=True) a = ap.parse_args() man = json.loads((DATA / 'manifest.json').read_text()) out = dict(kind='tuned_ensemble', seed=SEED, metric='roc_auc', trials=TRIALS, source_sha256=hashlib.sha256(Path(__file__).read_bytes()).hexdigest(), datasets={}) a.artifacts.mkdir(parents=True, exist_ok=True) for name, m in man.items(): if a.datasets and name not in a.datasets: continue X, y = load(name, m['target']) if y is None: continue idx = np.arange(len(y)) tr, rest = train_test_split(idx, test_size=0.4, stratify=y, random_state=SEED) va, te = train_test_split(rest, test_size=0.5, stratify=y[rest], random_state=SEED) rng = np.random.default_rng(SEED) t0 = time.monotonic() cands = [] for i in range(TRIALS): p = hgb(rng) mdl = make_pipeline(prep(X), HistGradientBoostingClassifier(early_stopping=False, random_state=SEED, **p)).fit(X.iloc[tr], y[tr]) cands.append(('hgb', p, mdl, mdl.predict_proba(X.iloc[va])[:, 1])) for c in (0.1, 1.0): mdl = make_pipeline(prep(X), LogisticRegression(C=c, max_iter=500)).fit(X.iloc[tr], y[tr]) cands.append(('logreg', dict(C=c), mdl, mdl.predict_proba(X.iloc[va])[:, 1])) mdl = make_pipeline(prep(X), ExtraTreesClassifier(300, min_samples_leaf=2, n_jobs=2, random_state=SEED)).fit(X.iloc[tr], y[tr]) cands.append(('et', {}, mdl, mdl.predict_proba(X.iloc[va])[:, 1])) if a.gbdt: for kind, p, est in gbdt(np.random.default_rng(SEED + 1)): mdl = make_pipeline(prep(X), est).fit(X.iloc[tr], y[tr]) cands.append((kind, p, mdl, mdl.predict_proba(X.iloc[va])[:, 1])) aucs = [roc_auc_score(y[va], c[3]) for c in cands] order = np.argsort(aucs)[::-1] top = [cands[i] for i in order[:3]] ens_va = np.mean([c[3] for c in top], axis=0) ens_auc = roc_auc_score(y[va], ens_va) single = cands[order[0]] use_ens = ens_auc > aucs[order[0]] members = top if use_ens else [single] pred = lambda i: np.mean([c[2].predict_proba(X.iloc[i])[:, 1] for c in members], axis=0) path = a.artifacts / f'{name}.joblib' joblib.dump(dict(members=[c[2] for c in members], columns=list(X.columns)), path, compress=3) out['datasets'][name] = dict( val_auc=round(max(ens_auc, aucs[order[0]]), 4), test_auc=round(roc_auc_score(y[te], pred(te)), 4), ensemble=use_ens, best_single_kind=single[0], members=[dict(kind=c[0], params=c[1]) for c in members], artifact_bytes=path.stat().st_size, artifact_sha256=hashlib.sha256(path.read_bytes()).hexdigest(), search_s=round(time.monotonic() - t0, 1)) print(name, out['datasets'][name], flush=True) a.output.write_text(json.dumps(out, indent=2) + '\n')
if __name__ == '__main__': main().gitignoreAdded+10
README.mdAdded+53
artifacts/.gitkeepAdded
artifacts/adult.joblibAdded+3
artifacts/bank-marketing.joblibAdded+3
artifacts/credit-g.joblibAdded+3
artifacts/diabetes.joblibAdded+3
artifacts/phoneme.joblibAdded+3
cog/.cog/cog.lockAdded
cog/.cog/openapi_schema.jsonAdded+1
cog/.dockerignoreAdded+3
cog/DockerfileAdded+10
cog/models/adult.joblibAdded+3
cog/models/bank-marketing.joblibAdded+3
cog/models/credit-g.joblibAdded+3
cog/models/diabetes.joblibAdded+3
cog/models/phoneme.joblibAdded+3
cog/predict.pyAdded+29
cog/requirements.txtAdded+4
cog/server.pyAdded+53
cog/tests/test_predict.pyAdded+36
configs/.gitkeepAdded
configs/project.jsonAdded+20
prompts/.gitkeepAdded
prompts/implement.txtAdded+9
prompts/kernel.txtAdded+50
prompts/review.txtAdded+124
results/.gitkeepAdded
results/baselines.jsonAdded+169
results/smoke.jsonAdded+14
results/tuned-adult.jsonAdded+44
results/tuned-bank-marketing.jsonAdded+50
results/tuned-credit-g.jsonAdded+40
results/tuned-diabetes.jsonAdded+36
results/tuned-phoneme.jsonAdded+24
results/tuned.jsonAdded+151
src/.gitkeepAdded
tests/.gitkeepAdded
train/fetch_tabular.pyAdded+17
train/tabular_bench.pyAdded+75
train/tabular_tune.pyAdded+89