Skip to content

Memoize network calls in model registry#1547

Open
nico-martin wants to merge 62 commits intomainfrom
v4-cache-handler-memo
Open

Memoize network calls in model registry#1547
nico-martin wants to merge 62 commits intomainfrom
v4-cache-handler-memo

Conversation

@nico-martin
Copy link
Collaborator

The ModelRegistry has two points where calls to the model host are made: fetching the model config (config.json) and fetching file metadatas. When a consumer first calls ModelRegistry.get_model_files to inspect what a model needs (display the total size on the dowload button) and then creates the pipeline, both of those network calls are made twice. Which is not necessary.

This PR introduces a small memoizePromise utility that deduplicates promises by key. Whether the first call is still in-flight or already resolved, any subsequent call with the same key gets the same promise back. This is then applied to get_file_metadata and the new get_config helper in get_model_files.js, so the config and metadata fetches each happen at most once per unique set of arguments.

nico-martin and others added 30 commits January 29, 2026 22:56
…tion that does not check for tokenizer files or processor files if the task does not use them
Co-authored-by: Joshua Lochner <admin@xenova.com>
Co-authored-by: Joshua Lochner <admin@xenova.com>
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@nico-martin nico-martin requested a review from xenova February 28, 2026 07:08
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea! I think -- in any case, we should add a max cache size, kind of like how we do here: https://github.com/huggingface/tokenizers.js/blob/488865017c65e9b84b84ede4d7fa89f348dc0fea/src/utils/data-structures/LRUCache.ts#L4

Base automatically changed from v4-cache-handler to main March 1, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants