Skip to content

Commit 0c5aa65

Browse files
committed
Merge branch 'main' into feat/agent.md
2 parents 66723f8 + 400ad82 commit 0c5aa65

File tree

11 files changed

+505
-222
lines changed

11 files changed

+505
-222
lines changed

.devcontainer/devcontainer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
3+
{
4+
"name": "Node.js & TypeScript",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-22-bookworm",
7+
8+
// Features to add to the dev container. More info: https://containers.dev/features.
9+
"features": {
10+
"ghcr.io/joshuanianji/devcontainer-features/mount-pnpm-store:1": {}
11+
}
12+
13+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
14+
// "forwardPorts": [],
15+
16+
// Use 'postCreateCommand' to run commands after the container is created.
17+
// "postCreateCommand": "yarn install",
18+
19+
// Configure tool-specific properties.
20+
// "customizations": {},
21+
22+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
23+
// "remoteUser": "root"
24+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ You can run our packages with vanilla JS, without any bundler, by using a CDN or
9999
```html
100100
<script type="module">
101101
import { InferenceClient } from 'https://cdn.jsdelivr.net/npm/@huggingface/inference@4.7.1/+esm';
102-
import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/hub@2.5.0/+esm";
102+
import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/hub@2.5.2/+esm";
103103
</script>
104104
```
105105

packages/hub/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
xet-core-wasm-build
2+
shard.bin
3+
xorb.bin

packages/hub/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@huggingface/hub",
33
"packageManager": "pnpm@10.10.0",
4-
"version": "2.5.0",
4+
"version": "2.5.2",
55
"description": "Utilities to interact with the Hugging Face hub",
66
"repository": "https://github.com/huggingface/huggingface.js.git",
77
"publishConfig": {

packages/hub/scripts/bench.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { RepoId } from "../src/types/public.js";
88
import { toRepoId } from "../src/utils/toRepoId.js";
99
import { commitIter } from "../src/index.js";
1010
import { pathToFileURL } from "node:url";
11+
import { WebBlob } from "../src/utils/WebBlob.js";
1112

1213
/**
1314
* This script downloads the files from openai-community/gpt2 and simulates an upload to a xet repo.
@@ -23,10 +24,17 @@ const FILES_TO_DOWNLOAD = [
2324
{
2425
url: "https://huggingface.co/openai-community/gpt2/resolve/main/64-8bits.tflite?download=true",
2526
filename: "64-8bits.tflite",
27+
sha256: "c966da3b74697803352ca7c6f2f220e7090a557b619de9da0c6b34d89f7825c1",
2628
},
2729
{
2830
url: "https://huggingface.co/openai-community/gpt2/resolve/main/64-fp16.tflite?download=true",
2931
filename: "64-fp16.tflite",
32+
sha256: "1ceafd82e733dd4b21570b2a86cf27556a983041806c033a55d086e0ed782cd3",
33+
},
34+
{
35+
url: "https://huggingface.co/openai-community/gpt2/resolve/main/64.tflite?download=true",
36+
filename: "64.tflite",
37+
sha256: "cfcd510b239d90b71ee87d4e57a5a8c2d55b2a941e5d9fe5852298268ddbe61b",
3038
},
3139
];
3240

@@ -68,6 +76,15 @@ async function* createFileSource(
6876
const sha256Hash = res.value;
6977

7078
console.log(`SHA256 for ${file.filename}: ${sha256Hash}`);
79+
80+
if (sha256Hash !== FILES_TO_DOWNLOAD.find((f) => f.filename === file.filename)?.sha256) {
81+
throw new Error(
82+
`SHA256 mismatch for ${file.filename}: ${sha256Hash} !== ${FILES_TO_DOWNLOAD.find(
83+
(f) => f.filename === file.filename
84+
)?.sha256}`
85+
);
86+
}
87+
7188
yield {
7289
content: blob,
7390
path: file.filename,
@@ -92,7 +109,7 @@ function getBodySize(body: RequestInit["body"]): string {
92109
return "unknown size";
93110
}
94111

95-
function createMockFetch(): {
112+
function createMockFetch(args: { write: boolean }): {
96113
fetch: typeof fetch;
97114
getStats: () => { xorbCount: number; shardCount: number; xorbBytes: number; shardBytes: number };
98115
} {
@@ -111,6 +128,11 @@ function createMockFetch(): {
111128
xorbBytes += parseInt(bodySize);
112129
console.log(`[MOCK] Xorb upload ${xorbCount}: ${init?.method || "GET"} ${url} (${bodySize})`);
113130

131+
if (args.write) {
132+
// Write the body to a file
133+
await writeFile("xorb.bin", init?.body as Uint8Array);
134+
}
135+
114136
return new Response(null, {
115137
status: 200,
116138
statusText: "OK",
@@ -123,6 +145,11 @@ function createMockFetch(): {
123145
shardBytes += parseInt(bodySize);
124146
console.log(`[MOCK] Shard upload ${shardCount}: ${init?.method || "GET"} ${url} (${bodySize})`);
125147

148+
if (args.write) {
149+
// Write the body to a file
150+
await writeFile("shard.bin", init?.body as Uint8Array);
151+
}
152+
126153
return new Response(null, {
127154
status: 200,
128155
statusText: "OK",
@@ -158,6 +185,11 @@ async function main() {
158185
short: "c",
159186
default: false,
160187
},
188+
write: {
189+
type: "boolean",
190+
short: "w",
191+
default: false,
192+
},
161193
},
162194
});
163195

@@ -189,7 +221,7 @@ async function main() {
189221
const repo: RepoId = toRepoId(repoName);
190222

191223
// Create mock fetch
192-
const mockFetchObj = createMockFetch();
224+
const mockFetchObj = createMockFetch({ write: args.write });
193225

194226
// Setup upload parameters
195227
const uploadParams = {
@@ -290,6 +322,19 @@ async function main() {
290322
}
291323

292324
console.log("Done committing");
325+
326+
console.log("Redownloading files and verifying SHA256 integrity");
327+
for (const file of FILES_TO_DOWNLOAD) {
328+
const fileBlob = await WebBlob.create(new URL(file.url));
329+
const sha256Hash = sha256(fileBlob, { useWebWorker: false });
330+
let res: IteratorResult<number, string>;
331+
do {
332+
res = await sha256Hash.next();
333+
} while (!res.done);
334+
const finalHash = res.value;
335+
336+
console.log(`${file.filename}: ${finalHash} === ${file.sha256} ${finalHash === file.sha256 ? "✅" : "❌"}`);
337+
}
293338
}
294339
}
295340

packages/hub/src/lib/commit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export type CommitParams = {
9292
/**
9393
* @deprecated Not yet ready for production use
9494
*/
95-
xet?: boolean;
95+
useXet?: boolean;
9696
} & Partial<CredentialsParams>;
9797

9898
export interface CommitOutput {
@@ -298,7 +298,7 @@ export async function* commitIter(params: CommitParams): AsyncGenerator<CommitPr
298298

299299
const shaToOperation = new Map(operations.map((op, i) => [shas[i], op]));
300300

301-
if (params.xet) {
301+
if (params.useXet) {
302302
// First get all the files that are already uploaded out of the way
303303
for (const obj of json.objects) {
304304
const op = shaToOperation.get(obj.oid);

packages/hub/src/lib/upload-file.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export function uploadFile(
1515
fetch?: CommitParams["fetch"];
1616
useWebWorkers?: CommitParams["useWebWorkers"];
1717
abortSignal?: CommitParams["abortSignal"];
18+
/**
19+
* @deprecated Not yet ready for production use
20+
*/
21+
useXet?: CommitParams["useXet"];
1822
} & Partial<CredentialsParams>
1923
): Promise<CommitOutput> {
2024
const path =
@@ -43,5 +47,6 @@ export function uploadFile(
4347
fetch: params.fetch,
4448
useWebWorkers: params.useWebWorkers,
4549
abortSignal: params.abortSignal,
50+
useXet: params.useXet,
4651
});
4752
}

0 commit comments

Comments
 (0)