MCPcopy Index your code
hub / github.com/cztomsik/ggml-js

github.com/cztomsik/ggml-js @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
112 symbols 250 edges 23 files 40 documented · 36%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

This project is temporarily on hold.\ I am now working on Ava, Personal Language Server, a GUI app for running LLMs.

ggml-js

JavaScript bindings for the GGML library, a fast and lightweight tensor/machine-learning library implemented in C.

RWKV example

https://user-images.githubusercontent.com/3526922/236536800-fca4d729-3479-471a-aea5-2d0ae5df3fdf.mov

Installation

You can install ggml-js via npm:

npm install ggml-js

Basic Usage

Here's an example of how to use ggml-js in your JavaScript code:

import { Context, F } from 'ggml-js/core'

// Create context, two 1D tensors and multiply them
const ctx = Context.init()
const a = ctx.newTensor1D('f32', 1)
const b = ctx.newTensor1D('f32', 1)
const ab = F.mul(a, b)

// Build the computation graph
const graph = ctx.buildForward(ab)

// Set values & compute the graph
a.set(0, 1.5)
b.set(0, 2)
graph.compute()

// Get result
console.log(ab.get(0))

Advanced Usage

ggml-js also provides modules for working with pre-trained models and tokenizers. Here's an example of how to use the RWKV model and BPETokenizer:

import { RWKV } from 'ggml-js/llms'
import { BPETokenizer } from 'ggml-js/tokenizers'

// see examples/rwkv.js for full example
const model = RWKV.loadFromFile(...)
const tokenizer = BPETokenizer.loadFromFile(...)

for (const t of model.generate(tokenizer.encode('Hello world!'))) {
  process.stdout.write(tokenizer.decodeOne(t))
}

Building From Source

If you want to build ggml-js from source, you can clone the repository and run the following commands:

zig build

License

This project is licensed under the MIT License.

This project bundles GGML library by Georgi Gerganov, which is also licensed under the MIT License.

Core symbols most depended-on inside this repo

newTensor
called by 18
lib/core/context.js
callOp
called by 17
lib/core/context.js
unaryOp
called by 16
lib/core/functional.js
forward
called by 12
lib/llms/rwkv.js
set
called by 11
lib/core/tensor.js
forward
called by 10
lib/llms/gpt-neox.js
loadFromFile
called by 9
lib/core/model.js
binaryOp
called by 7
lib/core/functional.js

Shape

Method 65
Class 38
Function 9

Languages

TypeScript100%

Modules by API surface

lib/llms/rwkv.js18 symbols
lib/llms/gpt-neox.js17 symbols
lib/core/tensor.js15 symbols
lib/core/context.js13 symbols
lib/core/layers.js12 symbols
lib/tokenizers/bpe-tokenizer.js8 symbols
lib/core/model.js7 symbols
lib/core/functional.js7 symbols
lib/tokenizers/tokenizer.js6 symbols
lib/llms/causal.js5 symbols
lib/core/module.js3 symbols
lib/core/native.js1 symbols

For agents

$ claude mcp add ggml-js \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact