cgbur / llama2.zig Goto Github PK
View Code? Open in Web Editor NEWInference Llama 2 in one file of pure Zig
License: MIT License
Inference Llama 2 in one file of pure Zig
License: MIT License
( CONTROL BUILD WITH upstream main branch and zig cc)
.PHONY: winzig
winzig:
c:\zig\zig cc -Doptimize=ReleaseFast -march=native -ffinite-loops -DCOMPILER="ZIG" -Ofast -fno-math-errno -D_WIN32 -o runzig.exe -I. -xc save_to_file.c run.c win.c base64_utils.c
../babylwin.c/runzig ../out/model15M.bin -z ..\out\tok32k.bin -t 0 -p 1.0 -n 0 -s 42 -i "Varsa ran"
Varsa ran to the park. She saw a big, red balloon in the sky. She wanted to catch it. She ran after it, but it was too high. She tried to jump, but she couldn't reach it.Suddenly, a boy came up to her. He had a big smile on his face. He said, "I can help you catch the balloon!" He ran up to the balloon and grabbed it. He held it tight and said, "I'm going to release it!"The boy ran around the park, pulling the balloon with all his might. He was so strong! The balloon flew up into the sky. The boy was so happy. He said, "Thank you for helping me!"The boy and Vars played with the balloon all day. They had so much fun. They were the best of friends. Once upon a time, there was a little girl named Lily. She loved to play outside in the sunshine. One day, she saw a big, red ball in the sky. It was the sun! She thought it was so pretty.Lily wanted to play with the ball
achieved tok/s: 35.250207 for ZIG
main.exe ../out/model15M.bin -t 0 -v -s 42 -p 1.0 -i "Versa ran"
config: main.Config{ .dim = 288, .hidden_dim = 768, .n_layers = 6, .n_heads = 6, .n_kv_heads = 6, .vocab_size = 32000, .seq_len = 256 }
shared weights: true
temperature: 0
top-p: 1
SIMD vector size: 4
Versa ran to the park. He was very excited to go and play. He saw a big slide and he wanted to go on it. He ran to the slide and started to climb up. He was so excited that he started to slide down. He went faster and faster and he felt like he was flying. He was having so much fun!
Suddenly, he heard a loud noise. He looked up and saw a big truck. It was carrying a lot of boxes. He was so excited that he started to run towards it. He was so excited that he forgot to be careful. He ran right into the truck and the boxes fell out of the truck. He was so scared and he started to cry.
The truck driver saw what happened and he was very sorry. He said to the boy, "I'm sorry, I didn't mean to scare you. I was just having fun." The boy was so sorry that he had been scared. He said, "It's okay. I'm sorry I scared you. I'm sorry I scared you."
The truck driver smiled and said, "It's okay. I'm sorry I sc
61 tokens per second
and the apples versus oranges acid test (clang + omp)
.PHONY: winclang
winclang:
clang -march=native -ffinite-loops -fopenmp -DCOMPILER="CLANG" -D_CRT_SECURE_NO_WARNINGS -Ofast -fno-math-errno -D_WIN32 -o run.exe -I. -xc run.c win.c base64_utils.c save_to_file.c
$env:OMP_NUM_THREADS=4; ../babylwin.c/run ../out/model15M.bin -z ..\out\tok32k.bin -t 0 -p 1.0 -n 0 -s 42 -i "Varsa ran"
Varsa ran to the park. She saw a big, red balloon in the sky. She wanted to catch it. She ran after it, but it was too high. She tried to jump, but she couldn't reach it.Suddenly, a boy came up to her. He had a big smile on his face. He said, "I can help you catch the balloon!" He ran up to the balloon and grabbed it. He held it tight and said, "I'm going to release it!"The boy ran around the park, pulling the balloon with all his might. He was so strong! The balloon flew up into the sky. The boy was so happy. He said, "Thank you for helping me!"The boy and Vars played with the balloon all day. They had so much fun. They were the best of friends. Once upon a time, there was a little girl named Lily. She loved to play outside in the sunshine. One day, she saw a big, red ball in the sky. It was the sun! She thought it was so pretty.Lily wanted to play with the ball
achieved tok/s: 91.660676 for CLANG
Hope it helps. not really an issue, more for your ref.
main.exe ../out/model15M.bin -t 0 -v -s 42 -i "Værså ran"
config: main.Config{ .dim = 288, .hidden_dim = 768, .n_layers = 6, .n_heads = 6, .n_kv_heads = 6, .vocab_size = 32000, .seq_len = 256 }
shared weights: true
temperature: 0
top-p: 1
SIMD vector size: 4
error: TokenNotFound
main.exe ../out/model15M.bin -t 0 -v -s 42 -i "Versa ran"
config: main.Config{ .dim = 288, .hidden_dim = 768, .n_layers = 6, .n_heads = 6, .n_kv_heads = 6, .vocab_size = 32000, .seq_len = 256 }
shared weights: true
temperature: 0
top-p: 1
SIMD vector size: 4
Versa ran to the park. et cetera
Can you add -march=native to llama2.c make runfast? zig enables it by default.
https://godbolt.org/z/1n3bbTafs
Also enable native for rust.
Reported that it does not work properly on windows. Pushed 631d596 to avoid using linux specific mappings. Will test and debug to get it working properly on windows this weekend.
Thank you @Freakman
on discord for testing this!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.