Views
No views yet

Note on Qwen3 thinking mode: Qwen3 supports a nativeenable_thinkingtoggle in its chat template that wraps reasoning in<think>...</think>blocks. This model was tuned to produce reasoning through its own structured prompt format (not Qwen3's native thinking blocks), so if you build prompts viatokenizer.apply_chat_template(...), setenable_thinking=Falseto avoid mixing the two reasoning styles. The example below uses a raw instruction-style prompt and is unaffected either way.
pip install torch transformers bitsandbytes accelerate1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3
4MODEL_NAME = "ahammad115566/qwen-smeft"
5RESPONSE_PREFIX = "\n### Response:\n"
6
7# 4-bit quantisation
8bnb_config = BitsAndBytesConfig(
9 load_in_4bit=True,
10 bnb_4bit_quant_type="nf4",
11 bnb_4bit_compute_dtype=torch.bfloat16,
12 bnb_4bit_use_double_quant=True,
13)
14
15# Load model and tokenizer
16tokenizer = AutoTokenizer.from_pretrained(
17 MODEL_NAME,
18 trust_remote_code=True,
19)
20
21model = AutoModelForCausalLM.from_pretrained(
22 MODEL_NAME,
23 quantization_config=bnb_config,
24 device_map={"": 0},
25 trust_remote_code=True,
26)
27
28model.eval()
29
30if tokenizer.pad_token is None:
31 tokenizer.pad_token = tokenizer.eos_token
32
33
34# ================= Inference ================
35
36def build_prompt(instruction: str) -> str:
37 """Construct the prompt using the format used during fine-tuning."""
38 return f"\n### Instruction:\n{instruction}\n{RESPONSE_PREFIX}"
39
40
41@torch.inference_mode()
42def ask(instruction: str) -> str:
43 """Generate a response to an SMEFT-related instruction."""
44 prompt = build_prompt(instruction)
45
46 inputs = tokenizer(
47 prompt,
48 return_tensors="pt",
49 add_special_tokens=True,
50 ).to(model.device)
51
52 output_ids = model.generate(
53 **inputs,
54 max_new_tokens=2048,
55 do_sample=False,
56 repetition_penalty=1.1,
57 eos_token_id=tokenizer.eos_token_id,
58 pad_token_id=tokenizer.pad_token_id,
59 )
60
61 new_tokens = output_ids[0][inputs["input_ids"].shape[-1]:]
62
63 return tokenizer.decode(
64 new_tokens,
65 skip_special_tokens=True,
66 ).strip()
67
68
69# Example
70instruction = """
71Which SMEFT operators modify EWPO?
72"""
73
74response = ask(instruction)
75print(response)| Parameter | Value |
|---|---|
| Base Model | Qwen3 |
| Fine-tuning Method | LoRA (merged) |
| Inference Quantization | 4-bit NF4 (bitsandbytes) |
| Domain | Standard Model Effective Field Theory (SMEFT) |
| Training Corpus | Curated SMEFT and HEP preprints |
| Task Format | Instruction-following scientific QA |
1@article{Hammad:2026bvw,
2 author = "Hammad, Ahmed and Sanz, Veronica",
3 title = "{Language-Guided Hypotheses Generation for Sparse SMEFT Analyses}",
4 eprint = "2608.04100",
5 archivePrefix = "arXiv",
6 primaryClass = "hep-ph",
7 month = "8",
8 year = "2026"
9}