Views
No views yet
tokenizer_config.json.
We completely overrode the default chat_template using Jinja2 to act as an "Absolute Defense Shield" and a "Dynamic Heuristics Injector".MySQL or SQL is detected in the prompt, the model is forced into a DB Agent persona with the following injected rules:Action: Operation to execute DESCRIBE table_name; and check the correct schema before retrying."household or Interact with a is detected, the model is forced into an ALFWorld Agent persona:THOUGHT:/ACTION:) and strictly enforces the stable Think:/Act: format.Nothing happened), analyze why in your Think: step and choose a DIFFERENT action."q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_projchat_template, you must use this tokenizer to see the performance gains.1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3import torch
4
5base_model_id = "Qwen/Qwen3-4B-Instruct-2507"
6adapter_id = "your_huggingface_id/your_model_name" # Change this to your actual repo ID
7
8# 1. Load the customized tokenizer (CRITICAL)
9tokenizer = AutoTokenizer.from_pretrained(adapter_id)
10
11# 2. Load Base Model & Attach LoRA
12model = AutoModelForCausalLM.from_pretrained(
13 base_model_id,
14 torch_dtype=torch.bfloat16,
15 device_map="auto",
16)
17model = PeftModel.from_pretrained(model, adapter_id)
18
19# 3. Standard Inference (The Jinja2 template handles the routing automatically)
20messages = [
21 {"role": "user", "content": "You are a specialized MySQL database agent..."}
22]
23inputs = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to("cuda")
24outputs = model.generate(**inputs, max_new_tokens=512)
25print(tokenizer.decode(outputs[0], skip_special_tokens=True))