Tutorial: Decentralized AI in 50 Lines of Python
Posted by iamtrask@reddit | Python | View on Reddit | 7 comments
Hi! I've been researching decentralized AI systems for about 10 years at Oxford/OpenMined/DeepMind, mostly the intersection between deep learning, cryptography, and distributed systems. One challenge i've learned in the community is that the deep learning folks don't know cryptography or distributed systems (and vice versa). I'm starting this new (from scratch) python tutorial series to help bridge that gap. This first tutorial builds a basic peer-to-peer AI system, which will be the foundation for later posts which get into more advanced techniques (e.g. secure enclaves, differential privacy, homomorphic encryption, etc.). I hope you enjoy it.
(note for mods: I made this tutorial by hand over the course of about 2 weeks.)
Link: https://iamtrask.github.io/2026/04/07/decentralized-ai-in-50-lines/
Jrix@reddit
Could I pay someone for access to a private folder? Say, $500 for watching history? $50,000 for their contacts.
Obviously yes, anyone can negotiate such a trade, but in this case, because it's AI serving as delegation in addition to being an interface for an entity's private data, AI can negotiate the economics (or whatever) on privacy.
Naively, you'd think you can just not give the AI the ability to change entity access rights, but why wouldn't you? You will be outcompeted by those that do, and if you're not in the business of competition (knitting meetup group of grandmas), what is one doing that is so important that a pollable AI needs to function "behind one's back"?
The mix of incentives and decision-making makes it such that the bulk of security ONLY MATTERS, with the assumption that a sandbox is not guaranteed.
If Harry has access to Ron's private folder and I Hermione want it, I can just go through Harry.
Ron also, like everyone, would prefer their secrets to be known by as much people as possible—assuming trustworthiness; trust is the enormous limiting factor, not incentive. Which can be exploited on the margins.
The only situations where such a decentralized fantasy world can make sense is in highly bespoke situations like fintech, where the delegating power of AI is just serving as a placeholder for future non-delegating algorithms.
All this does is create an information market, which is technically decentralized, but all markets are decentralized.
Particular-Plan1951@reddit
This is insanely cool, especially coming from someone who’s actually lived at the intersection of DL + crypto + distributed systems for a decade instead of just vibing with buzzwords. A “50 lines” peer-to-peer AI demo is exactly the kind of concrete example that makes these ideas click for people who get models but not networks, or vice versa
Henry_old@reddit
To move forward in 2026, we need to connect Crypto and Deep Learning. Many “AI” projects today are just centralized systems with a fancy name. In the high-frequency trading world, we’ve been managing distributed state and P2P streams for years, but often at the expense of security. I’m excited to hear your thoughts on secure enclaves. For those of us using proprietary algorithms on untrusted nodes, that’s what we’re really aiming for. Keeping the logic secure while still achieving sub-ms execution is the big challenge for 2026. This is a fantastic initiative!
SoftestCompliment@reddit
I see what you're getting at for a "part 1". It's a toy example which probably isn't going to be satisfying for this sub, but the most important part is how it illustrates basic user-level security in parts 6 & 7 and how that limits data exfiltration risk.
I think it's fine seeing the nuts and bolts for these examples, but for a daily driver pydantic-ai and other libraries will have qol features to interact with the model api, json, context history, tool calling loops, and so on.
semininja@reddit
Why would anyone want this?
Also, you spelled Gandhi's name wrong in your bloviating image attribution.
iamtrask@reddit (OP)
Eh... mostly for the fun of learning about what's going on in cryptography/deep learning/distributed systems but which isn't mainstream yet. This stuff won't be in prime-time AI products for at least 2-4 years. I suppose it's also useful for students looking to learn about tech which will be employable in around that timeframe. But to your point, this is niche content for now.
semininja@reddit
But what is the actual use case for this combination of ... stuff?