Views
No views yet
1mkdir -p ~/hf_cache
2export HF_HOME=$HOME/hf_cache
3export HF_HUB_CACHE=$HOME/hf_cache/hub
4
5python3 - <<'PY'
6import torch
7from transformers import AutoTokenizer, AutoModelForCausalLM
8from peft import PeftModel
9
10BASE = "Qwen/Qwen3-4B-Instruct-2507"
11LORA = "ikep2001/llm25-adv-qwen3-4b-lora"
12
13tok = AutoTokenizer.from_pretrained(BASE, trust_remote_code=True)
14base = AutoModelForCausalLM.from_pretrained(
15 BASE, torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=True
16)
17model = PeftModel.from_pretrained(base, LORA).eval()
18
19prompt = "次のJSONを正規化して。余計なフィールドは消して。\n\n{\"a\":1,\"b\":2,\"extra\":3}\n"
20inputs = tok(prompt, return_tensors="pt").to(model.device)
21out = model.generate(**inputs, max_new_tokens=128, do_sample=False)
22print(tok.decode(out[0], skip_special_tokens=True))
23PY