#!/usr/bin/env python """Smoke-test the rebuilt ABForge env. Verifies the critical imports + versions match the frozen spec, loads the base tokenizer/config, and (if --gpu) runs a tiny vLLM generate. Exit 0 only if all critical checks pass. python scripts/smoke_repro_env.py # CPU import + version check python scripts/smoke_repro_env.py --gpu # + vLLM load/generate (needs a GPU) NOTE: everything runs under `if __name__ == "__main__"` — vLLM spawns worker processes that re-import this module, and without the guard they'd re-execute the whole script. """ import sys, importlib EXPECT = { # critical pins from docs/env_abforge_vllm_frozen.txt "torch": "2.6.0", "vllm": "0.8.5.post1", "transformers": "4.52.1", "flash_attn": "2.8.3", "ray": "2.43.0", "xformers": "0.0.29.post2", } # Use the HF hub model — the scratch copy under models/Qwen3-8B is being evicted (config.json gone). BASE = "Qwen/Qwen3-8B" def main(): ok = True print("== imports / versions ==") for mod, want in EXPECT.items(): try: m = importlib.import_module(mod) got = getattr(m, "__version__", "?") mark = "OK " if str(got).startswith(want) else "DIFF" if mark == "DIFF": ok = False print(f" [{mark}] {mod:14s} got={got} want~={want}") except Exception as e: ok = False print(f" [ERR] {mod:14s} {type(e).__name__}: {str(e)[:90]}") print("== verl (bundled) ==") try: import verl print(f" [OK ] verl {getattr(verl,'__version__','?')}") except Exception as e: ok = False; print(f" [ERR] verl {type(e).__name__}: {str(e)[:90]}") print("== torch CUDA ==") try: import torch print(f" cuda_available={torch.cuda.is_available()} built_cuda={torch.version.cuda} " f"devices={torch.cuda.device_count() if torch.cuda.is_available() else 0}") except Exception as e: print(f" [ERR] {e}") print("== tokenizer/config load (base Qwen3-8B) ==") try: import os from transformers import AutoConfig, AutoTokenizer src = BASE if os.path.isdir(BASE) else "Qwen/Qwen3-8B" AutoConfig.from_pretrained(src) AutoTokenizer.from_pretrained(src) print(f" [OK ] loaded from {src}") except Exception as e: ok = False; print(f" [ERR] {type(e).__name__}: {str(e)[:120]}") if "--gpu" in sys.argv: try: import torch if torch.cuda.is_available(): print("== vLLM tiny generate ==") from vllm import LLM, SamplingParams llm = LLM(model="Qwen/Qwen3-8B", gpu_memory_utilization=0.85, max_model_len=2048, enforce_eager=True) out = llm.generate(["Hello, the ablation study"], SamplingParams(max_tokens=8)) print(" [OK ] generated:", repr(out[0].outputs[0].text[:60])) except Exception as e: ok = False; print(f" [ERR] vLLM generate {type(e).__name__}: {str(e)[:160]}") print("\nSMOKE_OK" if ok else "\nSMOKE_FAILED") sys.exit(0 if ok else 1) if __name__ == "__main__": main()