Skip to content

Commit 2c3c6c2

Browse files
committed
Merge branch 'main' into patch-4
2 parents 8557110 + 678eba8 commit 2c3c6c2

File tree

146 files changed

+6264
-576
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+6264
-576
lines changed

.github/workflows/lint.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ jobs:
4242
4343
- name: "Checking format errors"
4444
run: |
45-
pnpm --filter ...[${{ steps.since.outputs.SINCE }}] format:check
45+
# Could also use pnpm --filter [${{ steps.since.outputs.SINCE }}] format:check
46+
# But this way we can see the diff
47+
pnpm --filter [${{ steps.since.outputs.SINCE }}] format
48+
git diff | head -n 100
49+
git diff --name-only --exit-code
4650
4751
- name: Check types
4852
run: pnpm --filter ...[${{ steps.since.outputs.SINCE }}] check
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Space-header - Version and Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
newversion:
7+
type: choice
8+
description: "Semantic Version Bump Type"
9+
default: patch
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
15+
concurrency:
16+
group: "push-to-main"
17+
18+
defaults:
19+
run:
20+
working-directory: packages/space-header
21+
22+
jobs:
23+
version_and_release:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v3
27+
with:
28+
# Needed to push the tag and the commit on the main branch, otherwise we get:
29+
# > Run git push --follow-tags
30+
# remote: error: GH006: Protected branch update failed for refs/heads/main.
31+
# remote: error: Changes must be made through a pull request. Required status check "lint" is expected.
32+
token: ${{ secrets.BOT_ACCESS_TOKEN }}
33+
- run: corepack enable
34+
- uses: actions/setup-node@v3
35+
with:
36+
node-version: "20"
37+
cache: "pnpm"
38+
cache-dependency-path: |
39+
packages/space-header/pnpm-lock.yaml
40+
# setting a registry enables the NODE_AUTH_TOKEN env variable where we can set an npm token. REQUIRED
41+
registry-url: "https://registry.npmjs.org"
42+
- run: pnpm install
43+
- run: git config --global user.name machineuser
44+
- run: git config --global user.email [email protected]
45+
- run: |
46+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
47+
BUMPED_VERSION=$(node -p "require('semver').inc('$PACKAGE_VERSION', '${{ github.event.inputs.newversion }}')")
48+
# Update package.json with the new version
49+
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');"
50+
git commit . -m "🔖 @hugginface/space-header $BUMPED_VERSION"
51+
git tag "space-header-v$BUMPED_VERSION"
52+
- run: pnpm publish --no-git-checks .
53+
env:
54+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
55+
- run: git pull --rebase && git push --follow-tags
56+
# hack - reuse actions/setup-node@v3 just to set a new registry
57+
- uses: actions/setup-node@v3
58+
with:
59+
node-version: "20"
60+
registry-url: "https://npm.pkg.github.com"
61+
- run: pnpm publish --no-git-checks .
62+
env:
63+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
- name: "Update Doc"
65+
uses: peter-evans/repository-dispatch@v2
66+
with:
67+
event-type: doc-build

.github/workflows/sync-widgets-demo.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
name: Sync Widgets Demo
22
on:
33
workflow_dispatch:
4-
push:
5-
branches:
6-
- main
7-
paths:
8-
- "packages/widgets/**"
9-
- "packages/tasks/**"
10-
- "package.json"
11-
- "pnpm-lock.yaml"
12-
- ".github/workflows/sync-widgets-demo.yml"
4+
# push:
5+
# branches:
6+
# - main
7+
# paths:
8+
# - "packages/widgets/**"
9+
# - "packages/tasks/**"
10+
# - "package.json"
11+
# - "pnpm-lock.yaml"
12+
# - ".github/workflows/sync-widgets-demo.yml"
1313

1414
jobs:
1515
sync:

.github/workflows/trufflehog.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Secret Leaks
2+
3+
on:
4+
push:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
trufflehog:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
- name: Secret Scanning
18+
uses: trufflesecurity/trufflehog@main

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
"editor.defaultFormatter": "esbenp.prettier-vscode"
1414
},
1515
"cSpell.words": ["huggingface"],
16-
"deno.enablePaths": ["./e2e/deno"]
16+
"deno.enablePaths": ["./e2e/deno"],
17+
"typescript.tsdk": "node_modules/typescript/lib"
1718
}

CODEOWNERS

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
# Ownership for the Tasks Package
66

7-
/packages/tasks/ @osanseviero @SBrandeis @gary149 @Wauplin @julien-c
8-
9-
# Ownership for the Widgets Package
10-
11-
/packages/widgets/ @mishig25 @SBrandeis
7+
/packages/tasks/ @osanseviero @SBrandeis @gary149 @Wauplin @julien-c @pcuenca
128

139
# Ownership for the Hub Package
1410

@@ -25,3 +21,6 @@
2521
# Ownership for the gguf Package
2622

2723
/packages/gguf @mishig25 @julien-c
24+
25+
# Ownership for the space-header Package
26+
/packages/space-header @enzostvs

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ This is a collection of JS libraries to interact with the Hugging Face API, with
5454
- [@huggingface/agents](packages/agents/README.md): Interact with HF models through a natural language interface
5555
- [@huggingface/gguf](packages/gguf/README.md): A GGUF parser that works on remotely hosted files.
5656
- [@huggingface/tasks](packages/tasks/README.md): The definition files and source-of-truth for the Hub's main primitives like pipeline tasks, model libraries, etc.
57+
- [@huggingface/space-header](packages/space-header/README.md): Use the Space `mini_header` outside Hugging Face
5758

5859

5960
We use modern features to avoid polyfills and dependencies, so the libraries will only work on modern browsers / Node.js >= 18 / Bun / Deno.
@@ -87,7 +88,7 @@ You can run our packages with vanilla JS, without any bundler, by using a CDN or
8788

8889
```html
8990
<script type="module">
90-
import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/inference@2.7.0/+esm';
91+
import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/inference@2.8.0/+esm';
9192
import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm";
9293
</script>
9394
```

docs/_toctree.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@
2121
title: Use Agents to run multi-modal workflows from a natural language API
2222
- local: agents/modules
2323
title: API Reference
24+
- title: "@huggingface/space-header"
25+
isExpanded: true
26+
sections:
27+
- local: space-header/README
28+
title: Use Space mini_header in your app
29+
- title: "@huggingface/gguf"
30+
isExpanded: true
31+
sections:
32+
- local: gguf/README
33+
title: Parse local and remote GGUF files

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"eslint-config-prettier": "^9.0.0",
1818
"eslint-plugin-prettier": "^4.2.1",
1919
"eslint-plugin-svelte": "^2.30.0",
20+
"npm-run-all": "^4.1.5",
2021
"prettier": "^3.1.0",
2122
"prettier-plugin-svelte": "^3.1.2",
2223
"semver": "^7.5.0",

packages/doc-internal/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
"description": "Package to generate doc for other @huggingface packages",
66
"private": true,
77
"scripts": {
8-
"start": "pnpm run fix-cdn-versions && pnpm run doc-hub && pnpm run doc-inference && pnpm run doc-agents && cp ../../README.md ../../docs/index.md && pnpm run update-toc && pnpm run fix-md-links && pnpm run fix-md-headinghashlinks",
8+
"start": "pnpm run fix-cdn-versions && pnpm run doc-hub && pnpm run doc-inference && pnpm run doc-agents && pnpm run doc-space-header && pnpm run doc-gguf && cp ../../README.md ../../docs/index.md && pnpm run update-toc && pnpm run fix-md-links && pnpm run fix-md-headinghashlinks",
99
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
1010
"lint:check": "eslint --ext .cjs,.ts .",
1111
"format": "prettier --write .",
1212
"format:check": "prettier --check .",
1313
"doc-hub": "typedoc --tsconfig ../hub/tsconfig.json --githubPages false --plugin typedoc-plugin-markdown --out ../../docs/hub --hideBreadcrumbs --hideInPageTOC --sourceLinkTemplate https://github.com/huggingface/huggingface.js/blob/main/{path}#L{line} ../hub/index.ts",
1414
"doc-inference": "typedoc --tsconfig ../inference/tsconfig.json --githubPages false --plugin typedoc-plugin-markdown --out ../../docs/inference --hideBreadcrumbs --hideInPageTOC --sourceLinkTemplate https://github.com/huggingface/huggingface.js/blob/main/{path}#L{line} ../inference/src/index.ts",
1515
"doc-agents": "typedoc --tsconfig ../agents/tsconfig.json --githubPages false --plugin typedoc-plugin-markdown --out ../../docs/agents --hideBreadcrumbs --hideInPageTOC --sourceLinkTemplate https://github.com/huggingface/huggingface.js/blob/main/{path}#L{line} ../agents/src/index.ts",
16+
"doc-gguf": "mkdir -p ../../docs/gguf && cp ../../packages/gguf/README.md ../../docs/gguf/README.md",
17+
"doc-space-header": "mkdir -p ../../docs/space-header && cp ../../packages/space-header/README.md ../../docs/space-header/README.md",
1618
"update-toc": "tsx update-toc.ts",
1719
"fix-cdn-versions": "tsx fix-cdn-versions.ts",
1820
"fix-md-links": "tsx fix-md-links.ts",

packages/gguf/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@huggingface/gguf",
33
"packageManager": "[email protected]",
4-
"version": "0.1.5",
4+
"version": "0.1.10",
55
"description": "a GGUF parser that works on remotely hosted files",
66
"repository": "https://github.com/huggingface/huggingface.js.git",
77
"publishConfig": {

packages/gguf/scripts/generate-llm.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { writeFileSync } from "node:fs";
77

8-
const SOURCE_CPP_URL = "https://raw.githubusercontent.com/ggerganov/llama.cpp/master/llama.cpp";
8+
const SOURCE_CPP_URL = "https://raw.githubusercontent.com/ggerganov/llama.cpp/master/src/llama.cpp";
99
const DEST_FILE_PATH = "./src/transformer-llm.ts";
1010
const DEST_COMMON_SOURCE = `
1111
/** This file is auto-generated by generate-llm.ts */
@@ -80,6 +80,20 @@ const KV_TYPE = {
8080
LLM_KV_SSM_STATE_SIZE: "number",
8181
LLM_KV_SSM_TIME_STEP_RANK: "number",
8282
LLM_KV_LOGIT_SCALE: "number",
83+
LLM_KV_EXPERT_FEED_FORWARD_LENGTH: "number",
84+
LLM_KV_EXPERT_SHARED_FEED_FORWARD_LENGTH: "number",
85+
LLM_KV_ATTENTION_SLIDING_WINDOW: "number",
86+
LLM_KV_ATTN_LOGIT_SOFTCAPPING: "number",
87+
LLM_KV_FINAL_LOGIT_SOFTCAPPING: "number",
88+
LLM_KV_LEADING_DENSE_BLOCK_COUNT: "number",
89+
LLM_KV_ATTENTION_KV_LORA_RANK: "number",
90+
LLM_KV_EXPERT_SHARED_COUNT: "number",
91+
LLM_KV_EXPERT_WEIGHTS_SCALE: "number",
92+
LLM_KV_ROPE_SCALING_YARN_LOG_MUL: "number",
93+
LLM_KV_ATTENTION_Q_LORA_RANK: "number",
94+
LLM_KV_ATTENTION_RELATIVE_BUCKETS_COUNT: "number",
95+
LLM_KV_DECODER_START_TOKEN_ID: "number",
96+
LLM_KV_USE_PARALLEL_RESIDUAL: "boolean",
8397
};
8498

8599
interface Arch {
@@ -199,7 +213,12 @@ async function main() {
199213
if (a.hparams.length) {
200214
code += [
201215
" & {",
202-
...a.hparams.map((k) => `\t${JSON.stringify(constToKVName[k].replace("%s", a.name))}: ${KV_TYPE[k]},`),
216+
...a.hparams.map((k) => {
217+
if (!KV_TYPE[k]) {
218+
throw new Error(`Cannot find type definition of ${k}`);
219+
}
220+
return `\t${JSON.stringify(constToKVName[k].replace("%s", a.name))}: ${KV_TYPE[k]},`;
221+
}),
203222
"};",
204223
].join("\n");
205224
} else {

packages/gguf/src/gguf.spec.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { describe, expect, it } from "vitest";
2-
import { GGMLQuantizationType, gguf, ggufAllShards, parseGgufShardFilename } from "./gguf";
1+
import { beforeAll, describe, expect, it } from "vitest";
2+
import type { GGUFParseOutput } from "./gguf";
3+
import { GGMLFileQuantizationType, GGMLQuantizationType, gguf, ggufAllShards, parseGgufShardFilename } from "./gguf";
34
import fs from "node:fs";
45

56
const URL_LLAMA = "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/191239b/llama-2-7b-chat.Q2_K.gguf";
@@ -12,8 +13,21 @@ const URL_V1 =
1213
"https://huggingface.co/tmadge/testing/resolve/66c078028d1ff92d7a9264a1590bc61ba6437933/tinyllamas-stories-260k-f32.gguf";
1314
const URL_SHARDED_GROK =
1415
"https://huggingface.co/Arki05/Grok-1-GGUF/resolve/ecafa8d8eca9b8cd75d11a0d08d3a6199dc5a068/grok-1-IQ3_XS-split-00001-of-00009.gguf";
16+
const URL_BIG_METADATA = "https://huggingface.co/ngxson/test_gguf_models/resolve/main/gguf_test_big_metadata.gguf";
1517

1618
describe("gguf", () => {
19+
beforeAll(async () => {
20+
// download the gguf for "load file" test, save to .cache directory
21+
if (!fs.existsSync(".cache")) {
22+
fs.mkdirSync(".cache");
23+
}
24+
if (!fs.existsSync(".cache/model.gguf")) {
25+
const res = await fetch(URL_BIG_METADATA);
26+
const arrayBuf = await res.arrayBuffer();
27+
fs.writeFileSync(".cache/model.gguf", Buffer.from(arrayBuf));
28+
}
29+
});
30+
1731
it("should parse a llama2 7b", async () => {
1832
const { metadata, tensorInfos } = await gguf(URL_LLAMA);
1933

@@ -25,7 +39,7 @@ describe("gguf", () => {
2539
tensor_count: 291n,
2640
kv_count: 19n,
2741
"general.architecture": "llama",
28-
"general.file_type": 10,
42+
"general.file_type": GGMLFileQuantizationType.MOSTLY_Q2_K,
2943
"general.name": "LLaMA v2",
3044
"general.quantization_version": 2,
3145
"llama.attention.head_count": 32,
@@ -84,7 +98,7 @@ describe("gguf", () => {
8498
tensor_count: 291n,
8599
kv_count: 24n,
86100
"general.architecture": "llama",
87-
"general.file_type": 17,
101+
"general.file_type": GGMLFileQuantizationType.MOSTLY_Q5_K_M,
88102
"general.name": "mistralai_mistral-7b-instruct-v0.2",
89103
"general.quantization_version": 2,
90104
"llama.attention.head_count": 32,
@@ -122,7 +136,7 @@ describe("gguf", () => {
122136
tensor_count: 164n,
123137
kv_count: 21n,
124138
"general.architecture": "gemma",
125-
"general.file_type": GGMLQuantizationType.Q8_K, // 15
139+
"general.file_type": GGMLFileQuantizationType.MOSTLY_Q4_K_M,
126140
"general.name": "gemma-2b-it",
127141
"general.quantization_version": 2,
128142
"gemma.attention.head_count": 8,
@@ -159,7 +173,7 @@ describe("gguf", () => {
159173
tensor_count: 197n,
160174
kv_count: 23n,
161175
"general.architecture": "bert",
162-
"general.file_type": GGMLQuantizationType.F16,
176+
"general.file_type": GGMLFileQuantizationType.MOSTLY_F16,
163177
"general.name": "bge-small-en-v1.5",
164178
"bert.attention.causal": false,
165179
"bert.attention.head_count": 12,
@@ -228,16 +242,10 @@ describe("gguf", () => {
228242
});
229243

230244
it("should parse a local file", async () => {
231-
// download the file and save to .cache folder
232-
if (!fs.existsSync(".cache")) {
233-
fs.mkdirSync(".cache");
234-
}
235-
const res = await fetch(URL_V1);
236-
const arrayBuf = await res.arrayBuffer();
237-
fs.writeFileSync(".cache/model.gguf", Buffer.from(arrayBuf));
238-
239-
const { metadata } = await gguf(".cache/model.gguf", { allowLocalFile: true });
240-
expect(metadata).toMatchObject({ "general.name": "tinyllamas-stories-260k" });
245+
const parsedGguf = await gguf(".cache/model.gguf", { allowLocalFile: true });
246+
const { metadata } = parsedGguf as GGUFParseOutput<{ strict: false }>; // custom metadata arch, no need for typing
247+
expect(metadata["dummy.1"]).toBeDefined(); // first metadata in the list
248+
expect(metadata["dummy.32767"]).toBeDefined(); // last metadata in the list
241249
});
242250

243251
it("should detect sharded gguf filename", async () => {

packages/gguf/src/gguf.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { isBackend } from "./utils/isBackend";
44
import { promisesQueue } from "./utils/promisesQueue";
55

66
export type { MetadataBaseValue, MetadataValue, Version, GGUFMetadata, GGUFTensorInfo, GGUFParseOutput } from "./types";
7-
export { GGUFValueType, GGMLQuantizationType, Architecture } from "./types";
7+
export { GGUFValueType, GGMLFileQuantizationType, GGMLQuantizationType, Architecture } from "./types";
88
export { GGUF_QUANT_DESCRIPTIONS } from "./quant-descriptions";
99

1010
export const RE_GGUF_FILE = /\.gguf$/;
1111
export const RE_GGUF_SHARD_FILE = /^(?<prefix>.*?)-(?<shard>\d{5})-of-(?<total>\d{5})\.gguf$/;
12+
const PARALLEL_DOWNLOADS = 20;
1213

1314
export interface GgufShardFileInfo {
1415
prefix: string;
@@ -143,6 +144,7 @@ class RangeViewLocalFile extends RangeView {
143144
const range = [this.chunk * HTTP_CHUNK_SIZE, (this.chunk + 1) * HTTP_CHUNK_SIZE - 1];
144145
const buffer = await blob.slice(range[0], range[1]).arrayBuffer();
145146
this.appendBuffer(new Uint8Array(buffer));
147+
this.chunk += 1;
146148
}
147149
}
148150

@@ -400,8 +402,13 @@ export async function ggufAllShards(
400402
*/
401403
fetch?: typeof fetch;
402404
additionalFetchHeaders?: Record<string, string>;
405+
parallelDownloads?: number;
403406
}
404407
): Promise<{ shards: GGUFParseOutput[]; parameterCount: number }> {
408+
const parallelDownloads = params?.parallelDownloads ?? PARALLEL_DOWNLOADS;
409+
if (parallelDownloads < 1) {
410+
throw new TypeError("parallelDownloads must be greater than 0");
411+
}
405412
const ggufShardFileInfo = parseGgufShardFilename(url);
406413
if (ggufShardFileInfo) {
407414
const total = parseInt(ggufShardFileInfo.total);
@@ -412,10 +419,9 @@ export async function ggufAllShards(
412419
urls.push(`${prefix}-${shardIdx.toString().padStart(5, "0")}-of-${total.toString().padStart(5, "0")}.gguf`);
413420
}
414421

415-
const PARALLEL_DOWNLOADS = 20;
416422
const shards = await promisesQueue(
417423
urls.map((shardUrl) => () => gguf(shardUrl, { ...params, computeParametersCount: true })),
418-
PARALLEL_DOWNLOADS
424+
parallelDownloads
419425
);
420426
return {
421427
shards,

0 commit comments

Comments
 (0)