#!/usr/bin/env python3 """Claim 2 scaled proxy: base Qwen3-Coder-30B-A3B vs FullStack-Learn-LM-30B-A3B. Prompts each model with ONLY the app instruction; scores the generated code against HIDDEN requirements (frontend UI tasks, backend API tests, DB entities) with a deterministic requirement-coverage + structural heuristic. This is a PROXY (labeled toy): it is NOT the FullStack-Bench harness (no browser/DB tests, no 480B judge). It probes the direction of Claim 2 on the real released weights. Modes: --selftest score a stub codebase (no GPU / no vllm), print, exit --generate MODEL OUTFILE load MODEL with vLLM, generate for all prompts -> OUTFILE --run (default) generate for BASE + FT via subprocesses, score, write results, upload to the Hub, print summary """ import argparse, json, os, re, subprocess, sys, gc, time # Slim base image has no nvcc/CUDA toolkit, so avoid FlashInfer JIT paths. os.environ.setdefault("VLLM_ATTENTION_BACKEND", "FLASH_ATTN") os.environ.setdefault("VLLM_USE_FLASHINFER_SAMPLER", "0") BASE_MODEL = os.environ.get("BASE_MODEL", "Qwen/Qwen3-Coder-30B-A3B-Instruct") FT_MODEL = os.environ.get("FT_MODEL", "luzimu/FullStack-Learn-LM-30B-A3B") RESULT_REPO = os.environ.get("RESULT_REPO", "sandeepbh/fullstack-claim2-proxy") MAX_TOKENS = int(os.environ.get("MAX_TOKENS", "4096")) MAX_MODEL_LEN = int(os.environ.get("MAX_MODEL_LEN", "8192")) def prompts_path(): for p in (os.environ.get("PROMPTS"), "/work/prompts.jsonl", os.path.join(os.path.dirname(__file__), "prompts.jsonl")): if p and os.path.exists(p): return p raise FileNotFoundError("prompts.jsonl not found") def load_items(): return [json.loads(l) for l in open(prompts_path(), encoding="utf-8") if l.strip()] # ---------------- scoring (deterministic) ---------------- STOP = set("""the a an and or to of in for with on by is are be that this it as at from into using use user users system page pages data information test tests verify testing ensure check checks should when then display displays displaying show shows return returns returning correct correctly correct functionality feature features valid enter entering based all each its their such via able website web app application new using request response api endpoint send sending button click clicking view details detail list add create update delete remove select selecting different various can will has have""".split()) def toks(text): return set(t for t in re.split(r"[^a-zA-Z0-9]+", (text or "").lower()) if len(t) >= 4 and t not in STOP) def covered(req, hay): kw = toks(req) if not kw: return True hit = len(kw & hay) need = 2 if len(kw) >= 3 else 1 return hit >= need BACKEND_PAT = re.compile(r"@app\.route|@router\.(get|post|put|delete|patch)|app\.(get|post|put|delete|patch)\s*\(|router\.(get|post|put|delete|patch)|APIRouter|fastapi|from flask|express\(\)|urlpatterns|path\(|@(get|post|put|delete)\(|def \w+\([^)]*request", re.I) DB_PAT = re.compile(r"create table|db\.Model|models\.Model|mongoose\.Schema|new Schema|Column\(|sqlalchemy|sequelize|prisma|ForeignKey|primary key|db\.session|createConnection|sqlite3|psycopg2|pymongo|collection\(", re.I) FRONTEND_PAT = re.compile(r" {outfile}", flush=True) # ---------------- orchestration ---------------- def run(): items = load_items() gens = {} for tag, mid in (("base", BASE_MODEL), ("ft", FT_MODEL)): outf = f"/tmp/gen_{tag}.jsonl" print(f"[run] generating with {tag} = {mid}", flush=True) subprocess.run([sys.executable, os.path.abspath(__file__), "--generate", mid, outf], check=True) gens[tag] = {json.loads(l)["id"]: json.loads(l)["output"] for l in open(outf, encoding="utf-8") if l.strip()} per = {"base": [], "ft": []} for it in items: for tag in ("base", "ft"): per[tag].append(score_site(gens[tag].get(it["id"], ""), it)) summary = { "experiment": "FullStack-Agent Claim 2 scaled proxy (requirement-coverage; NOT FullStack-Bench)", "base_model": BASE_MODEL, "ft_model": FT_MODEL, "n_sites": len(items), "max_tokens": MAX_TOKENS, "base": aggregate(per["base"]), "ft": aggregate(per["ft"]), } for k in ("frontend_cov", "backend_cov", "db_cov", "overall_cov"): b, f = summary["base"][k], summary["ft"][k] summary.setdefault("delta_ft_minus_base", {})[k] = round((f - b), 4) if (b is not None and f is not None) else None os.makedirs("/tmp/out", exist_ok=True) json.dump(summary, open("/tmp/out/results.json", "w"), indent=2) json.dump({"base": per["base"], "ft": per["ft"]}, open("/tmp/out/per_site.json", "w"), indent=2) for tag in ("base", "ft"): if os.path.exists(f"/tmp/gen_{tag}.jsonl"): os.replace(f"/tmp/gen_{tag}.jsonl", f"/tmp/out/gen_{tag}.jsonl") # upload artifacts to the Hub (best-effort) try: from huggingface_hub import HfApi api = HfApi() api.create_repo(RESULT_REPO, repo_type="dataset", exist_ok=True) for fn in ("results.json", "per_site.json", "gen_base.jsonl", "gen_ft.jsonl"): p = f"/tmp/out/{fn}" if os.path.exists(p): api.upload_file(path_or_fileobj=p, path_in_repo=f"results/{fn}", repo_id=RESULT_REPO, repo_type="dataset") print(f"[run] uploaded artifacts to dataset {RESULT_REPO}/results/", flush=True) except Exception as e: print(f"[run] upload skipped: {e}", flush=True) print("===CLAIM2_PROXY_RESULT===", flush=True) print(json.dumps(summary, indent=2), flush=True) print("===END===", flush=True) def selftest(): stub_full = ("```python\nfrom flask import Flask, request, jsonify\napp = Flask(__name__)\n" "import sqlalchemy\nclass Stock(db.Model):\n Column(name)\n" "@app.route('/api/search')\ndef search(): return jsonify(stock information)\n```\n" "```html\n
" "\n```") stub_frontend_only = ("```html\n
Stock report
" "\n```") items = load_items() it = items[0] print("site:", it["id"], "| reqs fe/be/db =", len(it["frontend_reqs"]), len(it["backend_reqs"]), len(it["db_reqs"])) print("FULL-STACK stub score:", json.dumps(score_site(stub_full, it))) print("FRONTEND-ONLY stub score:", json.dumps(score_site(stub_frontend_only, it))) print("aggregate(full x3):", json.dumps(aggregate([score_site(stub_full, x) for x in items[:3]]))) print("SELFTEST OK") def main(): ap = argparse.ArgumentParser() ap.add_argument("--selftest", action="store_true") ap.add_argument("--generate", nargs=2, metavar=("MODEL", "OUTFILE")) ap.add_argument("--run", action="store_true") a = ap.parse_args() if a.selftest: selftest() elif a.generate: generate(a.generate[0], a.generate[1]) else: run() if __name__ == "__main__": main()