perf: optimize safetensors metadata fetching latency by fetching in parallel - #99
Open
saquibsaifee wants to merge 1 commit into
Conversation
Contributor
Author
|
Benchmark can be reproduced using: import time
import argparse
from src.models.safetensors_metadata import fetch_safetensors_metadata
def benchmark(repo_id: str):
# Warmup
try:
fetch_safetensors_metadata(repo_id)
except Exception:
pass
start = time.time()
res = fetch_safetensors_metadata(repo_id)
end = time.time()
print(f"Time taken for {repo_id}: {end - start:.4f} seconds")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Benchmark safetensors metadata fetch.")
parser.add_argument("--repo_id", default="TinyLlama/TinyLlama-1.1B-Chat-v1.0", help="Hugging Face repo ID")
args = parser.parse_args()
benchmark(args.repo_id) |
Contributor
Author
|
@eaglei15 this PR is ready to be reviewed. |
Refactored fetch_safetensors_metadata to fetch config.json, tokenizer_config.json and the safetensors metadata concurrently using concurrent.futures.ThreadPoolExecutor. This reduces metadata network operations latency by running them in parallel rather than sequentially. Removes benchmark_verify.py script per PR review. Signed-off-by: saquibsaifee <saquibsaifee2@gmail.com>
saquibsaifee
force-pushed
the
feat/optimize-safetensors-metadata-fetch-13406851267980656361
branch
from
August 31, 2026 17:03
d6b2b1d to
be3e440
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 What: Refactored
fetch_safetensors_metadatato useconcurrent.futures.ThreadPoolExecutorfor fetchingconfig.json,tokenizer_config.json, and safetensors metadata in parallel rather than sequentially.🎯 Why: To reduce overall network I/O latency when fetching metadata about safetensors. The previous implementation executed three blocking downloads in sequence.
📊 Measured Improvement: Running a basic warmup-based test benchmarking
TinyLlama/TinyLlama-1.1B-Chat-v1.0, latency dropped from~0.46sdown to~0.32s, approximately a 30% reduction in fetch time. The latency improvement applies best for models containingtokenizer_config.jsonand valid safetensors metadata alongsideconfig.jsonby combining their network IO time.