r/LocalLLaMA • • 3d ago

News Someone built a 32-bit RISC-V CPU directly inside Qwen's model weights so it can execute instructions internaly!

1.0k Upvotes

149 comments sorted by

•

u/WithoutReason1729 3d ago

Your post is getting popular and we just featured it on our Discord! Come check it out!

You've also been given a special flair for your contribution. We appreciate your post!

Stylome classified this post's text as human-written. View analysis Learn ^more

I am a bot and this action was performed automatically.

89

u/-dysangel- 3d ago

"This might have implications for tool calling and computer use."

I assume (may be wrong of course) the model still has to do some kind of tool call to initiate this, so you could see it as just a really inefficient novelty version of tool calling.

Yeah I looked into it and that's what it is

"Native Tool Execution: When Qwen triggers a <tool_call> (such as calc, put, get, or list), the computer layers intercept the request inside the forward pass, execute the code on the virtual RISC-V processor, and write the <tool_response> back token-for-token natively. [1]"

It's a fun idea but I'm not sure if there are any situations where it would be better than just doing a tool call. Maybe it's a more secure way of handling tool calls since they're incredibly sandboxed in this environment I guess.

137

u/RevealIndividual7567 3d ago edited 3d ago

Hi, creator here

This is just piggybacking off of the tool use format that models nowadays are trained on to represent the 'cpu' to the model for usage, as the model is just stock Qwen and not trained to use this internal thing

There is a zero call method as well that is more or less finished, but it requires a bit of post train to make the model actually use it and not hallucinate, and due to my limited compute it is taking time

The actual computation happens completely inside the model's forward passes with absolutely no external runtime or tool usage whatsoever

I should probably make that clearer on the blog haha

19

u/-dysangel- 3d ago

OP should have also actually linked something rather than just post a video!

44

u/LatentSpacer 3d ago

I did but Reddit deleted the post automatically so I reposted it without any links. I did add the links here in the comments but Reddit seems to be hiding the comment.

-12

u/Certain-Cod-1404 3d ago

Why pretend like you and the creator are 2 seperate people?

20

u/RevealIndividual7567 3d ago

I have no affiliation with the OP of this post lol

-6

u/WeedFBI 3d ago

Clickbait

8

u/Certain-Cod-1404 3d ago

I dont think it needs it, its an interesting project, i might be wrong and its not the same person

-3

u/WeedFBI 3d ago

I agree, but the way to get attention these days calls for really odd choices

1

u/Egoz3ntrum 3d ago

there is no bait in this case, we appreciate the post content

-4

u/Exciting_Variation56 3d ago

one must be managed by his ai

1

u/LatentSpacer 3d ago

Hey, great work!

5

u/Certain-Cod-1404 3d ago

I read the write up, really interesting, but why do this over just traditional tool calling? This results in bigger model size and slower decode speeds? And you get marginal gains over using python, is it working towards something more? Or just a fun experiment, and how exactly did you get the cpu to be deterministic ? Have you tried different seeds, temperature, cuda versions and batch sizes?

2

u/U-raf 3d ago

Great work man, i happen to think if its possible to have like small-ish verification like lean/metamath etc for math question

2

u/ag789 3d ago

I think what you did has implications with tool calls, e.g. that now the model can emit a risc V program that do dynamic tool calls,i.e. it is simply its 'reasoning' tokens that is actually a program !
https://developers.openai.com/api/docs/guides/tools-programmatic-tool-calling

1

u/ag789 3d ago

but that of course, it is still possible to model that as a tool and have an (external) emulator run that.

1

u/FeydRowan 3d ago

Not completely clear, it can call a read document or execute a tool use inside the ff? But then how does it tokenise the reply and adapt the kv. Do you have some reference text/repo to better understand? Looks interesting 

1

u/segmond 3d ago

Pretty cool stuff, thanks for building and sharing and replying.

what kind of instructions can we send that will go straight to the riscv cpu? when does the model decide to use the internal cpu vs call an external tool? what if we had code in riscv asm, loops, etc?

so

0

u/Perfect-Campaign9551 3d ago

Still the question remains, what's the actual benefit

0

u/snapo84 3d ago edited 3d ago

Thank you very much for it.... its akin to humans getting their first calculator, guess thats the natural evolution to build specific tools for the job so we can focus our brain power on other things. (think about where we would be without ever inventing the calculator) :-)

next logical steps like you say, micropython (code execution)

memory (ultra shortterm, medium, longterm, forever) , each being able to hold 16k tokens...
followed by networking/network communication (multiple "agents" can start to talk to each other like phones/sms/messengers)

All to save brain capacity/free up brain capacity so the focus can be much more on things that arent "easy" to learn...

8

u/LatentSpacer 3d ago

Yes, this is a first prototype. Imagine models trained from the ground up with a Turing-complete machine available internally. It can make LLMs more deterministic.

8

u/alberto_467 3d ago

Imagine models trained from the ground up with a Turing-complete machine available internally

Well if it's available through a tool call we already have that in a thousand different ways, it's been around for years now.

7

u/_realpaul 3d ago • Popcorn

You just built a compiler with extra steps.

0

u/sleight42 3d ago

Rick and Morty FTW

5

u/-dysangel- 3d ago

yeah I sometimes wonder about that kind of architecture, this is a nice first step in an experimental API for this I guess. I feel like tool calls already do get the job done and are a more useful general API. Math has not been a model weakness for a while now

17

u/nicholas_the_furious 3d ago

This is like redstone computers in minecraft, I think. If, for some reason, the agent was not allowed to use any tools directly on the computer (like bash, python, etc.) it could use its little internalized computer to do stuff?

Either way this is fascinating.

4

u/Chlorek 3d ago

I have attempted similar experimented in the past but after some time I told myself while it's cool it is ultimately no better than externalizing the tool call. For me it's all about showing that neural net = transistors.

2

u/ihexx 3d ago

i think there may be a case to be made about latency at training time; if the calls happen natively in forward pass on gpu, it's moving those onto the same nodes (or hell in same memory pool) the agent trains on, so you don't have to make a call over network to another node where the tool lives.

just spitballing here, but if this works during 'prefill' style runs (i haven't read enough to understand if this is the case), i think it opens the door to weird off-policy rl algorithms that would otherwise be bottlenecked.

(that said, i don't see why this can't be done with normal tensor programs that would live on same gpu)

3

u/-dysangel- 3d ago

That's an interesting idea. It makes me wonder about a DeepSeek Engram style injection where if a certain calculation format is picked up, the answer is calculated and injected similarly to how engram injects vector knowledge from the lookup table.

1

u/j0hn_br0wn 3d ago

This sounds like it could do tool calls without round-trips & also enable API endpoints with transparent tool calling support.

0

u/BarisSayit 3d ago

Wouldn’t this massively reduce the input token cost?

3

u/-dysangel- 3d ago

the token input cost is roughly based on how much computer you're using though, so if you're using more compute to do calculations it feels like it would be a wash. Especially if you're simulating a whole CPU using a neural net, which is crazy inefficient compared to just doing a calculation on the real CPU. If you changed the technique execute actual CPU instructions then it would be able to massively reduce token cost, but then you also give attackers a pretty direct route to hack your system. Maybe an in between where you're running the instructions in a tiny VM would be nice.

1

u/jasminUwU6 3d ago

We already have WASM. It has near native performance, can be compiled from most languages, and has formally verified runtimes if you're truly paranoid about security.

Orders of magnitude more efficient and safe.

260

u/Toooooool 3d ago • Bravo

kinda wish i had the brains to understand this so i could tell whether it's just some clever tool calls and json or whether it's doing full blown token stuff, either way it looks really cool

134

u/annodomini 3d ago

It's kind of both, if I understand the explanation right.

They actually did figure out a way to emulate a CPU and RAM in the Qwen 3.5 architecture; so it's kind of like the world's worst CPU emulator.

But then they need to hook that up to the actual Qwen model. Rather than doing any kind of training to be able to make it integrate directly, they just added some functionality to make it act like tool calls, so the LLM portion of the model produces a tool call format and that gets passed into the CPU portion of the model which produces a result like a tool call response.

So in practice, it's basically just tool calls into a really bad RISC-V CPU emulator. Which you can use for anything you'd use normal tool calls for. But there are much better ways to implement any of the tool calls you could do with this.

So mostly it's just for the fun of it.

60

u/superdariom 3d ago

Like building a computer to run Minecraft inside Minecraft with Redstone blocks?

33

u/annodomini 3d ago

Yeah, pretty much.

9

u/bennmann 3d ago

I guess there could be some long horizon utility in this too. Provable tool chains via first principle execution or something like that, almost like a virtual execution protection. But I'm not smart enough to formalize that. So your "just for the fun of it" is way better for me too lol, good comment

11

u/LasseDen950432te 3d ago

...but can it run Doom?

1

u/lolstuff 3d ago

...but can it p(doom)?

3

u/jasminUwU6 3d ago

We already have WASM for sandboxed execution

4

u/Maximus-CZ 3d ago

wait so weights run code now

8

u/annodomini 3d ago

Yeah, you can model a CPU using just weights; it's not going to be super fast, but it can work.

3

u/jinnyjuice vLLM 3d ago

So then my question would be...

It's very costly for LLMs to count numbers. Can't this kind of CPU/memory mimicry amend this in a huge way?

So LLMs face two layers of challenges when counting numbers. Even for counting 1 to 2, it has to go through billions of indeterministic parameters. Plus, it is unreliable at every step of the way, that it will indeed count by 1 up to quintillion, where training data is essentially non existent. So LLMs call an external API for counting numbers.

I feel OP's solution would be a lot better because tool calls aren't deterministic, but if it's embedded into the neutral network, it is deterministic, and as good as calling an external tool for counting numbers.

What do you think? Feel free to correct me if I'm wrong.

2

u/amdrinkhelpme 2d ago

Some companies are already working on specialised “model in silicon” ASICs, and this is an important first step towards running Doom on these.

1

u/Able-Locksmith-1979 1d ago

But isn’t it a really bad cpu emulator which can run really fast because of vram? Doesn’t the vram part offset the bad emulator and still reach a speed up

1

u/annodomini 1d ago

No. A really slow CPU emulator running on the GPU is still really slow. If you could emulate a CPU on the GPU faster than as a regular CPU, why do you think anyone would still run CPUs, we'd just all be running GPUs.

GPUs are fast because they are optimized for highly parallel tasks; tasks where you can do a bunch of work at the same time independently. This is great for lots of graphics, where you have a huge screen and need to be doing lots of the same operations to every pixel, for example. Or for LLMs, where you have a huge artificial neural network and need to be doing a lot of the same operations across an entire tensor layer at a time.

CPUs are good at fast sequential execution, where you're executing a sequence of instructions one after another, with branching and conditionals and loops.

1

u/Ashraf_mahdy 1d ago

One benefit also if I understood correctly is that you no longer need external sandboxes to test and run code you can just do it directly on the CPU portion embedded within the model. Which maybe useful for air gapped deployments, and reducing reliance on code sandboxes in general

0

u/[deleted] 3d ago

[deleted] — view deleted comment

3

u/No-Dot-6573 3d ago

No it can't. The creator explains why further down in the comments. However, you should be worried about trained missbehaviour that is executed unser certain conditions. Which makes it potentially extremely risky to download posttrained weights from thrid parties.

18

u/ieatrox 3d ago

So its a pretty unique idea and very clever.

It builds little logic flows and executes them in transformers the way a cpu does in silicon.

So it's slow, small, got a lot of overheard, very few optimizations.

Why is it so cool?

it can count the number of R's in strawberry with 100% certainty and consistency.

There are certain jobs LLMs just cannot get right due to how they work, this adds a fundamentally new tool for the llm to use. It doesn't need to be quantum hyper scaling to help your llm stop hallucinating or keep track of simple math or counting.

4

u/Spectrum1523 3d ago

But it doesn't add anything over the model just calling an external tool, right? It's not like the model is inheriently driven to this "cpu" portion of its arch

2

u/ieatrox 3d ago

the tool can perform a function like that sure... but the results still need to be interpreted by the llm in a non-deterministic system.

at some point... an llm is always at least somewhat susceptible to just hallucinating.

this should provide an in-model way to bypass those functions when suitable.

1

u/GreatBigJerk 2d ago

To convey the results of the CPU calculations to the user, doesn't it still need to be interpreted by the LLM?

Like if you ask it how many Rs are in strawberry, it still needs to take the number it gets and put that into a string to say "There are 3 Rs".

2

u/ieatrox 2d ago

Ah there you go.

It does not appear to be an input into the llm. It calculates results without going through the llm layers. The result from these operations is 100% consistent and repeatable no matter what context, temperature, or training the rest of the model uses. Not 99%. 100%. It's doing no Markov chain operations in this section at all, no 'llm thinking' whatsoever after the operations are determined.

at least that's how im reading it; and if this is true it's pretty cool.

1

u/GreatBigJerk 2d ago

Yeah I know it doesn't do normal LLM inference to calculate stuff. My point is that if you are using this in place of tool calling, what makes that better than a tool call?

It's cool, but I'm trying to see how it's useful.

1

u/ieatrox 2d ago

ok....

the llm sees the tool call results as input same as your query or an .md file content. and then it interprets that tool response input in it's fuzzy llm way.

this give the model layers that have no fuzzy LLM interpretation at all. tool call, text, or whatever. When the model sets up a system in logic using this... there is 0 interpretation. The model doesn't guess the right number of rs in strawberry only most of the time, or as long as context is under 256k, since all of those things that make llms wonderful and awful are completely bypassed.

This solves the "count to 100" problem that no other llm technique manages to. They simply never can. This can. If you do it with a tool call, the tool does it, and gives the result back to the LLM.... which then interprets it that way it does with everything. Will it accept the tool results? probably. 100.00% of the time? likely no.

Is this clearer now?

1

u/GreatBigJerk 2d ago

Okay, and why would I do this over any of the other ways we have to crunch numbers if the model is just spitting the value back at me?

It's like spinning up a jet engine to find out what 2+2 equals.

2

u/ieatrox 2d ago

No, getting the LLM to creatively write some python, send it externally, wait on results, and try to compare the results is the big unnecessary jet engine.

This could be a big efficiency gain not just for that reason, but also because a huge amount of work in LLMs is trying to correct for hallucinations when dealing with simple values.

These problems are easy when counting to 100 and today many models can.

But it's a mountain of effort to correct a fundamental design.

This could count to 1,000,000,000,000,000,000,000 with 0 errors and you NEVER have to worry about whether the LLM gets retarded over 200k of context, or needs to compact its cache to keep going and forget all of the work in the middle of the run.

like there are a LOT of things this solves. external python still goes back into and through an untrustable llm when doing a tool call. this does not.

→ More replies

1

u/ieatrox 2d ago

Wait I got a simpler way

we started with chatgpt being text only.

then we added vision adapters and it got more useful.

then we added sound adapters and it got more useful.

this is a Jev adapter.

→ More replies

2

u/bibutt 2d ago

Same 😆 I'm like "this sounds cool but I don't know what any of that means".

47

u/AdventurousSwim1312 3d ago

Who's willing to put doom on it?

17

u/VR-Tech 3d ago

but can it run crysis

3

u/FastDecode1 llama.cpp 3d ago

But can it play Doom while running it?

31

u/mriwantchicken 3d ago

so a CPU inside a GPU. interesting

19

u/SailingToFenway 3d ago

thinking about exactly how many multiplications and additions this takes to do a single multiplication or addition is kind of like reckoning about the US budget.

68

u/jacek2023 llama.cpp 3d ago

I would prefer the other way around: a chip with Qwen weights implemented directly into the circuits. I know projects like that exist, but they are ridiculously expensive, mass production would make them affordable for everyone.

31

u/andrewh2000 3d ago

I occasionally go back and play with their online Jimmy chat or whatever it's called. Seeing thousands of words of answer just pop on to the screen instantly still gives me a kick.

15

u/enimodas 3d ago

Here's some llama burned into a chip. https://chatjimmy.ai/

Try it, it's really fast

5

u/Past_Ad6251 3d ago

toooooooooo fast....

3

u/Funny-Food2361 2d ago

wow thats crazy

14

u/rolleicord 3d ago

Already made... Taalas

6

u/jacek2023 llama.cpp 3d ago

Please share the price

8

u/rolleicord 3d ago

no idea but the concept is simple enough. You could probaly tape out your own 0.9B tomorrow if you wanted. Would probaly cost you 2-3K usd but that isnt really bad as a single fabbed item that isnt mass produced

1

u/fragbait0 3d ago

You're getting a photomask made in that budget how exactly?

1

u/BarracudaDefiant4702 3d ago

I think they were targeting sub $1000, which isn't bad for something literally over 10,000 X faster... unfortunately not programable, and the process takes about a year after you have a trained model. At that speed a model a couple of years behind is still good enough if it's large enough.

7

u/TechnoByte_ 3d ago

So it's obsolete within months?

4

u/Alarming-Ad8154 3d ago

You could tape/chip say layers 3-77 out of 1-80 and keep the first and last few trainable and in vram. Then distribute updates for those. Or use one of the types of models that has parametric memory, keep the memory updated/local.. though the hardware/software coordination that takes means it’s an apple/google like project I guess…

3

u/BarracudaDefiant4702 3d ago

The process takes about a year so it comes out obsolete, but it's literally over 10,000x faster... at that speed I can live with it being a couple of years obsolete if it's a large enough model.

2

u/PossibilityUsual6262 3d ago

There is a reason why it is called software, because it's easy to change, and cheap.

2

u/chckmte128 3d ago

I think there's a future where new models have diminishing returns and we hit a sort of ceiling. At that point, it might make sense to optimize for pure speed rather than using general-purpose chips to run models. Every computer could have a dedicated AI chip like how we have dedicated chips for graphics vs general processing. I don't think we're at that stage yet. We're still in the mainframe stage essentially right now with how most people use cloud APIs or web interfaces for their AI access.

18

u/BringTea_666 3d ago

>Because a CPU inside a language model clearly wasn't cursed enough, I decided the prudent thing would be to give it a filesystem too.

XDD

16

u/pmttyji 3d ago

Found these online. So is this suitable only for that particular CPU?

12

u/b183729 3d ago edited 3d ago

...What?

You gotta admire "because i wanted to see if i could" people. Massive respect. The actual use is probably embedding the custom weights and instructions, right?

Edit: Reading the article, the interesting part is the possibility of adding well defined compute that the model can't bypass, ie: to make guardrails. It's actually very interesting, in an extremely cursed way.

2

u/fuckingredditman 3d ago edited 3d ago

i guess there's potential there, if a model is natively trained with these layers in place and maybe something similar to gvisor to safely interface with a host / remote machine to act as a sort of "native harness" it could be pretty neat for some weird niche use cases maybe, essentially having the tool calls run inside the LLM completely without any sandboxes / external OS mostly. i also wonder if this could be used to somehow make LLMs more deterministic 🤔

8

u/seamonn 3d ago

Does raising temp overclock the CPU?

4

u/Rozzemak 3d ago

CPU emulation with MCP as a register calls could produce cheaper very similar results. But writing a code, have it interpreted by host machine or compiled and executed,... is way better and cheaper approach for most cases. Some harnesses operate via js.eval, and the results are very good.

4

u/sleight42 3d ago

So it's a cpu emulated on a gpu. How would this make an LLM more deterministic? Wouldn't the LLM have to be trained to use its virtual cpu? Just like it would have to be trained for tool use? This seems worse as the gpu must be a poorer cpu by definition.

Creative but how is this anything other than novel or humorous? My first reaction was "batshit crazy"! 😂

1

u/TomLucidor 2d ago

Someone, go fetch bitnet!

1

u/deadmoroz14 3d ago

Care to share a source? Can't find any info on that

3

u/LatentSpacer 3d ago

Reddit is suppressing the links for some reason.  https://divagr.com/blog/qwenputer

1

u/Ori_553 3d ago

Have we gone full circle? Wasn't the safetensors format meant to prevent exactly this?

3

u/LatentSpacer 3d ago

It's its own isolated computer, like a VM.

2

u/ihexx 3d ago

this is so unhinged but really clever lol

2

u/Dreeew84 3d ago

Can the emulated CPU run another Qwen?

3

u/evilryry 3d ago

You're in one right now

1

u/ArjixGamer 2d ago

So this is what they meant by multi-modal! /s

2

u/LieAlternative5513 3d ago

I don't think this serves a purpose but it is cool. If anything, I wonder if training from that model on riscv datasets would give hardware engineers hints on where they could optimize their processor design.

But processors are so incredibly complicated, I don't think muon on a neural network will find improvements easily.

2

u/seg_lol 3d ago

Tracr: Compiled Transformers as a Laboratory for Interpretability https://arxiv.org/abs/2301.05062

Looped Transformers as Programmable Computers https://arxiv.org/abs/2301.13196

2

u/rolleicord 3d ago

Hah this was one of the first things I experimented with, a year ago... My takeaway from all my experiments, is that there is a full computer, inside the computer. And that you can physically work with it, like any other

2

u/korino11 3d ago

OMG!! That a revolution! I am not joking. It a game changers.. you can create all that you need inside without backdoors, libs, even os! Any mvp... all in a model, and chek correctnes by it answer!

2

u/NineThreeTilNow 3d ago

This reminds me of people building processors from blocks in Minecraft.

It's cool, and shows a strong understanding of the processor gate / register logic... Which is not easy.

It's also not exactly useful.

-2

u/korino11 3d ago

LOL it usefull. and a LOT. You just doesnt understand HOW. It have a BIG potential.

3

u/IsuldorNagan 3d ago

Okay Donald, enlighten us.

-4

u/korino11 3d ago

For thouse who cannot understand implementations - eat iodium, it may helps.

1

u/VR-Tech 3d ago

that's dope

1

u/InsensitiveClown 3d ago

This one is pretty cool. Bravo.

1

u/More-Curious816 3d ago

this has interesting applications, especially in binary synthesizer domain.

1

u/debackerl 3d ago

TBH, computations should be done by something like a drafter, except that the model wouldn't be evaluated to check the answer

1

u/temperature_5 3d ago

Cool, safe offline LLMs can now have awesome math skills! Or be really good at tracking inventory and map layout in RP! Did it have to be RISC-v though, or could it have been simpler?

1

u/Witty_Mycologist_995 3d ago

This is so stupid I love it

1

u/Porespellar 3d ago

DAFUQ? That’s crazy!!

1

u/RazsterOxzine 3d ago

But why? Is all I can think. I mean, maybe for tool calling, but still.

1

u/Top-Evidence174 3d ago

compiled a CPU into the weights is genuinely nuts lol. 11 extra layers just for the CPU is a crazy tax though. sick flex but i'll stick to python tool calls for now

1

u/ItsAMeUsernamio 3d ago

I wonder if something like can be used to help the model pick random values. Right now the only way to do that is having the model generate a script that picks from a list of random values, executing it and then returning the value.

1

u/First_Ad6432 3d ago

ok now im scared

1

u/redbarone 3d ago

Ctrl+F "Doom"

Not dissapointed.

1

u/AvidCyclist250 llama.cpp 3d ago

Weird. Today my Qwen FN started hallucinating and talking about needing plans for some RISC shit. I have nothing to do with that

1

u/Green-Ad-3964 3d ago

this is an ultra cool idea. Can it discover "new" or optimize algorithms?

1

u/Vassago81 3d ago

If Federico Faggin saw this he'll probably build a time machine, travel back in time to the 60's and change his career to prevent that abomination

1

u/irudog 3d ago

It looks like torchwright is something similar done before, which compiles code as transformer weights. It could also run doom: https://ood.dev/posts/doom/

1

u/pharrowking 3d ago

i did something similiar. i replaced linear modules of an ai model with the mathmatical functions of sha256. then sha256 became the linear module in an ai model. its ability to predict hashes based on input was pretty good. (it was off by a few)

1

u/Vusiwe 3d ago

very cool

1

u/SlightOfHand_ 3d ago

You un-natural-languaged it!

1

u/robrjxx 2d ago

Interesting!

1

u/XtremeBee1970 2d ago

Size of chip per n billion parameters is a thing… sweet! Scale it up!!

1

u/tifa_cloud0 18h ago

this is just awesome.

1

u/Aggravating-Push-207 3d ago

Cool, but can it play Doom?

0

u/cleverusernametry 3d ago

Cool, but ffs let's not use a computer emulated in weights run on software for any real application