Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

LoRA Router

Can a small language model, adapted with LoRA, close timing on a chip design faster than OpenROAD's fixed repair scripts?

This repo trains a LoRA adapter on Qwen2.5-1.5B to drive OpenROAD step by step during timing closure, on small open-source blocks in the sky130 technology.

The problem

After placement and clock-tree synthesis, a design usually misses its clock target. Engineers then run repair commands (resize cells, insert buffers, re-route) until timing is met. OpenROAD's flows use a fixed script for this: the same commands, in the same order, on every design. That wastes tool time when a cheap fix would do, and stops too early when more work is needed.

The idea

Let a model look at the design's current timing and choose the next repair, one step at a time, and stop as soon as the target is met.

 placed design ──► OpenROAD reports the worst paths ──► Qwen + LoRA picks one action ──► OpenROAD runs it
       ▲                                                                                      │
       └──────────────────────────────── until Qwen picks "finish" ◄──────────────────────────┘
  • Qwen decides what to do and where (which repair, which path, which cell).
  • OpenROAD does the actual work (sizing, buffering, routing, timing analysis).
  • The goal is less tool time to reach the same clock target, not a faster clock.

How one decision works

Each step, the model gets a text summary of the design and a short list of legal actions labelled A, B, C… It answers with one letter. That is one forward pass (about 1 s), and it can never give an invalid answer.

TARGETS  period <= 6.96 ns at slow corner | hold >= 0 | cell area <= 5966 um^2
NOW      period 7.02 ns | hold +0.045 | cell area 5172 um^2 (57%)
ROUTED   period after a trial global route 7.09 ns | MET: no (margin -0.13 ns)
HISTORY  1. route_repair -> period 9.25 -> 7.02 ns, 28.3 s
WORST PATHS  P1 slack -1.42 | 9 stages | _341_ or4_4 fo4 d1.08 ...
CHOICES
 A: finish
 B: repair_timing   (global setup + hold repair)
 C: repair_design   (fix slew, cap and fanout)
 D: route_repair    (global route, then repair with routed wires)
 E: pull_path P1    (move the worst path's cells together)
Answer with one letter.

(Shortened from a real prompt on the uart design.)

How it is trained

  1. Search (CPU, about 10 h for 31 designs). For every design, OpenROAD tries many action sequences from the same starting point, and we record the period and tool time after each one.
  2. Labels. For each state seen in the search, each choice is scored by the tool time it takes to reach the target from there. finish is the best choice once the target is met, which teaches the model when to stop.
  3. Fine-tuning (GPU, about 30 min per epoch). The LoRA learns to put the highest probability on the fastest choice.
  4. Eval. The trained model runs live OpenROAD on designs it never saw, against the default and max-effort scripts and the best fixed action sequence.

Results so far

Early and small: 3 unseen designs, 1 seed. Full details: docs/2026-11-15_pick_agent_results.md.

Unseen design Max-effort script Best fixed sequence Qwen + LoRA
xtea met, 428 s missed met, 176 s (2.4× faster), stopped by itself
simd4 met, 40 s missed missed
axis_stat_counter marginal missed missed by 0.01 ns
  • Works: no invalid answers, about 1 s per decision, and it stops on its own once the target is met.
  • Not yet good enough: it leans on one action (route_repair), which misses on the smaller designs. Fine-tuning raised held-out choice accuracy from about 0.3 to 0.6.
  • Next: deeper search trees, then eval on all 5 held-out designs with several seeds.

Designs

31 small blocks, no full CPUs (flows/designs/): multipliers, MAC units, FIR, ALU, SIMD, floating-point units, a register file, UART, I2C, Ethernet and PTP blocks, AXI-stream FIFO and switch, and crypto cores (AES, SHA-1/256, MD5, ChaCha, SipHash, PRINCE, XTEA). They range from about 500 to 15,000 cells. The 25 third-party designs are under MIT, BSD-2 or Apache-2.0; flows/designs/SOURCES.md lists each origin and licence. Five are held out from training (flows/designs/held_out.txt).

Repo layout

Path What it is
flows/pick.py The current agent. Search, labels, fine-tuning, fixed-sequence baseline and eval
flows/pipeline2.sh Runs search → fixed → fine-tune → eval; FROM=sft resumes at a stage
flows/closure_env.py The OpenROAD environment: timing summary, action → Tcl, trial route, checkpoints, parallel branches
flows/session.py A live OpenROAD session in the OpenLane Docker image
flows/run_flow.py Runs the OpenLane 2 flow with given settings
flows/designs/ The 31 designs and their OpenLane configs
results/agent/ Search trees (search_*.json), per-design setup (prep_*.json), logs, the trained adapter (adapter_pick.pt, 72 MB)
docs/ Dated write-ups and the plan
flows/agent.py, flows/rl.py, flows/compare.py, flows/sta_at.py Earlier work (see below)
lora_router/, tests/ LoRA layer code, and the congestion-model work (see below)

Setup

  1. Python packages: pip install -r requirements.txt (see the notes at the top of the file for torch).
  2. WSL2 with Docker, and the image ghcr.io/efabless/openlane2:2.3.10.
  3. The sky130 PDK, installed by volare at ~/.volare inside WSL (the version OpenLane 2.3.10 pins).
  4. Qwen weights:
    python -c "from huggingface_hub import snapshot_download as d; d('Qwen/Qwen2.5-1.5B-Instruct', local_dir='third_party/models/Qwen2.5-1.5B-Instruct')"

Run directories go to ~/lora_router_runs/ inside WSL. The search needs about 7 GB of WSL memory at 4 branches at once (--par 4).

Running it

python -u -W ignore -m flows.pick search --designs all            # CPU; skips designs already searched
python -u -W ignore -m flows.pick fixed --designs train           # best fixed sequence (seconds)
python -u -W ignore -m flows.pick sft --designs train --val held --epochs 2   # GPU; held-out accuracy peaked at epoch 1
python -u -W ignore -m flows.pick eval --designs held --policies default max_effort fixed pick_lora

Useful eval flags: --no_repeat 0.02 (don't re-offer an action that just gained under 0.02 ns), --auto_finish (finish by rule when the target is met; an ablation).

Earlier work

  • Choosing flow settings by RL (flows/rl.py): on one design (mac16), a found setting routed 1.69× faster than the default flow at the same clock and area, and another reached +11.3% frequency. The LoRA did not beat base Qwen, so this is not shown to be learned. docs/2026-11-11_openroad_rl.md
  • First command agent, free-text JSON answers (flows/agent.py): met the target in 2 of 12 runs, 81% of answers invalid, about 9 s per decision. It is the reason for the letter-choice design above. docs/2026-11-11_agent_results.md
  • Congestion-model adaptation (lora_router/): a LoRA on CircuitFormer, adapting a congestion predictor from CircuitNet-N28 to N14. On hold (paper topic 2). docs/congestion_lora.md

Third-party

Qwen2.5-1.5B-Instruct (Apache 2.0) is downloaded, not redistributed; the .pt files in results/ hold only LoRA weights. OpenLane 2, OpenROAD and the sky130 PDK are used through their published Docker image and installer. CircuitFormer and the CircuitNet datasets belong to their authors and are not redistributed; fully fine-tuned CircuitFormer checkpoints are git-ignored because they are derived from its weights. Third-party RTL licences are listed in flows/designs/SOURCES.md.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages