Code Monkey home page Code Monkey logo

llama2.zig's Introduction

llama2.zig

This's just a work to reimplement llama2.c in Zig, also a toy project for me to explore Zig.

This repo would be more like a direct implementation to keep things simple and easy to understand (at least for myself).

If you are looking for a stable & fast implementations, please consider checking out cgbur/llama2.zig and clebert/llama2.zig!

Requirements

  • zig: 0.11.0

Build

# XXX: Currently the build have to look up `ztracy` even if it's dependency for
# development only, so you have to fetch the submodule once.
# $ git submodule update --init --recursive

$ zig build -Doptimize=ReleaseFast

Usage

Almost all arguments in llama2.c are supported except those ones related to chat mode:

# For stories15M, remember to download the model and tokenizer first:
# $ wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin -P models
# $ wget https://github.com/karpathy/llama2.c/raw/master/tokenizer.bin -P models

$ ./zig-out/bin/run models/stories15M.bin \
    -z models/tokenizer.bin -t 0.8 -n 256 -i "One day, Lily met a Shoggoth"

(if you want to compare the output with llama2.c, remember to specify an identical seed)

Tests

To run tests, it currently requires installing PyTorch to load checkpoint for checking whether weights are correctly mapped.

# Remember to download the model `stories15M.pt` (PyTorch model) first:
# wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.pt -P models

$ zig test tests.zig

Developments

If you want to profile the code, please fetch the submodules:

$ git submodule update --init --recursive

Then build the code with tracy enabled:

$ zig build -Doptimize=ReleaseFast -Duse_tracy=true

For further details, please checkout docs/INSTALL.md.

llama2.zig's People

Contributors

naleraphael avatar

Stargazers

 avatar

Watchers

 avatar  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.