Spaces:
Running on Zero
Running on Zero
File size: 1,761 Bytes
64494c5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# Set environment variables BEFORE importing torch
import os
os.environ["TORCHINDUCTOR_DISABLE"] = "1"
os.environ["TORCH_COMPILE_DISABLE"] = "1"
# Optional: force a specific GPU (uncomment if needed)
# os.environ["CUDA_VISIBLE_DEVICES"] = "0"
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch
# In-code disables for torch.compile and inductor/triton
torch._dynamo.config.suppress_errors = True
#torch._dynamo.config.enable = False
torch.set_float32_matmul_precision('high')
#base = "google/gemma-3-1b-it"
#adapter = "Agent/Gemma3_1B_weights"
base = "Qwen/Qwen2.5-3B-Instruct"
adapter = "Agent/Qwen2.5_3b_weights"
model = AutoModelForCausalLM.from_pretrained(
base,
dtype="auto",
device_map=None,
load_in_8bit=True,
low_cpu_mem_usage=True,
local_files_only=False # Set to False to force download if needed
#trust_remote_code=True
)
model = PeftModel.from_pretrained(model, adapter, local_files_only=True)
model = model.to("cuda") # Move model to GPU
tokenizer = AutoTokenizer.from_pretrained(base)
prompt = "Schema: employee(emp_no, birth_date, first_name, last_name, gender, hire_date),\n" \
"department(dept_no, dept_name),\n" \
"dept_emp(emp_no, dept_no, from_date, to_date),\n" \
"salary(emp_no, salary, from_date, to_date),\n" \
"Write PostgreSQL query for highest and lowest salary across all departments. Do not include any explanation."
inputs = tokenizer(prompt, return_tensors="pt")
# Move all input tensors to CUDA
inputs = {k: v.to("cuda") for k, v in inputs.items()}
output = model.generate(**inputs, max_new_tokens=1028)
print(tokenizer.decode(output[0], skip_special_tokens=True)) |