Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

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!

799,826 Aufrufe • vor 1 Monat •via X (Twitter)

46 Kommentare

Profilbild von Shu
Shuvor 1 Monat

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.

Profilbild von Shu
Shuvor 1 Monat

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.

Profilbild von Shu
Shuvor 1 Monat

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.

Profilbild von Shu
Shuvor 1 Monat

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!

Profilbild von Maximiliano Moxarella
Maximiliano Moxarellavor 1 Monat

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

Profilbild von shadcn
shadcnvor 1 Monat

🤯

Profilbild von Evil Rabbit
Evil Rabbitvor 1 Monat

shu you are my hero

Profilbild von Shu
Shuvor 1 Monat

Evil you’re mine too

Profilbild von Evil Rabbit
Evil Rabbitvor 1 Monat

🤍🫂

Profilbild von Patrick Smith
Patrick Smithvor 1 Monat

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.

Profilbild von Shu
Shuvor 1 Monat

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

Profilbild von Patrick Smith
Patrick Smithvor 1 Monat

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!

Profilbild von Aiden Bai
Aiden Baivor 1 Monat

frickin awesome

Profilbild von Guillaume Ausset - @ausset.me
Guillaume Ausset - @ausset.mevor 1 Monat

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

Profilbild von Aarav Dayal
Aarav Dayalvor 1 Monat

IDK man its not that good.

Profilbild von Jingtao Wang
Jingtao Wangvor 1 Monat

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

Profilbild von Brett Lamy
Brett Lamyvor 1 Monat

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

Profilbild von Evan Bacon 🥓
Evan Bacon 🥓vor 1 Monat

This is wild, nice work!

Profilbild von Shu
Shuvor 1 Monat

Thanks Evan!

Profilbild von Matias 🧉
Matias 🧉vor 1 Monat

this is so cool

Profilbild von Max
Maxvor 1 Monat

This is sick!

Profilbild von Daniel White
Daniel Whitevor 1 Monat

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

Profilbild von Mike Majara
Mike Majaravor 1 Monat

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

Profilbild von Shu
Shuvor 1 Monat

@cramforce It's made with

Profilbild von Mendy
Mendyvor 1 Monat

Will you share the process?

Profilbild von Duncan
Duncanvor 1 Monat

wow

Profilbild von Ericoolen
Ericoolenvor 1 Monat

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.

Profilbild von Anoop
Anoopvor 1 Monat

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

Profilbild von Dominic Gannaway
Dominic Gannawayvor 1 Monat

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

Profilbild von Shu
Shuvor 1 Monat

I can re-train it with some examples!

Profilbild von Dominic Gannaway
Dominic Gannawayvor 1 Monat

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

Profilbild von Jesse
Jessevor 1 Monat

very nice

Profilbild von Duncan
Duncanvor 1 Monat

this is really really good and impressive

Profilbild von Bola Banjo
Bola Banjovor 1 Monat

Insaneeeeee.

Profilbild von Pedro Duarte
Pedro Duartevor 1 Monat

🐐

Profilbild von Terry · OpenCreators
Terry · OpenCreatorsvor 1 Monat

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

Profilbild von Travis Fischer
Travis Fischervor 1 Monat

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

Profilbild von Alex
Alexvor 1 Monat

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.

Profilbild von Matthew Porteous
Matthew Porteousvor 1 Monat

very cool

Profilbild von Zach
Zachvor 1 Monat

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

Profilbild von Avinash
Avinashvor 1 Monat

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

Profilbild von Aryan Vichare
Aryan Vicharevor 1 Monat

this is so cool

Profilbild von NSPG 911
NSPG 911vor 1 Monat

or we could just use hljs?

Profilbild von Simon Le Marchant
Simon Le Marchantvor 1 Monat

Now that's pretty damn cool

Profilbild von Enri
Enrivor 1 Monat

magic!

Profilbild von Patrick Smith
Patrick Smithvor 1 Monat

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

Ähnliche Videos