Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d2f908b75 | ||
|
|
4f05ee165c |
No files matched your search
@@ -4,6 +4,26 @@ All notable changes to this project are documented here.
|
||||
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); each milestone of
|
||||
step 1 (Hugging Face downloader) is released as a minor version.
|
||||
|
||||
## [0.14.3] - 2026-10-22
|
||||
|
||||
### Fixed
|
||||
|
||||
- Downloads over Xet (any download with a file over 50 GB, or all of them with
|
||||
`HF_HUB_DISABLE_XET=false`) showed little or no progress. Xet keeps downloaded data in memory and
|
||||
writes the file in large chunks, sometimes minutes apart, so the bytes on disk don't show what has
|
||||
arrived. For Xet downloads the worker now turns on `hf`'s progress bars and reads its running
|
||||
byte count; the bars stay out of the job log. Ordinary downloads still measure the files on disk.
|
||||
|
||||
## [0.14.2] - 2026-10-22
|
||||
|
||||
### Fixed
|
||||
|
||||
- A running download's progress could jump back and forth between the real value and 0 B while
|
||||
`hf` kept downloading. A single progress reading that missed the partial file (a folder changing
|
||||
while the worker listed it, or a stale size on a network share) counted as nothing downloaded.
|
||||
Folders that vanish mid-listing are now skipped instead of failing the whole listing, and a file's
|
||||
progress no longer goes backwards during a run.
|
||||
|
||||
## [0.14.1] - 2026-10-22
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -107,7 +107,8 @@ Notes on the `hf` CLI (huggingface_hub 2.1.1, pinned in the image):
|
||||
Kaname cleans up the leftover partial files.
|
||||
- With Xet transfers the partial file only grows in large bursts, so Kaname disables Xet by default
|
||||
to show accurate progress. Files over 50 GB can only be downloaded with Xet, so a download that
|
||||
includes one uses Xet anyway.
|
||||
includes one uses Xet anyway; its progress then comes from `hf`'s own byte counter (the file on
|
||||
disk can sit still for minutes while Xet holds the data in memory).
|
||||
- `hf` exits successfully even if nothing matched, so Kaname checks every file's size and hash
|
||||
metadata after each download.
|
||||
- Files that already exist in the target folder without hf's metadata (copied in by hand) are
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "kaname",
|
||||
"version": "0.14.1",
|
||||
"version": "0.14.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "kaname",
|
||||
"version": "0.14.1",
|
||||
"version": "0.14.3",
|
||||
"dependencies": {
|
||||
"@base-ui/react": "^1.8.0",
|
||||
"@libsql/client": "^0.18.0",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "kaname",
|
||||
"version": "0.14.1",
|
||||
"version": "0.14.3",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "concurrently -k -n web,worker -c blue,magenta \"npm:dev:web\" \"npm:dev:worker\"",
|
||||
|
||||
+16
-5
@@ -20,13 +20,16 @@ import { escapeGlob } from "@/lib/selection";
|
||||
import {
|
||||
bytesOnDisk,
|
||||
type ExpectedFile,
|
||||
type FileProgress,
|
||||
listIncomplete,
|
||||
fileSize,
|
||||
modelDir,
|
||||
removeLocalFile,
|
||||
removeStaleIncomplete,
|
||||
steadyProgress,
|
||||
xetFor,
|
||||
} from "./hf-layout";
|
||||
import { XetCounter } from "./hf-progress";
|
||||
import { JobLog } from "./job-log";
|
||||
import { log } from "./log";
|
||||
import { settleModelStatus } from "./model-status";
|
||||
@@ -199,7 +202,7 @@ export class DownloadRunner implements Runner {
|
||||
}
|
||||
if (this.stopReason) return { state: this.stopReason, message: "Stopped before hf started." };
|
||||
|
||||
const exit = await this.spawnHf(dir, expected);
|
||||
const exit = await this.spawnHf(dir, expected, expected.reduce((s, f, i) => s + (initial[i].complete ? f.size : 0), 0));
|
||||
if (this.stopReason) {
|
||||
return {
|
||||
state: this.stopReason,
|
||||
@@ -247,12 +250,13 @@ export class DownloadRunner implements Runner {
|
||||
private spawnHf(
|
||||
dir: string,
|
||||
expected: ExpectedFile[],
|
||||
alreadyDone: number,
|
||||
): Promise<{ code: number | null; signal: NodeJS.Signals | null; error?: string }> {
|
||||
const env = coreEnv();
|
||||
const xet = xetFor(expected, env.HF_HUB_DISABLE_XET);
|
||||
if (xet.forcedBy.length) {
|
||||
this.jobLog.system(
|
||||
`Using Xet for this download: ${xet.forcedBy.slice(0, 3).join(", ")}${xet.forcedBy.length > 3 ? ", …" : ""} is over 50 GB, which hf only downloads with Xet (progress grows in bursts).`,
|
||||
`Using Xet for this download: ${xet.forcedBy.slice(0, 3).join(", ")}${xet.forcedBy.length > 3 ? ", …" : ""} is over 50 GB, which hf only downloads with Xet.`,
|
||||
);
|
||||
}
|
||||
const args = [
|
||||
@@ -272,7 +276,8 @@ export class DownloadRunner implements Runner {
|
||||
}
|
||||
Object.assign(childEnv, {
|
||||
HF_HUB_DISABLE_XET: xet.useXet ? "0" : "1",
|
||||
HF_HUB_DISABLE_PROGRESS_BARS: "1",
|
||||
// Xet: progress comes from hf's own byte counter (see hf-progress.ts), so force its bars on.
|
||||
...(xet.useXet ? { HF_HUB_DISABLE_PROGRESS_BARS: "0", TQDM_POSITION: "-1" } : { HF_HUB_DISABLE_PROGRESS_BARS: "1" }),
|
||||
HF_HUB_DISABLE_TELEMETRY: "1",
|
||||
NO_COLOR: "1",
|
||||
PYTHONUNBUFFERED: "1",
|
||||
@@ -294,6 +299,7 @@ export class DownloadRunner implements Runner {
|
||||
clearInterval(throttleTimer);
|
||||
running.delete(this);
|
||||
this.jobLog.end();
|
||||
this.jobLog.intercept = null;
|
||||
resolve(r);
|
||||
};
|
||||
|
||||
@@ -316,14 +322,19 @@ export class DownloadRunner implements Runner {
|
||||
const throttleTimer = this.throttle(dir, expected);
|
||||
|
||||
// Progress from bytes on disk, written to the DB once per second.
|
||||
const xetBytes = new XetCounter();
|
||||
if (xet.useXet) this.jobLog.intercept = (_stream, line) => xetBytes.feed(line);
|
||||
const speed = new SpeedMeter();
|
||||
let busy = false;
|
||||
let last: FileProgress[] | null = null;
|
||||
const timer = setInterval(async () => {
|
||||
if (busy) return;
|
||||
busy = true;
|
||||
try {
|
||||
const progress = await this.sample(dir, expected);
|
||||
const doneBytes = progress.reduce((s, p) => s + p.done, 0);
|
||||
const progress = steadyProgress(last, await this.sample(dir, expected));
|
||||
last = progress;
|
||||
const onDisk = progress.reduce((s, p) => s + p.done, 0);
|
||||
const doneBytes = Math.min(this.job.totalBytes, Math.max(onDisk, alreadyDone + xetBytes.bytes));
|
||||
speed.add(Date.now(), doneBytes);
|
||||
await this.writeProgress(progress, doneBytes, speed);
|
||||
await this.jobLog.flush();
|
||||
|
||||
+31
-14
@@ -61,24 +61,41 @@ export type IncompleteFile = { path: string; etag: string | null; size: number }
|
||||
|
||||
/** All partial files under the local dir's download cache. */
|
||||
export async function listIncomplete(dir: string): Promise<IncompleteFile[]> {
|
||||
const root = join(dir, DOWNLOAD_DIR);
|
||||
let entries;
|
||||
try {
|
||||
entries = await readdir(root, { recursive: true, withFileTypes: true });
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
const out: IncompleteFile[] = [];
|
||||
for (const e of entries) {
|
||||
if (!e.isFile() || !e.name.endsWith(".incomplete")) continue;
|
||||
const full = join(e.parentPath, e.name);
|
||||
const size = await fileSize(full);
|
||||
if (size == null) continue; // finished and moved between readdir and stat
|
||||
out.push({ path: full, etag: etagFromIncompleteName(e.name), size });
|
||||
}
|
||||
// Walked by hand: readdir's `recursive` fails as a whole when hf removes a folder mid-walk,
|
||||
// which read as "nothing downloaded" for that sample.
|
||||
const walk = async (path: string) => {
|
||||
let entries;
|
||||
try {
|
||||
entries = await readdir(path, { withFileTypes: true });
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
for (const e of entries) {
|
||||
const full = join(path, e.name);
|
||||
if (e.isDirectory()) await walk(full);
|
||||
if (!e.isFile() || !e.name.endsWith(".incomplete")) continue;
|
||||
const size = await fileSize(full);
|
||||
if (size == null) continue; // finished and moved between readdir and stat
|
||||
out.push({ path: full, etag: etagFromIncompleteName(e.name), size });
|
||||
}
|
||||
};
|
||||
await walk(join(dir, DOWNLOAD_DIR));
|
||||
return out;
|
||||
}
|
||||
|
||||
export type FileProgress = { done: number; complete: boolean };
|
||||
|
||||
/**
|
||||
* Progress that never goes backwards within one run. A sample can miss a partial file that is
|
||||
* still being written (a folder renamed mid-walk, a stale size from a network share), and showing
|
||||
* 0 B for a second is wrong; hf doesn't restart a file within a run.
|
||||
*/
|
||||
export function steadyProgress(prev: FileProgress[] | null, next: FileProgress[]): FileProgress[] {
|
||||
if (!prev) return next;
|
||||
return next.map((p, i) => (p.complete || !prev[i] ? p : { done: Math.max(p.done, prev[i].done), complete: false }));
|
||||
}
|
||||
|
||||
/** Delete leftover partial files from earlier runs. Only call while no hf process uses the dir. */
|
||||
export async function removeStaleIncomplete(dir: string): Promise<{ count: number; bytes: number }> {
|
||||
const files = await listIncomplete(dir);
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import { isProgressBar, XetCounter, xetDownloadedBytes } from "./hf-progress";
|
||||
import { JobLog, sanitizeLine } from "./job-log";
|
||||
|
||||
// Captured from hf 2.1.1 with TQDM_POSITION=-1 during an Xet download (after sanitizeLine).
|
||||
const LINES = [
|
||||
"Downloading bytes: | 0.00B ",
|
||||
"Downloading bytes: | 752B ",
|
||||
"Downloading bytes: ██▌ | 101MB, 3.07MB/s ",
|
||||
"Downloading bytes: ██████▌ | 261MB, 3.48MB/s ",
|
||||
"Downloading bytes: █████████▌| 1.23GB, 112MB/s ",
|
||||
];
|
||||
|
||||
describe("hf progress bars", () => {
|
||||
it("reads Xet's running byte total", () => {
|
||||
assert.deepEqual(LINES.map((l) => xetDownloadedBytes(l)?.bytes), [0, 752, 101e6, 261e6, 1.23e9]);
|
||||
assert.deepEqual(xetDownloadedBytes("Qwen3-0.6B-Q4_K_M.gguf: downloading bytes: █████████▊| 387MB, 1.55MB/s "), {
|
||||
file: "Qwen3-0.6B-Q4_K_M.gguf",
|
||||
bytes: 387e6,
|
||||
});
|
||||
assert.equal(xetDownloadedBytes("Reconstructing (incomplete total...): 0%| | 0.00B / 397MB"), null);
|
||||
assert.equal(xetDownloadedBytes("Downloading bytes are fun"), null);
|
||||
});
|
||||
|
||||
it("recognises bar lines and leaves real messages alone", () => {
|
||||
for (const l of LINES) assert.ok(isProgressBar(l), l);
|
||||
assert.ok(isProgressBar("Reconstructing (incomplete total...): | | 0.00B / 0.00B"));
|
||||
assert.ok(isProgressBar("Qwen3-0.6B-Q4_K_M.gguf: reconstructing file: 100%|██████████| 397M/397M"));
|
||||
assert.ok(isProgressBar("Qwen3-0.6B-Q4_K_M.gguf: downloading bytes: █████████▊| 387MB, 1.55MB/s"));
|
||||
assert.ok(isProgressBar("Download complete: ██████████| 684MB, 1.10MB/s"));
|
||||
assert.ok(isProgressBar("Fetching 2 files: 50%|█████ | 1/2 [00:00<00:00, 2.44it/s]"));
|
||||
assert.ok(isProgressBar("model.safetensors: 45%|████▌ | 180M/400M [00:10<00:12, 18MB/s]"));
|
||||
assert.ok(!isProgressBar("Warning: You are sending unauthenticated requests to the HF Hub."));
|
||||
assert.ok(!isProgressBar("Error: Invalid value. The file is too large to be downloaded"));
|
||||
});
|
||||
|
||||
it("sums per-file bars, or takes the total when hf prints one", () => {
|
||||
const c = new XetCounter();
|
||||
c.feed("a.gguf: downloading bytes: █ | 100MB, 1MB/s");
|
||||
c.feed("b.gguf: downloading bytes: █ | 50.0MB, 1MB/s");
|
||||
c.feed("a.gguf: downloading bytes: █ | 120MB, 1MB/s");
|
||||
assert.equal(c.bytes, 170e6);
|
||||
c.feed("Downloading bytes: █ | 300MB, 2MB/s");
|
||||
assert.equal(c.bytes, 300e6);
|
||||
});
|
||||
|
||||
it("the job log drops intercepted lines, including the cursor-up codes tqdm adds", () => {
|
||||
assert.equal(sanitizeLine("Downloading bytes: █ | 40.4MB, 2.85MB/s \x1b[A").trimEnd(), "Downloading bytes: █ | 40.4MB, 2.85MB/s");
|
||||
const log = new JobLog("test");
|
||||
const counter = new XetCounter();
|
||||
log.intercept = (_s, line) => counter.feed(line);
|
||||
log.chunk("stderr", "Downloading bytes: █ | 40.4MB, 2.85MB/s \x1b[A\rDownloading bytes: █ | 62.8MB, 2.83MB/s \x1b[A\rWarning: real problem\n");
|
||||
assert.equal(counter.bytes, 62.8e6);
|
||||
assert.deepEqual(log.stderrTail, ["Warning: real problem"]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
// hf's progress bars (tqdm), forced on for Xet downloads with TQDM_POSITION=-1 (huggingface_hub
|
||||
// 2.1.1 turns them off without a terminal). Xet keeps downloaded data in memory and writes the file
|
||||
// in large, late chunks, so the bytes on disk can sit still for minutes; the bar's running total
|
||||
// is the only live number. hf 2.1.1 prints one of:
|
||||
// "Downloading bytes: ███ | 261MB, 2.90MB/s" several files: one total
|
||||
// "model.gguf: downloading bytes: ███ | 387MB, 1.55MB/s" a single file
|
||||
|
||||
const UNITS: Record<string, number> = { "": 1, k: 1e3, K: 1e3, M: 1e6, G: 1e9, T: 1e12, P: 1e15 };
|
||||
const BYTES_RE = /^\s*(?:(.+?): )?[Dd]ownloading bytes:[^|]*\|[^|]*?([\d.]+)\s*([kKMGTP]?)B\b/;
|
||||
|
||||
/** Bytes from an Xet "downloading bytes" bar line (file = null for the total), or null. */
|
||||
export function xetDownloadedBytes(line: string): { file: string | null; bytes: number } | null {
|
||||
const m = BYTES_RE.exec(line);
|
||||
if (!m) return null;
|
||||
const n = Number(m[2]) * UNITS[m[3]];
|
||||
return Number.isFinite(n) ? { file: m[1] ?? null, bytes: Math.round(n) } : null;
|
||||
}
|
||||
|
||||
/** A progress bar line, kept out of the job log (it repeats several times a second). */
|
||||
export function isProgressBar(line: string): boolean {
|
||||
return (
|
||||
/^\s*(?:.+?: )?([Dd]ownloading bytes|Download complete|[Rr]econstructing\b[^:]*|Fetching \d+ files?):/.test(line) ||
|
||||
/\d+(\.\d+)?%\|.*\|/.test(line)
|
||||
);
|
||||
}
|
||||
|
||||
/** Running total of bytes Xet has downloaded in this hf run. */
|
||||
export class XetCounter {
|
||||
private total = 0;
|
||||
private perFile = new Map<string, number>();
|
||||
|
||||
/** Feed one output line; true if it was a progress bar line. */
|
||||
feed(line: string): boolean {
|
||||
const b = xetDownloadedBytes(line);
|
||||
if (b?.file == null && b) this.total = Math.max(this.total, b.bytes);
|
||||
else if (b?.file != null) this.perFile.set(b.file, Math.max(this.perFile.get(b.file) ?? 0, b.bytes));
|
||||
return isProgressBar(line);
|
||||
}
|
||||
|
||||
get bytes(): number {
|
||||
let files = 0;
|
||||
for (const n of this.perFile.values()) files += n;
|
||||
return Math.max(this.total, files);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ export class JobLog {
|
||||
private written = 0;
|
||||
private dropped = 0;
|
||||
readonly stderrTail: string[] = [];
|
||||
/** Sees every stdout/stderr line first; returning true keeps it out of the log. */
|
||||
intercept: ((stream: "stdout" | "stderr", line: string) => boolean) | null = null;
|
||||
|
||||
constructor(
|
||||
private jobId: string,
|
||||
@@ -52,6 +54,7 @@ export class JobLog {
|
||||
private push(stream: LogStream, raw: string) {
|
||||
const line = sanitizeLine(raw, this.secrets);
|
||||
if (!line.trim()) return;
|
||||
if (stream !== "system" && this.intercept?.(stream, line)) return;
|
||||
if (stream === "stderr") {
|
||||
this.stderrTail.push(line);
|
||||
if (this.stderrTail.length > 30) this.stderrTail.shift();
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { describe, it } from "node:test";
|
||||
import { listIncomplete, steadyProgress } from "./hf-layout";
|
||||
|
||||
const ETAG = "b139949c5bd74937ad8ed8c8cf3d9ffb1e99c866c823204dc42c0d91fa181897";
|
||||
|
||||
describe("download progress", () => {
|
||||
it("never goes backwards for a file that isn't complete", () => {
|
||||
const a = steadyProgress(null, [{ done: 300e6, complete: false }, { done: 0, complete: false }]);
|
||||
const b = steadyProgress(a, [{ done: 0, complete: false }, { done: 5e6, complete: false }]);
|
||||
assert.deepEqual(b, [{ done: 300e6, complete: false }, { done: 5e6, complete: false }]);
|
||||
const c = steadyProgress(b, [{ done: 400e6, complete: true }, { done: 6e6, complete: false }]);
|
||||
assert.deepEqual(c, [{ done: 400e6, complete: true }, { done: 6e6, complete: false }]);
|
||||
});
|
||||
|
||||
it("finds partial files in subfolders and skips folders that are gone", async () => {
|
||||
const dir = await mkdtemp(join(tmpdir(), "kaname-progress-"));
|
||||
try {
|
||||
const sub = join(dir, ".cache", "huggingface", "download", "Q4_K_M");
|
||||
await mkdir(sub, { recursive: true });
|
||||
await writeFile(join(sub, `abc=.${ETAG}.905d6ccf.incomplete`), Buffer.alloc(1234));
|
||||
assert.deepEqual((await listIncomplete(dir)).map((f) => [f.etag, f.size]), [[ETAG, 1234]]);
|
||||
assert.deepEqual(await listIncomplete(join(dir, "missing")), []);
|
||||
} finally {
|
||||
await rm(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user