# AI player on ICP - IChess

**URL:** <https://forum.dfinity.org/t/ai-player-on-icp-ichess/34839>\
**Category:** Showcase\
**Tags:** Functional-Programming, Discussing, community-consideration\
**Created:** [September 7, 2024, 9:31am UTC](https://forum.dfinity.org/t/ai-player-on-icp-ichess/34839 "2024-09-07T09:31:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![laska189345938458347](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/laska189345938458347/32/13364_2.png) [@laska189345938458347](https://forum.dfinity.org/u/laska189345938458347)\
**Post date:** [September 7, 2024, 9:31am UTC](https://forum.dfinity.org/t/ai-player-on-icp-ichess/34839/1 "2024-09-07T09:31:31Z")

</div>

![IChess](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/3X/6/d/6db2c6224623778e4623d58cf3a40e294ffd0a94.jpeg)  
**Overview:**  
The On-Chain Chess LLM project showcases the capability of running a fully functional Large Language Model (LLM) directly on the Internet Computer Protocol (ICP) canister system. This project aims to demonstrate the potential of blockchain-based AI by focusing on chess, where the LLM interprets chess positions and generates legal moves. The project is tailored for chess enthusiasts, developers interested in AI and blockchain integration, and anyone curious about the application of advanced AI models in decentralized environments.

 ![Screenshot 2024-09-03 at 7.16.43 AM](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/3X/f/c/fca6d7b92862b3e48e261765d96c35ab587ace40.jpeg)

**Web3 vs. Web2:|**  
While there are numerous chess engines and AI models available on traditional platforms (Web2), this project stands out by being fully on-chain, which ensures:  
• Transparency: All computations are visible and verifiable by any participant.  
• Security: Running the LLM on-chain reduces the risk of tampering or unauthorized access.  
• Decentralization: Unlike centralized systems, there’s no single point of failure, enhancing reliability and trustworthiness.

**Technical Stack:**  
• Base Model: LLaMA2 (compressed variant)  
• Training Data: Synthesized and cleaned chess data  
• Environment Simulation: Custom-built chess environment for model training  
• Backend Language: C++  
• Deployment: ICP canister system  
• Input Format: Forsyth–Edwards Notation (FEN) for chess positions

**Architecture & Design Decisions:**  
• The LLM has been compressed to fit within the storage and computation limits of an ICP canister.  
• A high-performance C++ backend was chosen for model execution to ensure that the LLM operates efficiently within the blockchain’s constraints.  
•The design prioritizes minimal resource usage while maintaining accurate chess move generation.

**Key ICP Features Utilized:**  
• Scalability: The ICP’s ability to handle multiple requests efficiently allows the LLM to process chess positions at scale.  
• Security: The deterministic nature of the ICP ensures that AI inferences are consistent and tamperproof.  
• Interoperability: The ICP allows seamless integration with other on-chain services, paving the way for potential expansions like on-chain chess tournaments.

**Resources:**  
[Frontend Canister](https://cirh4-aiaaa-aaaan-qmvqa-cai.icp0.io/)  
[Backend Canister](https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.icp0.io/?id=huk5z-laaaa-aaaan-qmvpq-cai)

[Project Repository](https://github.com/bridge-23/IChessAI)  
[ICP LLM Project](https://github.com/bridge-23/chess23/tree/main/models)  
[Discord](https://discord.gg/H2RCdvneyp)  
[X](https://x.com/bridge23app)  
[Telegram Channel](https://t.me/ChanellBridge23app)  
[TMA](https://t.me/bridge23bot/bridge23app?startapp=inv_5211582231)

**Check our additional show cases on Forum:**

[Data Portfolio app](https://forum.dfinity.org/t/bridge23-app-showcase/33926)

[DPOS:](https://forum.dfinity.org/t/gate23-showcase-by-bridge23-team/33872)

---

<div class="post-metadata">

**Author:** ![icpp](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icpp/32/9310_2.png) [@icpp](https://forum.dfinity.org/u/icpp)\
**Post date:** [September 8, 2024, 11:37pm UTC](https://forum.dfinity.org/t/ai-player-on-icp-ichess/34839/2 "2024-09-08T23:37:42Z")

</div>

Congrats!

Very interesting and innovative work to use a specialized on-chain LLM to predict the chess moves.

I have a few questions:

- How did you generate the training data?
- Did you use the 15M parameter model?
- Do you feel you have sufficient training data for a bigger model?

---

<div class="post-metadata">

**Author:** ![laughtt](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/laughtt/32/19402_2.png) [@laughtt](https://forum.dfinity.org/u/laughtt)\
**Post date:** [September 9, 2024, 2:37am UTC](https://forum.dfinity.org/t/ai-player-on-icp-ichess/34839/3 "2024-09-09T02:37:55Z")

</div>

Hi!, It was indeed a really fun project, we trained for a couple of hours with a set of games that a chess simulator created , we used the 15M model. And yes we have sufficiend data for bigger model but we had only around 24 hours for the hackaton so we had no more time to test extra things.

---

<div class="post-metadata">

**Author:** ![balizerodev](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/balizerodev/32/19436_2.png) [@balizerodev](https://forum.dfinity.org/u/balizerodev)\
**Post date:** [September 9, 2024, 1:48pm UTC](https://forum.dfinity.org/t/ai-player-on-icp-ichess/34839/4 "2024-09-09T13:48:37Z")

</div>

Wow so good inovation come from Hackaton and only 24 hours, I think you’re finished the model need one 3-4 days. Amazing #ICP now already trully only one running AI onchain  
please notice this guys @domwoe @jennifertran  
maybe can help another innovation AI for ICP after DecideAI

---

<div class="post-metadata">

**Author:** ![icpp](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icpp/32/9310_2.png) [@icpp](https://forum.dfinity.org/u/icpp)\
**Post date:** [September 9, 2024, 2:30pm UTC](https://forum.dfinity.org/t/ai-player-on-icp-ichess/34839/5 "2024-09-09T14:30:16Z")

</div>

@laughtt ,  
that is very impressive you did this all during a hackathon!

Feel free to ping me for additional discussion. I have a fine-tuning pipeline for that model as well, and we can compare notes.

---

<div class="post-metadata">

**Author:** ![wirapratamaz](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/wirapratamaz/32/19460_2.png) [@wirapratamaz](https://forum.dfinity.org/u/wirapratamaz)\
**Post date:** [September 9, 2024, 2:52pm UTC](https://forum.dfinity.org/t/ai-player-on-icp-ichess/34839/6 "2024-09-09T14:52:37Z")

</div>

Wow with fine-tuning pipeline I think we can leverage new innovation AI again for ICP 🤣

---

<div class="post-metadata">

**Author:** ![laska189345938458347](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/laska189345938458347/32/13364_2.png) [@laska189345938458347](https://forum.dfinity.org/u/laska189345938458347)\
**Post date:** [September 9, 2024, 3:01pm UTC](https://forum.dfinity.org/t/ai-player-on-icp-ichess/34839/7 "2024-09-09T15:01:32Z")

</div>

Wow, is great i text you in X

---

<div class="post-metadata">

**Author:** ![icpp](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icpp/32/9310_2.png) [@icpp](https://forum.dfinity.org/u/icpp)\
**Post date:** [September 9, 2024, 3:16pm UTC](https://forum.dfinity.org/t/ai-player-on-icp-ichess/34839/8 "2024-09-09T15:16:27Z")

</div>

Not yet fine-tuning on ICP, although that is also a goal. We train/fine-tune off chain right now.

I am looking into [GitHub - karpathy/llm.c: LLM training in simple, raw C/CUDA](https://github.com/karpathy/llm.c) , but you really need a GPU for that.

That llm.c can definitely be used to train your chess game.

---

<div class="post-metadata">

**Author:** ![jennifertran](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jennifertran/32/11558_2.png) [@jennifertran](https://forum.dfinity.org/u/jennifertran)\
**Post date:** [October 8, 2024, 9:08pm UTC](https://forum.dfinity.org/t/ai-player-on-icp-ichess/34839/9 "2024-10-08T21:08:07Z")

</div>

What is the frontend canister supposed to demo?

---

<div class="post-metadata">

**Author:** ![laska189345938458347](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/laska189345938458347/32/13364_2.png) [@laska189345938458347](https://forum.dfinity.org/u/laska189345938458347)\
**Post date:** [October 9, 2024, 8:27am UTC](https://forum.dfinity.org/t/ai-player-on-icp-ichess/34839/10 "2024-10-09T08:27:40Z")

</div>

Demonstrates your moves and the moves of the AI ​​player, the main point is that this model works inside the canister and does not make requests to Open AI or AWS, but works entirely on the Internet Computer.
