Views
No views yet
BSC-LT/salamandra-7b-instructbfloat16transformers, peft, trl) with severe optimizations tailored for mixed hardware environments (e.g., RTX 4070 Ti 12GB VRAM + 32GB System RAM).BitsAndBytes with double_quant=True and computations in bfloat16.paged_adamw_8bit optimizer.q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_projdevice_map="cpu").merge_and_unload()), meaning you do not need to load the adapter independently. It is ready for inference.transformers library. Since it is already merged, it loads like any standard causal language model.1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4# Load the model and tokenizer
5model_id = "DavidCaraballoBulnes/ResidentEvil-QA"
6
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8model = AutoModelForCausalLM.from_pretrained(
9 model_id,
10 torch_dtype=torch.bfloat16,
11 device_map="auto",
12 trust_remote_code=True
13)
14
15# 1. System Prompt: Strict guardrails to prevent AI hallucinations and enforce canon
16system_prompt = (
17 "Eres un archivero experto en la historia, los personajes y los virus "
18 "del universo oficial de los videojuegos de Resident Evil (creado por Capcom). "
19 "Tu misión es dar respuestas precisas, directas y basadas estrictamente en el canon. "
20 "Reglas críticas: No inventes nombres de criaturas, no mezcles novelas con los juegos, "
21 "y bajo ninguna circunstancia alucines información. Si no conoces la respuesta exacta, "
22 "debes responder: 'No tengo información verificada sobre esto en los archivos de Umbrella'."
23)
24
25# 2. Prepare the messages using the chat template
26messages = [
27 {"role": "system", "content": system_prompt},
28 {"role": "user", "content": "¿Quién es Oswell E. Spencer?"}
29]
30
31prompt = tokenizer.apply_chat_template(
32 messages,
33 tokenize=False,
34 add_generation_prompt=True
35)
36
37# Use model.device to ensure hardware agnosticism (works on CUDA, CPU, or MPS/Mac)
38inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
39
40# 3. Generate the response (Low temperature enforces factual accuracy)
41outputs = model.generate(
42 **inputs,
43 max_new_tokens=1024,
44 temperature=0.2,
45 top_p=0.9,
46 do_sample=True
47)
48
49# 4. Decode only the newly generated tokens
50response = tokenizer.decode(outputs[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True)
51print(response)