Spaces:
Running on Zero
Running on Zero
ZeroGPU: force cuda placement via env; use transformers 5.x dtype arg
Browse files37 unmodified lines3839404142434439 unmodified lines848586878889909192939437 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"# Prompt per PaddleOCR-VL task.PROMPTS = {39 unmodified linesfrom transformers import AutoModelForCausalLM, AutoProcessorprint("[vlm] loading", MODEL_PATH, flush=True)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)37 unmodified lines3839404142434445464748495039 unmodified lines9091929394959697989910010110210310410510610737 unmodified linesRENDER_DPI = 150 # PDF rasterization DPIMAX_SIDE = 2200 # cap the long side of a page (px)# 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 linesfrom transformers import AutoModelForCausalLM, AutoProcessorprint("[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()if DEVICE == "cuda":model = model.to("cuda")processor = AutoProcessor.from_pretrained(MODEL_PATH, trust_remote_code=True)
app.py+19-6