Skip to content

Commit f7487c7

Browse files
authored
Fix duplicate model file downloads when progress_callback is active (#1663) (#1664)
When `progress_callback` is provided to `pipeline()`, model files are fetched from the server more times than necessary — `config.json` appears 3× and `tokenizer.json` 2× in the nginx logs, compared to once each without a callback. Signed-off-by: anish k <ak8686@princeton.edu>
1 parent 6688e09 commit f7487c7

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

packages/transformers/src/utils/model_registry/get_file_metadata.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,18 @@ async function fetch_file_head(urlOrPath) {
5151
* @returns {Promise<{exists: boolean, size?: number, contentType?: string, fromCache?: boolean}>} A Promise that resolves to file metadata.
5252
*/
5353
export function get_file_metadata(path_or_repo_id, filename, options = {}) {
54+
// Normalize option fields to their defaults so that callers passing explicit
55+
// defaults (e.g. revision='main', cache_dir=null, local_files_only=false)
56+
// share the same memoize key as callers that omit those options entirely.
57+
// Without normalization, pipeline() and loadResourceFile() compute different
58+
// keys for the same file, causing _get_file_metadata to run (and re-fetch)
59+
// once per call site instead of being deduplicated.
5460
const key = JSON.stringify([
5561
path_or_repo_id,
5662
filename,
57-
options?.revision,
58-
options?.cache_dir,
59-
options?.local_files_only,
63+
options?.revision ?? 'main',
64+
options?.cache_dir ?? null,
65+
options?.local_files_only ?? false,
6066
]);
6167
return memoizePromise(key, () => _get_file_metadata(path_or_repo_id, filename, options));
6268
}

0 commit comments

Comments
 (0)