ansuz / RIIR

why not Rewrite It In Rust
https://transitiontech.ca/random/RIIR
640 stars 6 forks source link

Rewrite ChatGPT in Rust #104

Closed HuangFuSL closed 1 year ago

HuangFuSL commented 1 year ago

Rewriting ChatGPT in Rust is not a trivial task, as it involves porting the Python code of ChatGPT to Rust, as well as adapting the model to use a different tensor library and backend. However, it is not impossible, and there are some resources that can help you get started.

One possible approach is to use the llm crate, which is an ecosystem of Rust libraries for working with large language models. It supports several GPT variants, including GPT-2 and GPT-J, and it is built on top of the ggml library for machine learning. You can find the documentation and examples of how to use llm on its GitHub repository.

Another possible approach is to use the femtoGPT crate, which is a pure Rust implementation of a minimal Generative Pretrained Transformer. It can be used for both inference and training of GPT-style language models using CPUs and GPUs. It is very similar to nanoGPT, which was explained by Andrej Karpathy in his video lecture. You can find the source code and instructions of how to use femtoGPT on its GitHub repository.

Both of these crates are still in development and may not have all the features and functionality of ChatGPT, but they can serve as a starting point for rewriting ChatGPT in Rust. You will need to have a good understanding of both Python and Rust, as well as the GPT architecture and its components, such as the transformer, the attention mechanism, the tokenizer, and the decoder. You will also need to have access to the pretrained weights of ChatGPT, which you can download from Hugging Face, and convert them to a format that can be loaded by ggml or femtoGPT.

I hope this answer helps you with your project. Good luck! 😊

image

image