Skip to content

Commit 163d1cb

Browse files
Merge branch 'main' into add-link-to-local-chat
2 parents 82460b0 + 9706030 commit 163d1cb

26 files changed

+412
-134
lines changed

.github/workflows/inference-publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
git tag "inference-v$BUMPED_VERSION"
5555
5656
- name: "Check Deps are published before publishing this package"
57-
run: pnpm -w check-deps gguf
57+
run: pnpm -w check-deps tasks
5858

5959
- run: pnpm publish --no-git-checks .
6060
env:

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ You can run our packages with vanilla JS, without any bundler, by using a CDN or
9393
```html
9494
<script type="module">
9595
import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm';
96-
import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/hub@0.21.0/+esm";
96+
import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/hub@1.0.0/+esm";
9797
</script>
9898
```
9999

packages/gguf/src/gguf.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,9 @@ describe("gguf", () => {
283283
expect(parseGGUFQuantLabel("Codestral-22B-v0.1-IQ3_XS.gguf")).toEqual(undefined); // TODO: investigate IQ3_XS
284284
expect(parseGGUFQuantLabel("Codestral-22B-v0.1-Q4_0_4_4.gguf")).toEqual("Q4_0"); // TODO: investigate Q4_0_4_4
285285
});
286+
287+
it("calculate tensor data offset", async () => {
288+
const { tensorDataOffset } = await gguf(URL_LLAMA);
289+
expect(tensorDataOffset).toEqual(741056n);
290+
});
286291
});

packages/gguf/src/gguf.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export { parseGGUFQuantLabel, GGUF_QUANT_RE, GGUF_QUANT_RE_GLOBAL } from "@huggi
1010

1111
export const RE_GGUF_FILE = /\.gguf$/;
1212
export const RE_GGUF_SHARD_FILE = /^(?<prefix>.*?)-(?<shard>\d{5})-of-(?<total>\d{5})\.gguf$/;
13+
const GGUF_DEFAULT_ALIGNMENT = 32; // defined in ggml.h
14+
const GGML_PAD = (x: number, n: number) => (x + n - 1) & ~(n - 1); // defined in ggml.h
1315
const PARALLEL_DOWNLOADS = 20;
1416

1517
export interface GgufShardFileInfo {
@@ -384,14 +386,18 @@ export async function gguf(
384386
});
385387
}
386388

389+
// calculate absolute offset of tensor data
390+
const alignment: number = Number(metadata["general.alignment"] ?? GGUF_DEFAULT_ALIGNMENT);
391+
const tensorDataOffset = BigInt(GGML_PAD(offset, alignment));
392+
387393
if (params?.computeParametersCount) {
388394
const parameterCount = tensorInfos
389395
.map(({ shape }) => shape.reduce((acc, val) => acc * Number(val), 1))
390396
.reduce((acc, val) => acc + val, 0);
391397

392-
return { metadata, tensorInfos, parameterCount };
398+
return { metadata, tensorInfos, tensorDataOffset, parameterCount };
393399
} else {
394-
return { metadata, tensorInfos };
400+
return { metadata, tensorInfos, tensorDataOffset };
395401
}
396402
}
397403

@@ -429,7 +435,10 @@ export async function ggufAllShards(
429435
parameterCount: shards.map(({ parameterCount }) => parameterCount).reduce((acc, val) => acc + val, 0),
430436
};
431437
} else {
432-
const { metadata, tensorInfos, parameterCount } = await gguf(url, { ...params, computeParametersCount: true });
433-
return { shards: [{ metadata, tensorInfos }], parameterCount };
438+
const { metadata, tensorInfos, tensorDataOffset, parameterCount } = await gguf(url, {
439+
...params,
440+
computeParametersCount: true,
441+
});
442+
return { shards: [{ metadata, tensorInfos, tensorDataOffset }], parameterCount };
434443
}
435444
}

packages/gguf/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,5 @@ export interface GGUFTensorInfo {
155155
export interface GGUFParseOutput<Options extends GGUFMetadataOptions = { strict: true }> {
156156
metadata: GGUFMetadata<Options>;
157157
tensorInfos: GGUFTensorInfo[];
158+
tensorDataOffset: bigint;
158159
}

packages/hub/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@huggingface/hub",
33
"packageManager": "[email protected]",
4-
"version": "0.21.0",
4+
"version": "1.0.0",
55
"description": "Utilities to interact with the Hugging Face hub",
66
"repository": "https://github.com/huggingface/huggingface.js.git",
77
"publishConfig": {

packages/hub/src/error.ts

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export async function createApiError(
1515
if (response.headers.get("Content-Type")?.startsWith("application/json")) {
1616
const json = await response.json();
1717
error.message = json.error || json.message || error.message;
18+
if (json.error_description) {
19+
error.message = error.message ? error.message + `: ${json.error_description}` : json.error_description;
20+
}
1821
error.data = json;
1922
} else {
2023
error.data = { message: await response.text() };

packages/hub/src/lib/create-repo.ts

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { toRepoId } from "../utils/toRepoId";
99
export async function createRepo(
1010
params: {
1111
repo: RepoDesignation;
12+
/**
13+
* If unset, will follow the organization's default setting. (typically public, except for some Enterprise organizations)
14+
*/
1215
private?: boolean;
1316
license?: string;
1417
/**

packages/hub/src/lib/file-download-info.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export async function fileDownloadInfo(
5050
const resp = await (params.fetch ?? fetch)(url, {
5151
method: "GET",
5252
headers: {
53-
...(params.credentials && {
53+
...(accessToken && {
5454
Authorization: `Bearer ${accessToken}`,
5555
}),
5656
Range: "bytes=0-0",

packages/hub/src/lib/list-datasets.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export async function* listDatasets<
8686
const res: Response = await (params?.fetch ?? fetch)(url, {
8787
headers: {
8888
accept: "application/json",
89-
...(params?.credentials ? { Authorization: `Bearer ${accessToken}` } : undefined),
89+
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : undefined),
9090
},
9191
});
9292

packages/hub/src/lib/list-models.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export async function* listModels<
9494
const res: Response = await (params?.fetch ?? fetch)(url, {
9595
headers: {
9696
accept: "application/json",
97-
...(params?.credentials ? { Authorization: `Bearer ${accessToken}` } : undefined),
97+
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : undefined),
9898
},
9999
});
100100

packages/hub/src/lib/list-spaces.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export async function* listSpaces<
8282
const res: Response = await (params?.fetch ?? fetch)(url, {
8383
headers: {
8484
accept: "application/json",
85-
...(params?.credentials ? { Authorization: `Bearer ${accessToken}` } : undefined),
85+
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : undefined),
8686
},
8787
});
8888

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { describe, expect, it } from "vitest";
2+
import { TEST_COOKIE, TEST_HUB_URL } from "../test/consts";
3+
import { oauthLoginUrl } from "./oauth-login-url";
4+
import { oauthHandleRedirect } from "./oauth-handle-redirect";
5+
6+
describe("oauthHandleRedirect", () => {
7+
it("should work", async () => {
8+
const localStorage = {
9+
nonce: undefined,
10+
codeVerifier: undefined,
11+
};
12+
const url = await oauthLoginUrl({
13+
clientId: "dummy-app",
14+
redirectUrl: "http://localhost:3000",
15+
localStorage,
16+
scopes: "openid profile email",
17+
hubUrl: TEST_HUB_URL,
18+
});
19+
const resp = await fetch(url, {
20+
method: "POST",
21+
headers: {
22+
Cookie: `token=${TEST_COOKIE}`,
23+
},
24+
redirect: "manual",
25+
});
26+
if (resp.status !== 303) {
27+
throw new Error(`Failed to fetch url ${url}: ${resp.status} ${resp.statusText}`);
28+
}
29+
const location = resp.headers.get("Location");
30+
if (!location) {
31+
throw new Error(`No location header in response`);
32+
}
33+
const result = await oauthHandleRedirect({
34+
redirectedUrl: location,
35+
codeVerifier: localStorage.codeVerifier,
36+
nonce: localStorage.nonce,
37+
hubUrl: TEST_HUB_URL,
38+
});
39+
40+
if (!result) {
41+
throw new Error("Expected result to be defined");
42+
}
43+
expect(result.accessToken).toEqual(expect.any(String));
44+
expect(result.accessTokenExpiresAt).toBeInstanceOf(Date);
45+
expect(result.accessTokenExpiresAt.getTime()).toBeGreaterThan(Date.now());
46+
expect(result.scope).toEqual(expect.any(String));
47+
expect(result.userInfo).toEqual({
48+
sub: "62f264b9f3c90f4b6514a269",
49+
name: "@huggingface/hub CI bot",
50+
preferred_username: "hub.js",
51+
email_verified: true,
52+
53+
isPro: false,
54+
picture: "https://hub-ci.huggingface.co/avatars/934b830e9fdaa879487852f79eef7165.svg",
55+
profile: "https://hub-ci.huggingface.co/hub.js",
56+
website: "https://github.com/huggingface/hub.js",
57+
orgs: [],
58+
});
59+
});
60+
});

0 commit comments

Comments
 (0)