Giter VIP home page Giter VIP logo

llama2.js's Introduction

llama2.js npm

llama2.js

A Fork of llama2.js rewritten to be usefull as a library and perhaps add some other functionalities in the future.

A pure JavaScript port of Karpathy's llama2.c with a simple UI.

How to run

  1. Download Karpathy's Llama2 (Orig instructions) parameters pretrained on TinyStories dataset
wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin
wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories42M.bin
wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories110M.bin
  1. Open run.html via a WebServer

Usage

import { loadVocab, readCheckpoint, generator } from "llama2js"
import * as process from 'process'
import * as fs from 'fs'

async function init() {
    const model = fs.readFileSync('pathto/stories15m.bin')
    readCheckpoint(model.buffer)
    const tokenizer = fs.readFileSync('pathto/tokenizer.bin')
    loadVocab(tokenizer.buffer)

    generate()
}

async function generate() {
    const iterator = await generator({
        prompt: "Once upon a time, there was a"
    })

    while (true) {
        const { value, done } = await iterator.next() 
        if (done) {
            console.log(value)
            break
        }
        process.stdout.write(value.next)
    }
}

init()

License

MIT

llama2.js's People

Contributors

karpathy avatar jellehak avatar richinseattle avatar epicure avatar tairov avatar aegkmq avatar luigifcruz avatar nikolaydubina avatar awgu avatar danielgross avatar leloykun avatar krzysztof-jusiak avatar sumo43 avatar kroggen avatar emma-eva avatar slyecho avatar manuel030 avatar mcognetta avatar tatellos avatar richardscottoz avatar som-sama avatar tmc avatar wsmoses avatar hu-po avatar madroidmaq avatar python273 avatar vovw avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.