Loading video...

Video Failed to Load

Go Home

I trained a small model to do syntax highlighting in the browser with GPU. Meet gpu-lexer from Vercel Labs: Small (27.5KB), fast (runs on WebGPU), and language-agnostic (model guesses the syntax). It is experimental and built for learning!

677,868 views • 4 days ago •via X (Twitter)

46 Comments

Shu's profile picture
Shu4 days ago

Perf is good thanks to WebGPU, especially when the source is large. Also it doesn’t block the main CPU thread. Keep in mind that all highlighters have different pipelines and use cases. This project can’t yet be used to fully replace any.

Shu's profile picture
Shu4 days ago

Size is also impressive considering that it’s trained with 50+ languages (and it behaves okay for languages outside of the training group). The model itself is like 70% of the lib, inlined in the bundle.

Shu's profile picture
Shu4 days ago

Correctness. I’m comparing every span types with Shiki, which is almost the golden standard today. It shows the weighted correctness of top 25 popular languages on GitHub. Shiki uses real AST while others might not, hence the differences.

Shu's profile picture
Shu4 days ago

Why creating this? I’ve been struggling with syntax highlighting for years mostly because: 1) large language grammar bundles; 2) language detection and dynamic loading; 3) bad perf and slow down of main app. And it’s great to explore more possibilities and share!

Maximiliano Moxarella's profile picture
Maximiliano Moxarella4 days ago

using matrix multiplication to turn the word function yellow is truly what alan turing died for

shadcn's profile picture
shadcn4 days ago

🤯

Evil Rabbit's profile picture
Evil Rabbit4 days ago

shu you are my hero

Shu's profile picture
Shu4 days ago

Evil you’re mine too

Evil Rabbit's profile picture
Evil Rabbit4 days ago

🤍🫂

Patrick Smith's profile picture
Patrick Smith3 days ago

My new js-syntax-highlight-html.wasm is faster for three.min.js and gets within 99.9% agreement with Shiki. I really love the language-agnostic model idea so I’m fascinated to see how that evolves.

Shu's profile picture
Shu3 days ago

Looks amazing & wasm makes a lot of sense, this is the way for accurate highlighting.

Patrick Smith's profile picture
Patrick Smith3 days ago

I’m really excited to see how gpu-lexer evolves, I think I see it’s already updated on your site so I’m comparing again. I’m also curious if a small model executing on WebAssembly could be viable, especially with SIMD!

Aiden Bai's profile picture
Aiden Bai4 days ago

frickin awesome

Guillaume Ausset - @ausset.me's profile picture
Guillaume Ausset - @ausset.me4 days ago

That’s right, syntax highlighting goes into the transformer hole.

Aarav Dayal's profile picture
Aarav Dayal4 days ago

IDK man its not that good.

Jingtao Wang's profile picture
Jingtao Wang4 days ago

Marvellous! I'm particularly interested in how you trained it. Would you mind sharing it someday?

Brett Lamy's profile picture
Brett Lamy4 days ago

Is this open source? Where do I download the model? Is there a NPM package I can install?

Evan Bacon 🥓's profile picture
Evan Bacon 🥓3 days ago

This is wild, nice work!

Shu's profile picture
Shu3 days ago

Thanks Evan!

Matias 🧉's profile picture
Matias 🧉3 days ago

this is so cool

Max's profile picture
Max4 days ago

This is sick!

Daniel White's profile picture
Daniel White4 days ago

this is crazy work man, you're cooking as always !!

Mike Majara's profile picture
Mike Majara4 days ago

@cramforce Incredible! Vid looks class to what did you use?

Shu's profile picture
Shu3 days ago

@cramforce It's made with

Mendy's profile picture
Mendy4 days ago

Will you share the process?

Duncan's profile picture
Duncan4 days ago

wow

Ericoolen's profile picture
Ericoolen3 days ago

Great experiment, but when I look at examples on cpp and haskell, its highlighting is pretty poor and inconsistent, and I think those languages should benefit most from such an approach for syntax highlighting, as normal ways cannot handle those complex and extendable syntaxes.

Anoop's profile picture
Anoop4 days ago

Incredible 🤯 -- r u planning on writing article on the training process ?

Dominic Gannaway's profile picture
Dominic Gannaway3 days ago

this is awesome! it's a shame it doesn't too well with tsrx though :(

Shu's profile picture
Shu3 days ago

I can re-train it with some examples!

Dominic Gannaway's profile picture
Dominic Gannaway3 days ago

that would be amazing! you can find plenty of examples here thank you!

Jesse's profile picture
Jesse4 days ago

very nice

Duncan's profile picture
Duncan4 days ago

this is really really good and impressive

Bola Banjo's profile picture
Bola Banjo4 days ago

Insaneeeeee.

Pedro Duarte's profile picture
Pedro Duarte3 days ago

🐐

Terry · OpenCreators's profile picture
Terry · OpenCreators4 days ago

27KB GPU syntax highlighter in-browser — language-agnostic lexing is the part I want to steal.

Travis Fischer's profile picture
Travis Fischer3 days ago

this is so dope dude would love more details on how you trained the model

Alex's profile picture
Alex3 days ago

27.5KB doing syntax highlighting in-browser on WebGPU is the demo that sticks. once the model is a local primitive you ship with the page, latency and privacy stop being product features you apologize for.

Matthew Porteous's profile picture
Matthew Porteous4 days ago

very cool

Zach's profile picture
Zach4 days ago

Dude... what!? Incredible. Can you share your process for this?

Avinash's profile picture
Avinash3 days ago

additionally - would be cool to have stories like this in aiconf asia -

Aryan Vichare's profile picture
Aryan Vichare4 days ago

this is so cool

NSPG 911's profile picture
NSPG 9113 days ago

or we could just use hljs?

Simon Le Marchant's profile picture
Simon Le Marchant4 days ago

Now that's pretty damn cool

Enri's profile picture
Enri4 days ago

magic!

Patrick Smith's profile picture
Patrick Smith3 days ago

Many programming languages are context-sensitive so I imagine the attention of language models is a perfect fit. Very cool stuff!

Related Videos