正在加载视频...

视频加载失败

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!

789,396 次观看 • 13 天前 •via X (Twitter)

46 条评论

Shu 的头像
Shu13 天前

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 的头像
Shu13 天前

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 的头像
Shu13 天前

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 的头像
Shu13 天前

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 的头像
Maximiliano Moxarella13 天前

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

shadcn 的头像
shadcn13 天前

🤯

Evil Rabbit 的头像
Evil Rabbit13 天前

shu you are my hero

Shu 的头像
Shu13 天前

Evil you’re mine too

Evil Rabbit 的头像
Evil Rabbit13 天前

🤍🫂

Patrick Smith 的头像
Patrick Smith12 天前

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 的头像
Shu12 天前

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

Patrick Smith 的头像
Patrick Smith12 天前

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 的头像
Aiden Bai13 天前

frickin awesome

Guillaume Ausset - @ausset.me 的头像
Guillaume Ausset - @ausset.me13 天前

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

Aarav Dayal 的头像
Aarav Dayal13 天前

IDK man its not that good.

Jingtao Wang 的头像
Jingtao Wang13 天前

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

Brett Lamy 的头像
Brett Lamy13 天前

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

Evan Bacon 🥓 的头像
Evan Bacon 🥓12 天前

This is wild, nice work!

Shu 的头像
Shu12 天前

Thanks Evan!

Matias 🧉 的头像
Matias 🧉13 天前

this is so cool

Max 的头像
Max13 天前

This is sick!

Daniel White 的头像
Daniel White13 天前

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

Mike Majara 的头像
Mike Majara13 天前

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

Shu 的头像
Shu12 天前

@cramforce It's made with

Mendy 的头像
Mendy13 天前

Will you share the process?

Duncan 的头像
Duncan13 天前

wow

Ericoolen 的头像
Ericoolen12 天前

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 的头像
Anoop13 天前

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

Dominic Gannaway 的头像
Dominic Gannaway12 天前

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

Shu 的头像
Shu12 天前

I can re-train it with some examples!

Dominic Gannaway 的头像
Dominic Gannaway12 天前

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

Jesse 的头像
Jesse13 天前

very nice

Duncan 的头像
Duncan13 天前

this is really really good and impressive

Bola Banjo 的头像
Bola Banjo13 天前

Insaneeeeee.

Pedro Duarte 的头像
Pedro Duarte12 天前

🐐

Terry · OpenCreators 的头像
Terry · OpenCreators13 天前

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

Travis Fischer 的头像
Travis Fischer12 天前

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

Alex 的头像
Alex13 天前

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 的头像
Matthew Porteous13 天前

very cool

Zach 的头像
Zach13 天前

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

Avinash 的头像
Avinash12 天前

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

Aryan Vichare 的头像
Aryan Vichare13 天前

this is so cool

NSPG 911 的头像
NSPG 91112 天前

or we could just use hljs?

Simon Le Marchant 的头像
Simon Le Marchant13 天前

Now that's pretty damn cool

Enri 的头像
Enri13 天前

magic!

Patrick Smith 的头像
Patrick Smith12 天前

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

相关视频