Spaces:
Runtime error
Runtime error
Update app.py
Browse files1223456789101112131415161718192092210111213141516171819202122232425262728293031323334357 unmodified lines4344454647484950517 unmodified lines596061496263646566675455565758596061686970717273747576777879import gradio as grfrom unsloth import FastLanguageModelfrom transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfigimport torchimport time
# ----------------------------# 🚀 Load Model (cached)# ----------------------------@gr.cachedef load_model(): max_seq_length = 1024 model, tokenizer = FastLanguageModel.from_pretrained( model_name="umarfarzan/my-finetuned-model2-lora", max_seq_length=max_seq_length, dtype=None, load_in_4bit=True ) FastLanguageModel.for_inference(model) return model, tokenizer
print("Loading model...")model, tokenizer = load_model()
model_name = "umarfarzan/my-finetuned-model2-lora"max_seq_length = 1024
# Configure quantization for efficient inferencebnb_config = BitsAndBytesConfig( load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_use_double_quant=True, bnb_4bit_compute_dtype=torch.bfloat16)
# Load tokenizertokenizer = AutoTokenizer.from_pretrained(model_name)
# Load model with 4-bit quantizationmodel = AutoModelForCausalLM.from_pretrained( model_name, quantization_config=bnb_config, device_map="auto", trust_remote_code=True)
print("✅ Model loaded successfully!")
# ----------------------------7 unmodified lines): """Generate a training program based on user instruction""" if not instruction.strip(): return "⚠️ Please enter a training program description.", "" # Build prompt in Alpaca format prompt_text = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
7 unmodified lines""" # Tokenize inputs = tokenizer([prompt_text], return_tensors="pt").to("cuda") inputs = tokenizer([prompt_text], return_tensors="pt").to(model.device) # Generate with progress start_time = time.time() with torch.inference_mode(): outputs = model.generate( **inputs, max_new_tokens=max_tokens, temperature=temperature, top_p=top_p, do_sample=True, use_cache=True ) outputs = model.generate( **inputs, max_new_tokens=max_tokens, temperature=temperature, top_p=top_p, do_sample=True, use_cache=True, pad_token_id=tokenizer.pad_token_id or tokenizer.eos_token_id ) generation_time = time.time() - start_time app.py+38-23