Skip to content

Commit

Permalink
a GGUF parser that works on remotely hosted files (over HTTP range re…
Browse files Browse the repository at this point in the history
…quests) (#540)

GGUF is the new single-file weights format that's been taking the Hub by
storm...

<img width="476" alt="image"
src="https://github.com/huggingface/huggingface.js/assets/326577/946b3a6c-6392-46fd-967f-3ea74412ac7d">

## Spec

https://github.com/ggerganov/ggml/blob/master/docs/gguf.md

Reference implementation (Python):
https://github.com/ggerganov/llama.cpp/blob/master/gguf-py/gguf/gguf_reader.py

## Acknowledgements & Inspirations

- https://github.com/hyparam/hyllama by @platypii (MIT license)
- https://github.com/ahoylabs/gguf.js by @biw @dkogut1996 @spencekim
(MIT license)
- might also be of interest to: @yagil

---------

Co-authored-by: Mishig <[email protected]>
Co-authored-by: Mishig Davaadorj <[email protected]>
  • Loading branch information
3 people committed Mar 13, 2024
1 parent ce98503 commit 7359058
Show file tree
Hide file tree
Showing 20 changed files with 703 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/agents-publish.yml
Expand Up @@ -33,7 +33,7 @@ jobs:
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
cache: "pnpm"
cache-dependency-path: |
packages/agents/pnpm-lock.yaml
Expand All @@ -59,7 +59,7 @@ jobs:
# hack - reuse actions/setup-node@v3 just to set a new registry
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
registry-url: "https://npm.pkg.github.com"
- run: pnpm publish --no-git-checks .
env:
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/gguf-publish.yml
@@ -0,0 +1,63 @@
name: GGUF - Version and Release

on:
workflow_dispatch:
inputs:
newversion:
type: choice
description: "Semantic Version Bump Type"
default: patch
options:
- patch
- minor
- major

concurrency:
group: "push-to-main"

defaults:
run:
working-directory: packages/gguf

jobs:
version_and_release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# Needed to push the tag and the commit on the main branch, otherwise we get:
# > Run git push --follow-tags
# remote: error: GH006: Protected branch update failed for refs/heads/main.
# remote: error: Changes must be made through a pull request. Required status check "lint" is expected.
token: ${{ secrets.BOT_ACCESS_TOKEN }}
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: "20"
cache: "pnpm"
cache-dependency-path: |
packages/gguf/pnpm-lock.yaml
# setting a registry enables the NODE_AUTH_TOKEN env variable where we can set an npm token. REQUIRED
registry-url: "https://registry.npmjs.org"
- run: pnpm install
- run: git config --global user.name machineuser
- run: git config --global user.email [email protected]
- run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
BUMPED_VERSION=$(node -p "require('semver').inc('$PACKAGE_VERSION', '${{ github.event.inputs.newversion }}')")
# Update package.json with the new version
node -e "const fs = require('fs'); const package = JSON.parse(fs.readFileSync('./package.json')); package.version = '$BUMPED_VERSION'; fs.writeFileSync('./package.json', JSON.stringify(package, null, '\t') + '\n');"
git commit . -m "🔖 @hugginface/gguf $BUMPED_VERSION"
git tag "gguf-v$BUMPED_VERSION"
- run: pnpm publish --no-git-checks .
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: git pull --rebase && git push --follow-tags
# hack - reuse actions/setup-node@v3 just to set a new registry
- uses: actions/setup-node@v3
with:
node-version: "20"
registry-url: "https://npm.pkg.github.com"
- run: pnpm publish --no-git-checks .
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/hub-publish.yml
Expand Up @@ -33,7 +33,7 @@ jobs:
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
cache: "pnpm"
cache-dependency-path: |
packages/hub/pnpm-lock.yaml
Expand All @@ -59,7 +59,7 @@ jobs:
# hack - reuse actions/setup-node@v3 just to set a new registry
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
registry-url: "https://npm.pkg.github.com"
- run: pnpm publish --no-git-checks .
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/inference-publish.yml
Expand Up @@ -33,7 +33,7 @@ jobs:
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
cache: "pnpm"
cache-dependency-path: |
packages/inference/pnpm-lock.yaml
Expand All @@ -59,7 +59,7 @@ jobs:
# hack - reuse actions/setup-node@v3 just to set a new registry
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
registry-url: "https://npm.pkg.github.com"
- run: pnpm publish --no-git-checks .
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/jinja-publish.yml
Expand Up @@ -33,7 +33,7 @@ jobs:
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
cache: "pnpm"
cache-dependency-path: |
packages/jinja/pnpm-lock.yaml
Expand All @@ -56,7 +56,7 @@ jobs:
# hack - reuse actions/setup-node@v3 just to set a new registry
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
registry-url: "https://npm.pkg.github.com"
- run: pnpm publish --no-git-checks .
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/languages-publish.yml
Expand Up @@ -33,7 +33,7 @@ jobs:
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
cache: "pnpm"
cache-dependency-path: |
packages/languages/pnpm-lock.yaml
Expand All @@ -56,7 +56,7 @@ jobs:
# hack - reuse actions/setup-node@v3 just to set a new registry
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
registry-url: "https://npm.pkg.github.com"
- run: pnpm publish --no-git-checks .
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Expand Up @@ -29,7 +29,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
cache: "pnpm"
cache-dependency-path: "**/pnpm-lock.yaml"
- run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tasks-publish.yml
Expand Up @@ -33,7 +33,7 @@ jobs:
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
cache: "pnpm"
cache-dependency-path: |
packages/tasks/pnpm-lock.yaml
Expand All @@ -56,7 +56,7 @@ jobs:
# hack - reuse actions/setup-node@v3 just to set a new registry
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
registry-url: "https://npm.pkg.github.com"
- run: pnpm publish --no-git-checks .
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -29,7 +29,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
cache: "pnpm"
cache-dependency-path: "**/pnpm-lock.yaml"
- run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/widgets-publish.yml
Expand Up @@ -33,7 +33,7 @@ jobs:
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
cache: "pnpm"
cache-dependency-path: |
packages/widgets/pnpm-lock.yaml
Expand Down Expand Up @@ -168,7 +168,7 @@ jobs:
# hack - reuse actions/setup-node@v3 just to set a new registry
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
registry-url: "https://npm.pkg.github.com"
- run: pnpm publish --no-git-checks .
env:
Expand Down
4 changes: 4 additions & 0 deletions packages/gguf/.prettierignore
@@ -0,0 +1,4 @@
pnpm-lock.yaml
# In order to avoid code samples to have tabs, they don't display well on npm
README.md
dist
17 changes: 17 additions & 0 deletions packages/gguf/README.md
@@ -0,0 +1,17 @@
# `@huggingface/gguf`

A GGUF parser that works on remotely hosted files.

## Spec

https://github.com/ggerganov/ggml/blob/master/docs/gguf.md

Reference implementation (Python): https://github.com/ggerganov/llama.cpp/blob/master/gguf-py/gguf/gguf_reader.py

## Acknowledgements & Inspirations

- https://github.com/hyparam/hyllama by @platypii (MIT license)
- https://github.com/ahoylabs/gguf.js by @biw @dkogut1996 @spencekim (MIT license)

🔥❤️

51 changes: 51 additions & 0 deletions packages/gguf/package.json
@@ -0,0 +1,51 @@
{
"name": "@huggingface/gguf",
"packageManager": "[email protected]",
"version": "0.0.1",
"description": "a GGUF parser that works on remotely hosted files",
"repository": "https://github.com/huggingface/huggingface.js.git",
"publishConfig": {
"access": "public"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
}
},
"browser": {
"./dist/index.js": "./dist/browser/index.js",
"./dist/index.mjs": "./dist/browser/index.mjs"
},
"engines": {
"node": ">=20"
},
"source": "index.ts",
"scripts": {
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
"lint:check": "eslint --ext .cjs,.ts .",
"format": "prettier --write .",
"format:check": "prettier --check .",
"prepublishOnly": "pnpm run build",
"build": "tsup src/index.ts --format cjs,esm --clean --dts",
"test": "vitest run",
"check": "tsc"
},
"files": [
"dist",
"src",
"tsconfig.json"
],
"keywords": [
"huggingface",
"hub",
"gguf"
],
"author": "Hugging Face",
"license": "MIT",
"devDependencies": {}
}
1 change: 1 addition & 0 deletions packages/gguf/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7359058

Please sign in to comment.