@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 5674a40366
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 14, 05:30 UTC

[Misc] Make `download_weights_from_hf` more reliable (#23863)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>

Harry Mellor committed Aug 29, 2025 at 20:37 UTC 5674a40366bae4cfc862c35b719e3dcac2587ac1
1 file changed +33 -18
vllm/model_executor/model_loader/weight_utils.py
+33 -18
@@ -278,33 +278,48 @@ def download_weights_from_hf(
278 Returns:
279 str: The path to the downloaded model weights.
280 """
281 + assert len(allow_patterns) > 0
282 local_only = huggingface_hub.constants.HF_HUB_OFFLINE
283 if not local_only:
283 - # Before we download we look at that is available:
284 - fs = HfFileSystem()
285 - file_list = fs.ls(model_name_or_path, detail=False, revision=revision)
286 -
287 - # depending on what is available we download different things
288 - for pattern in allow_patterns:
289 - matching = fnmatch.filter(file_list, pattern)
290 - if len(matching) > 0:
291 - allow_patterns = [pattern]
284 + # Attempt to reduce allow_patterns to a single pattern
285 + # so we only have to call snapshot_download once.
286 + try:
287 + fs = HfFileSystem()
288 + file_list = fs.ls(model_name_or_path,
289 + detail=False,
290 + revision=revision)
291 +
292 + # Use the first pattern found in the HF repo's files.
293 + for pattern in allow_patterns:
294 + matching = fnmatch.filter(file_list, pattern)
295 + if len(matching) > 0:
296 + allow_patterns = [pattern]
297 break
298 + except Exception as e:
299 + logger.warning(
300 + "Failed to get file list for '%s'. Trying each pattern in "
301 + "allow_patterns individually until weights have been "
302 + "downloaded. Error: %s", model_name_or_path, e)
303
304 logger.info("Using model weights format %s", allow_patterns)
305 # Use file lock to prevent multiple processes from
306 # downloading the same model weights at the same time.
307 with get_lock(model_name_or_path, cache_dir):
308 start_time = time.perf_counter()
299 - hf_folder = snapshot_download(
300 - model_name_or_path,
301 - allow_patterns=allow_patterns,
302 - ignore_patterns=ignore_patterns,
303 - cache_dir=cache_dir,
304 - tqdm_class=DisabledTqdm,
305 - revision=revision,
306 - local_files_only=local_only,
307 - )
309 + for allow_pattern in allow_patterns:
310 + hf_folder = snapshot_download(
311 + model_name_or_path,
312 + allow_patterns=allow_pattern,
313 + ignore_patterns=ignore_patterns,
314 + cache_dir=cache_dir,
315 + tqdm_class=DisabledTqdm,
316 + revision=revision,
317 + local_files_only=local_only,
318 + )
319 + # If we have downloaded weights for this allow_pattern,
320 + # we don't need to check the rest.
321 + if any(Path(hf_folder).glob(allow_pattern)):
322 + break
323 time_taken = time.perf_counter() - start_time
324 if time_taken > 0.5:
325 logger.info("Time spent downloading weights for %s: %.6f seconds",