Views
No views yet
Qwen/Qwen3.5-2B language model, specifically engineered to understand, analyze, and summarize electronic hardware circuits. Leveraging Low-Rank Adaptation (LoRA), this model was trained on a unique, synthetically generated dataset of 1000 diverse hardware circuits, encompassing both Power Electronics and High-Speed Design domains. Each circuit in the dataset is enriched with detailed specifications, Bill of Materials (BOM), Altium netlists, and LTspice netlists.transformers library and provide a structured prompt. The prompt should mirror the format used during training, incorporating all available circuit details and netlists.1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3from peft import PeftModel
4
5# Define the base model and fine-tuned adapter ID
6base_model_name = "Qwen/Qwen3.5-2B"
7lora_model_id = "omarsamehsyam/Xentrix"
8
9# Load the tokenizer
10tokenizer = AutoTokenizer.from_pretrained(base_model_name, trust_remote_code=True, padding_side="left")
11if tokenizer.pad_token is None:
12 tokenizer.pad_token = tokenizer.eos_token
13
14# Load the base model in 4-bit quantization for efficiency
15base_model = AutoModelForCausalLM.from_pretrained(
16 base_model_name,
17 trust_remote_code=True,
18 torch_dtype=torch.bfloat16,
19 device_map="auto",
20 low_cpu_mem_usage=True
21)
22
23# Load the fine-tuned LoRA adapter onto the base model
24model = PeftModel.from_pretrained(base_model, lora_model_id)
25model.eval()
26
27# Determine the device for inference
28device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
29model.to(device)
30
31# Construct the test prompt with example circuit data and netlists
32test_prompt = (
33 'Analyze this circuit with its netlists:
34
35'
36 'Name: Buck Converter
37'
38 'Category: Power Electronics
39'
40 'Description: Efficient DC-DC conversion for embedded systems.
41'
42 'Specifications: vin:24V, vout:17V, current:3A, efficiency:92%, fsw:500kHz
43
44'
45 'Altium Netlist:
46'
47 'J1,1,0,VIN
48'
49 'J2,2,0,GND
50'
51 'U1,PIN1,PIN2,LM27761
52'
53 'L1,SW,VOUT,10uH
54'
55 'C1,VOUT,GND,47uF
56
57'
58 'LTspice Netlist:
59'
60 '* Buck Converter Example
61'
62 'VIN VIN 0 DC 24
63'
64 'CIN VIN 0 10uF
65'
66 'XU1 PIN1,PIN2,PIN3,PIN4 LM27761
67'
68 'L1 SW VOUT 10uH
69'
70 'C1 VOUT 0 47uF
71'
72 '.tran 0 1m 0 10n
73'
74 '.end
75
76'
77 'Provide summary with key components and simulation setup:'
78)
79
80# Tokenize the input and move to the appropriate device
81inputs = tokenizer(test_prompt, return_tensors="pt", truncation=True, max_length=1024)
82inputs = {k: v.to(device) for k, v in inputs.items()}
83
84# Generate the response
85with torch.no_grad():
86 outputs = model.generate(
87 **inputs,
88 max_new_tokens=250, # Increased token generation for more detailed summaries
89 temperature=0.7, # Adjusted for more creative but still coherent output
90 do_sample=True,
91 top_p=0.9, # Sampling strategy
92 pad_token_id=tokenizer.pad_token_id,
93 eos_token_id=tokenizer.eos_token_id
94 )
95
96# Decode and print the generated response
97response = tokenizer.decode(outputs[0], skip_special_tokens=True)
98if "Provide summary" in response:
99 response = response.split("Provide summary")[-1].strip()
100
101print(response)Qwen/Qwen3.5-2Bhardware_circuits_dataset.jsonl. It comprises 1000 entries (500 Power Electronics circuits and 500 High-Speed Design circuits), each featuring:
r: 16 (LoRA attention dimension)lora_alpha: 32 (Scaling factor for LoRA)lora_dropout: 0.1 (Dropout probability for LoRA layers)target_modules: ["q_proj", "v_proj", "k_proj", "o_proj"] (Targeted attention layers for LoRA)Epochs: 2Batch Size: 1 (effective batch size 2 with gradient accumulation)Gradient Accumulation Steps: 2Learning Rate: 2e-4Max Sequence Length: 1024 tokens (allowing for detailed netlist inclusion)bnb_4bit_quant_type="nf4").hardware_circuits_dataset.jsonl used for training, along with this Google Colab notebook (Qwen_3.5_2B_Hardware_Circuits_Fine_Tuning.ipynb), are also available in this repository. This allows for full reproducibility and further experimentation.