Views
No views yet
Important: load the adapter againstQwen/Qwen3-4Bas shown below. Thebase_model_name_or_pathinadapter_config.jsonpoints at a 4-bit Unsloth variant (a training-time artifact); loading against that base is not the configuration this model was evaluated in and will fail on machines withoutbitsandbytes.
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5ADAPTER = "Hookem22/qwen3-4b-subtitle-es-v3-lora"
6
7tok = AutoTokenizer.from_pretrained(ADAPTER)
8base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-4B", dtype=torch.float16)
9model = PeftModel.from_pretrained(base, ADAPTER).eval()
10device = ("cuda" if torch.cuda.is_available()
11 else "mps" if torch.backends.mps.is_available() else "cpu")
12model.to(device)
13
14SYSTEM = ("Translate these subtitles from English to Spanish. Output exactly one "
15 "Spanish line per source line, and keep every line to 42 characters or fewer.")
16
17english_scene = """\
18I need the report by Friday.
19That's not enough time.
20Then ask Marcus for help.""" # normally 12-28 lines
21
22messages = [{"role": "system", "content": SYSTEM},
23 {"role": "user", "content": english_scene}]
24prompt = tok.apply_chat_template(messages, tokenize=False,
25 add_generation_prompt=True,
26 enable_thinking=False)
27inputs = tok(prompt, return_tensors="pt").to(device)
28with torch.no_grad():
29 out = model.generate(**inputs, max_new_tokens=1024, do_sample=False,
30 pad_token_id=tok.eos_token_id)
31print(tok.decode(out[0][inputs["input_ids"].shape[1]:],
32 skip_special_tokens=True).strip())wc -L ≤ 42)