Spaces:
Paused
Paused
Update app/main.py
Browse files71 unmodified lines727374757675767778795 unmodified lines85868788889089909192939495969697989910071 unmodified lines if current_model == model_name and generator is not None: return
device = 0 if torch.cuda.is_available() else -1 torch_dtype = torch.float16 if device == 0 else torch.float32 device = torch.device("cuda" if torch.cuda.is_available() else "cpu") torch_dtype = torch.float16 if device.type == "cuda" else torch.float32
logger.info(f"Loading model {model_name} on device {device}")
5 unmodified lines model = AutoModelForCausalLM.from_pretrained( model_name, cache_dir=cache_dir, device_map="auto" if device == 0 else None, torch_dtype=torch_dtype ) ).to(device)
# Create pipeline with proper device index pipeline_device = 0 if device.type == "cuda" else -1 generator = pipeline( task="text-generation", model=model, tokenizer=tokenizer, device=device, device=pipeline_device, return_full_text=False )
app/main.py+6-5