Spaces:
Running on Zero
Running on Zero
ZeroGPU: force cuda placement via env; use transformers 5.x dtype arg
Browse files37 unmodified lines383940414142434445464748495039 unmodified lines90919293949596979899878889909110010110210310410510610737 unmodified linesRENDER_DPI = 150 # PDF rasterization DPIMAX_SIDE = 2200 # cap the long side of a page (px)
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"# On ZeroGPU the GPU is not attached at import time, so torch.cuda.is_available()# is False here; the `spaces` package intercepts `.to("cuda")` at module scope and# streams the weights in on the first @spaces.GPU call. So trust the ZeroGPU env# var, not is_available(), when deciding to place weights on cuda.ON_ZEROGPU = bool(os.environ.get("SPACES_ZERO_GPU"))USE_CUDA = ON_ZEROGPU or torch.cuda.is_available()DEVICE = "cuda" if USE_CUDA else "cpu"
# Prompt per PaddleOCR-VL task.PROMPTS = {39 unmodified lines from transformers import AutoModelForCausalLM, AutoProcessor
print("[vlm] loading", MODEL_PATH, flush=True) try: model = AutoModelForCausalLM.from_pretrained( MODEL_PATH, trust_remote_code=True, dtype=torch.bfloat16, # transformers 5.x name (was torch_dtype) ).eval() except TypeError: model = AutoModelForCausalLM.from_pretrained( MODEL_PATH, trust_remote_code=True, torch_dtype=torch.bfloat16, ).eval() model = AutoModelForCausalLM.from_pretrained( MODEL_PATH, trust_remote_code=True, torch_dtype=torch.bfloat16, ).eval() if DEVICE == "cuda": model = model.to("cuda") processor = AutoProcessor.from_pretrained(MODEL_PATH, trust_remote_code=True)app.py+19-6