Skip to content

Commit 2c9cc32

Browse files
Add initial results
1 parent c6b0792 commit 2c9cc32

4 files changed

Lines changed: 57 additions & 6 deletions

File tree

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,32 @@ RSR-core/
1414
│ └── cuda/ # CUDA GPU kernels
1515
├── tests/ # Unit and integration tests
1616
└── benchmarks/ # Performance benchmarks
17-
```
17+
```
18+
19+
## Benchmark Results
20+
21+
### Matrix-Vector Multiplication
22+
23+
#### CPU:
24+
25+
#### CUDA:
26+
27+
### Ternary (1.58bit) LLMs
28+
29+
Speedup is computed from `Avg Time` against the `HF bfloat16` baseline for the same model.
30+
31+
#### CPU 🖥️
32+
| Model | HF Time | RSR (ours) Time | HF Tok/s | RSR (ours) Tok/s | Speedup vs HF |
33+
| --- | ---: | ---: | ---: | ---: | ---: |
34+
| Falcon3-10B-Instruct-1.58bit | 351.215s | **5.663s** | 0.2 | **11.3** | **62.0x** |
35+
| Llama3-8B-1.58-100B-tokens | 261.557s | **4.862s** | 0.2 | **13.4** | **53.8x** |
36+
| bitnet-b1.58-2B-4T-bf16 | 31.446s | **2.258s** | 2.1 | **28.8** | **13.9x** |
37+
| bitnet-b1.58-2B-4T | 4.582s | **2.221s** | 14.2 | **29.3** | **2.1x** |
38+
39+
#### CUDA ⚡
40+
| Model | HF Time | RSR (ours) Time | HF Tok/s | RSR (ours) Tok/s | Speedup vs HF |
41+
| --- | ---: | ---: | ---: | ---: | ---: |
42+
| Falcon3-10B-Instruct-1.58bit | 2.536s | **1.351s** | 25.2 | **47.4** | **1.9x** |
43+
| Llama3-8B-1.58-100B-tokens | 2.035s | **1.097s** | 31.9 | **59.3** | **1.9x** |
44+
| bitnet-b1.58-2B-4T-bf16 | 1.966s | **1.133s** | 33.1 | **57.4** | **1.7x** |
45+
| bitnet-b1.58-2B-4T | 1.563s | **1.139s** | 41.6 | **57.1** | **1.4x** |

integrations/bitnet/COMING_SOON.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Coming soon!

integrations/hf/model_infer.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
)
5050

5151

52+
def _bitnet_act_quant(activation: torch.Tensor) -> torch.Tensor:
53+
"""Compatibility wrapper around the shared BitNet activation quantizer."""
54+
return bitnet_act_quant(activation)
55+
56+
5257
def _read_json(path: Path) -> dict[str, Any]:
5358
return json.loads(path.read_text())
5459

@@ -175,10 +180,13 @@ def forward(self, inputs: torch.Tensor) -> torch.Tensor:
175180
if self.rms_norm is not None:
176181
inputs = self.rms_norm(inputs)
177182

183+
input_device = inputs.device
184+
input_dtype = inputs.dtype
185+
178186
if self._cuda_backend:
179-
# CUDA path: unchanged — the kernel does its own quantization.
180-
inputs = inputs.float()
181-
flat_inputs = inputs.reshape(-1, self.in_features)
187+
# CUDA path: run the kernel in float32, then restore the caller's
188+
# activation dtype so surrounding bf16 modules keep matching dtypes.
189+
flat_inputs = inputs.float().reshape(-1, self.in_features)
182190
out_device = self.multiplier.device
183191
flat_outputs = torch.empty(
184192
(flat_inputs.shape[0], self.out_features),
@@ -231,8 +239,8 @@ def forward(self, inputs: torch.Tensor) -> torch.Tensor:
231239
else:
232240
output = output * ws
233241

234-
if inputs.device.type != "cpu" or inputs.dtype != output.dtype:
235-
output = output.to(device=inputs.device, dtype=inputs.dtype)
242+
if output.device != input_device or output.dtype != input_dtype:
243+
output = output.to(device=input_device, dtype=input_dtype)
236244
return output
237245

238246
def extra_repr(self) -> str:

tests/test_model_infer.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,20 @@ def test_forward_batch(self):
189189
out = layer(x)
190190
assert out.shape == (4, 32)
191191

192+
def test_preserves_bfloat16_for_downstream_cuda_linear(self):
193+
layer, _ = _make_cuda_rsr_linear(32, 64)
194+
x = torch.randn(4, 64, device="cuda", dtype=torch.bfloat16)
195+
196+
out = layer(x)
197+
198+
assert out.device.type == "cuda"
199+
assert out.dtype == torch.bfloat16
200+
201+
downstream = nn.Linear(32, 16, bias=False, device="cuda", dtype=torch.bfloat16)
202+
y = downstream(out)
203+
assert y.dtype == torch.bfloat16
204+
assert y.shape == (4, 16)
205+
192206
def test_weight_scale_multiply(self):
193207
layer, _ = _make_cuda_rsr_linear(32, 64, weight_scale_mode="multiply",
194208
weight_scale_val=2.0)

0 commit comments

Comments
 (0)