GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Qwen3.5-0.8B on AWS F2: model, HLS datapath, bandwidth study, real si… · allthingssecurity/qwen_fpga@b9afb0e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .gitignore
  • README.md
  • artifacts
    • access.txt
    • generations.md
    • prompt_ids.txt
    • qwen35_int8.manifest.json
    • tv_deltanet.json
    • vitis_reports
      • f2_hbm_bandwidth.txt
      • hbm_bw
        • hbm_bw.cfg
        • hbm_bw_kernel.cpp
        • impl_1_kernel_util_routed.rpt
        • impl_1_slr_util_routed.rpt
        • link.log
        • util.rpt
      • synth_delta_head_csynth.rpt
      • synth_gemv_mlp_csynth.rpt
    • weights.idx
  • docs
    • build_afi.md
    • hbm_bandwidth.md
    • silicon_validation.md
    • synthesis_estimate.md
  • golden
    • dump_torch_ref.py
    • eval_quant.py
    • loader.py
    • model.py
    • quant.py
    • verify.py
  • hls
    • Makefile
    • src
      • activations.hpp
      • attention.hpp
      • conv1d.hpp
      • decoder.hpp
      • deltanet.hpp
      • gemv.hpp
      • mlp.hpp
      • norm.hpp
      • qwen_synth.hpp
      • rope.hpp
      • state.hpp
      • types.hpp
      • weight_offsets.hpp
    • tb
      • run_hls.cpp
      • tb_decode.cpp
      • tb_deltanet.cpp
    • vitis
      • gen_bw_kernel.py
      • hbm_bw.cfg
      • hbm_bw_host.cpp
      • hbm_bw_kernel.cpp
      • qwen.cfg
      • qwen_host.cpp
      • qwen_kernel.cpp
      • synth
        • hls.tcl
        • synth_delta.cpp
        • synth_gemv.cpp
  • run_all.sh
  • run_hls.py
  • run_prompt.py
  • scripts
    • emit_access.py
    • emit_weight_index.py
    • eval_act_int8.py
    • export_decode_ref.py
    • export_testvectors.py
    • gen_offsets.py
    • pack_weights.py
    • run_batch.py
  • sim
    • F2_HBM2_16ch.ini
    • F2_HBM2_16ch_interleave.ini
    • Makefile
    • hbm_bw.cpp

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.gitignore‎

Copy file name to clipboard
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# envs and caches
2+
.venv/
3+
__pycache__/
4+
*.pyc
5+
6+
# never commit keys or large binaries
7+
*.pem
8+
*.bin
9+
*.npz
10+
*.xclbin
11+
*.tar
12+
13+
# big third-party clone and build trees
14+
third_party/
15+
sim/build/
16+
hls/build/
17+
artifacts/dramsim3_out/
18+
artifacts/tb_deltanet
19+
artifacts/tb_decode
20+
artifacts/run_hls
21+
22+
# keep these generated artifacts in the repo
23+
!artifacts/generations.md
24+
!artifacts/qwen35_int8.manifest.json
25+
!artifacts/vitis_reports/
Collapse file

‎README.md‎

Copy file name to clipboard
+201Lines changed: 201 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
# Qwen3.5-0.8B on AWS FPGA (F2)
2+
3+
Running batch-1 decode of `Qwen/Qwen3.5-0.8B` (text only) on an AWS F2 instance,
4+
which carries an AMD Virtex UltraScale+ HBM part (VU47P) with 16 GiB of HBM.
5+
The work covers a bit-exact software model, an HLS hardware datapath verified
6+
against it, a cycle-accurate HBM bandwidth study, a real Vitis synthesis pass on
7+
the actual chip, and a full end to end validation of the FPGA delivery path on
8+
real silicon.
9+
10+
## The core idea
11+
12+
Single token decode reads every weight from memory once, does one multiply with
13+
it, and moves on. It is limited by memory bandwidth, not by math. So the token
14+
rate is set by one equation:
15+
16+
```
17+
tokens per second = HBM bandwidth / bytes read per token
18+
```
19+
20+
For this model at int8 that is about 0.7586 GB per token. This is why the whole
21+
project centers on HBM bandwidth, and why the hybrid architecture of this model
22+
matters: only 6 of its 24 layers keep a KV cache, so its per token memory traffic
23+
stays flat as context grows, unlike a dense model whose KV cache eventually
24+
dominates.
25+
26+
## Model shape
27+
28+
Qwen3.5-0.8B, text path only (the vision tower and the MTP head are dropped).
29+
24 layers in the pattern `[linear_attention x3, full_attention] x6`.
30+
31+
- **Gated DeltaNet layers (18 of 24):** 16 heads, key and value head dim 128, a
32+
short causal conv of width 4, no growing KV cache. The recurrent state is
33+
16 x 128 x 128 x 18 layers = 18 MB in fp32, constant regardless of context
34+
length. That fits in the VU47P on-chip URAM, so it never touches HBM.
35+
- **Full attention layers (6 of 24):** 8 query heads, 2 key/value heads, head
36+
dim 256, QK-norm, partial rotary on the first 64 of 256 dims, and an output
37+
gate. KV traffic is 6 KB per token, against 56 KB per token for a comparable
38+
dense model.
39+
- hidden size 1024, vocab 248320, tied embedding and output head.
40+
41+
## Repository layout
42+
43+
```
44+
golden/ pure-numpy fp32 and int8 decode, checked against HF transformers
45+
hls/ HLS C++ kernels and testbenches, plus the Vitis wrapper and configs
46+
sim/ DRAMsim3 HBM bandwidth harness driven by the real weight layout
47+
scripts/ weight packing, offset generation, prompt batch, eval
48+
docs/ architecture, bandwidth study, synthesis estimate, silicon validation
49+
artifacts/ generated outputs and the real Vitis reports
50+
```
51+
52+
## Results
53+
54+
### 1. The software model matches PyTorch
55+
56+
`golden/` is a from-scratch numpy decode transcribed from the Qwen3.5 modeling
57+
code and checked step by step against Hugging Face transformers.
58+
59+
```
60+
worst hidden deviation 1.9e-06
61+
worst logit deviation 7.5e-06
62+
result: numpy model matches torch
63+
```
64+
65+
Two things this caught, both of which would have produced fluent nonsense in
66+
hardware without an error: the norm uses `(1 + weight)` because the checkpoint
67+
stores gamma centered at zero, and the DeltaNet gated norm does not, so the two
68+
norms in the model use different conventions. And the recurrent form of the delta
69+
rule matches the chunked form to 7.6e-06, so the hardware needs a single
70+
recurrent datapath, not a separate prefill kernel.
71+
72+
### 2. int8 holds up, and int8 activations make it fit
73+
74+
Per output channel int8 weights, checked against fp32 over several prompts:
75+
76+
| datapath | top-1 agreement | mean KL | bytes per token |
77+
|---|---|---|---|
78+
| int8 weights, fp32 activations | 97.9% | 1.2e-3 | 758 MB |
79+
| int8 weights and int8 activations | 94.8% | 1.2e-2 | 758 MB |
80+
81+
int8 activations cost a few points of agreement but drop the compute cost by
82+
roughly 10x, because the multiply becomes int8 by int8. Quantizing the tied
83+
embedding and output head is free on quality and halves the per token bytes, so
84+
it is done.
85+
86+
### 3. The full HLS decode matches the model
87+
88+
Every operation is written as synthesizable HLS C++ and composed end to end:
89+
embedding, both norms, the int8 GEMV weight streamer, the causal conv, the gated
90+
delta rule, partial rotary, gated attention, SwiGLU, and the tied head. Checked
91+
against the int8 software model over 11 decode steps:
92+
93+
```
94+
argmax matches at all 11 steps
95+
step-0 logits agree to 6.6e-05 (fp summation order only)
96+
result: HLS decode matches the software model
97+
```
98+
99+
The DeltaNet kernel also has a standalone check on a warm state, where the output
100+
matches to 3.7e-09 and the evolved recurrent state to 6.0e-08 over 262,144
101+
elements.
102+
103+
### 4. HBM bandwidth study (cycle accurate model)
104+
105+
Since real silicon was not yet in hand for this step, the memory system was
106+
modeled with DRAMsim3 using an HBM2 config matched to the F2 device on both
107+
capacity and bandwidth, driven by the actual 758 MB weight layout in the order
108+
the decoder reads it. Two design choices decide everything:
109+
110+
| layout | shallow queue | deep queue |
111+
|---|---|---|
112+
| naive sequential | 88 tok/s | 391 tok/s |
113+
| channel interleaved | 221 tok/s | 559 tok/s |
114+
115+
The channel interleaved layout with a deep outstanding read queue reaches 424
116+
GB/s, which is 92 percent of the 460 GB/s device peak, at a 96.8 percent row
117+
buffer hit rate. This becomes two concrete hardware requirements: stripe the
118+
weights across HBM pseudo-channels, and keep a few hundred reads in flight.
119+
120+
### 5. Real Vitis synthesis on the VU47P
121+
122+
An HBM bandwidth kernel and the model kernels were run through real Vitis
123+
synthesis and place and route on the actual chip. Genuine numbers from the tools:
124+
125+
- The int8 GEMV closes timing at 342 MHz and uses about 3 percent of the DSPs.
126+
- The DeltaNet head as first written failed timing at 66 MHz because a 128 wide
127+
fp32 reduction was forced into one cycle. Tiling the value dimension so the
128+
tool can register the arithmetic fixes this, verified in the software checks.
129+
- The 32 channel HBM bandwidth kernel mapped to the real part at about 39,400
130+
LUTs (3.2 percent), 272 BRAM (14 percent), 4 DSP, 0 URAM.
131+
132+
These reports are saved under `artifacts/vitis_reports/`.
133+
134+
### 6. The FPGA delivery path works on real silicon
135+
136+
The Vitis flow cannot create an AFI on F2 today, so the route to silicon is the
137+
HDK / RTL flow. The full chain was validated on real hardware with small designs
138+
before committing to the model RTL. Build to checkpoint, checkpoint to AFI, AFI
139+
loaded onto an f2, and host driving the logic and reading correct results back,
140+
all confirmed. Details in `docs/silicon_validation.md`.
141+
142+
### 7. Measured HBM bandwidth on real silicon
143+
144+
The AWS HBM bandwidth benchmark `cl_mem_perf` was built through the HDK flow,
145+
turned into an AFI, and run on a real f2.6xlarge. It closed timing at 450 MHz on
146+
all 32 HBM channels. Measured on the chip:
147+
148+
```
149+
read bandwidth 426.14 GB/s
150+
write bandwidth 433.69 GB/s
151+
read latency 268 ns
152+
```
153+
154+
Read is 92.6 percent of the 460 GB/s device peak. Decode reads the weights, so
155+
the read number is the one that sets the token rate:
156+
157+
```
158+
426.14 GB/s / 0.7586 GB per token = 562 tokens per second
159+
```
160+
161+
The DRAMsim3 model in section 4 predicted 424 GB/s and 559 tokens per second.
162+
The real chip measured 426 GB/s and 562 tokens per second. The model was right,
163+
now confirmed on silicon. Full output is in
164+
`artifacts/vitis_reports/f2_hbm_bandwidth.txt`.
165+
166+
### 8. Generations
167+
168+
Full prompts, complete answers, token counts, and timings are in
169+
`artifacts/generations.md`. The text comes from the verified int8 model path, the
170+
same arithmetic the hardware datapath uses. The token rate the hardware sustains
171+
comes from the measured HBM bandwidth above, not from these CPU timings.
172+
173+
## Reproduce
174+
175+
Everything except the FPGA build runs on a laptop.
176+
177+
```bash
178+
python3 -m venv .venv && ./.venv/bin/pip install torch transformers safetensors numpy
179+
180+
./.venv/bin/python golden/dump_torch_ref.py # torch reference
181+
python3 golden/verify.py # numpy vs torch
182+
python3 golden/eval_quant.py # int8 quality
183+
python3 scripts/pack_weights.py --check # pack int8 weights for HBM
184+
make -C hls csim_decode # full HLS decode vs model
185+
python3 scripts/run_batch.py # prompt batch and timings
186+
187+
# HBM bandwidth model (builds DRAMsim3 once)
188+
cmake -S third_party/DRAMsim3 -B third_party/DRAMsim3/build -DCMAKE_POLICY_VERSION_MINIMUM=3.5
189+
make -C third_party/DRAMsim3/build dramsim3
190+
python3 scripts/emit_access.py && make -C sim && ./run_all.sh hbm
191+
```
192+
193+
The FPGA build and silicon steps are in `docs/silicon_validation.md` and
194+
`docs/build_afi.md`.
195+
196+
## Status and what is next
197+
198+
Done: the software model, the HLS datapath, the bandwidth study, a real Vitis
199+
synthesis pass, and full validation of the silicon delivery path on real F2
200+
hardware. Next is the actual model on chip, the Qwen decode datapath written in
201+
RTL on top of the proven HBM template, so the FPGA generates tokens directly.

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.