Files
tinygrad/test/external/external_benchmark_bert_matmuls.py
chenyu 43e4565148 weighted linear in external_benchmark_bert_matmuls (#9757)
include the linear to get qkv, and permute so that stride matches with the real run
2025-04-06 23:35:42 -04:00

16 lines
701 B
Python

from tinygrad import Tensor, dtypes
dtypes.default_float = dtypes.float16
if __name__ == "__main__":
# matmuls in bert layers
BS = 96//6
tensors = [
(Tensor.empty(BS, 512, 1024), Tensor.empty(1024, 1024).T), # linear to get qkv
(Tensor.empty(BS, 512, 16, 64).permute(0,2,1,3), Tensor.empty(BS, 512, 16, 64).permute(0,2,3,1)), # q@k
(Tensor.empty(BS, 16, 512, 512), Tensor.empty(BS, 512, 16, 64).permute(0,2,1,3)), # qk@v
]
for t0, t1 in tensors:
print(f"{t0.shape=}, {t0.lazydata.st.real_strides()=}, {t1.shape=}, {t1.lazydata.st.real_strides()=}")
for _ in range(5):
t0.dot(t1, dtype="half").realize()