R port of llama2.c

[This article was first published on T. Moudiki's Webpage - R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This is a post about the R port of llama2.c, a C implementation of a language model. The post includes installation instructions, code examples, and steps to run a Shiny app for experimenting with the model.

Code available at: https://github.com/thierrymoudiki/llama2r/tree/main

R port of llama2.c (https://github.com/karpathy/llama2.c)

Code and Shiny app for educational purpose. Experiment with temperature.

image-title-here

Install

devtools::install_github("thierrymoudiki/llama2r")

Code example in vignettes/getting-started.Rmd.

Shiny app

In /vignettes/app.R

Reproducible steps

Step 1: Prepare the C Code

Clone the Repository:

git clone https://github.com/karpathy/llama2.c.git
cd llama2.c

Step 2: Compile the C Code:

gcc -Ofast run.c -lm -o run

Step 3: Download a Pretrained Model:

wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories42M.bin

Step 4: Download the Tokenizer:

wget https://huggingface.co/karpathy/tinyllamas/resolve/main/tokenizer.bin

Step 5: Packaging

The .bins are stored in inst/bin

Step 6: Run the Shiny App

library(shiny)
library(llama2r)
runApp(system.file("vignettes", "app.R", package = "llama2r"))
To leave a comment for the author, please follow the link and comment on their blog: T. Moudiki's Webpage - R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)