dense-reader
A decode matmul for Tenstorrent Tensix devices, y = x @ W^T, optionally followed by SiLU or fused with SwiGLU or
GeGLU, from the dense_reader package of tensix-kernels.
Requirements
- Linux x86_64, Python 3.10 or 3.12, and torch.
- A Tenstorrent Blackhole card, or the Blackhole library (
libttsim_bh.so) of ttsim v1.16.0. - SFPI 7.89.0 in ttnn's
runtimedirectory, installed as RUNNING.md describes. - W [out, in] with out and in multiples of 32.
Usage
pip install kernels ttnn==0.81.1
import torch
from kernels import get_kernel
dense_reader = get_kernel("Xylolabs/dense-reader", version=1, backend="cpu")
device = dense_reader.open_device(0)
w = dense_reader.prepare_weight(device, torch.randn(4096, 2048) * 0.02, "bfloat8_b") # [out, in]
y = dense_reader.linear(torch.randn(1, 2048), w) # [1, 4096] bf16
API
| Function | Inputs | Output | Purpose |
|---|---|---|---|
open_device(device_id=0) |
int | ttnn device | Open a Tensix device or ttsim |
close_device(device) |
ttnn device | None | Close a device from open_device |
prepare_weight(device, weight, dtype="bfloat8_b", *, up=None, col_scale=False, sharded=True) |
weight, up: float [out, in]; dtype bfloat8_b, bfloat4_b or bfloat16 |
DenseWeight |
Put a weight, or a GLU's gate and up, in DRAM |
linear(x, weight, *, activation=None, fidelity="hifi2", out_dtype=torch.bfloat16) |
x: float [..., in], or ttnn bf16 TILE; activation None, "silu", "swiglu" or "geglu" | y: bf16 or float32 [..., out] | y = x @ W^T, then the activation |
weight_values(weight) |
DenseWeight |
float32 [in, out], or (gate, up) | The values the device weight holds |
reference(x, weight, *, activation=None) |
x: float [..., in]; DenseWeight |
float64 [..., out] | The float64 reference of linear |
DenseWeight.deallocate() |
none | None | Free the weight's device tensors |
Supported dtypes
- Weight:
bfloat8_b,bfloat4_borbfloat16. - x: bf16; accumulation in fp32.
- y: bf16 or float32.
License
Apache License 2.0, with tt-metal's attribution in NOTICE.txt.
- Downloads last month
- -
kernels
tenstorrent
tensix
apache-2.0
- Kernel Builder
- 95535fd