fix: restrict cache validation behaviors to CI only (#14849)

This commit is contained in:
Alison Shao
2025-12-10 16:03:53 -08:00
committed by GitHub
parent c51efb8b84
commit b6523a4f72
+26 -2
View File
@@ -47,6 +47,7 @@ from sglang.srt.model_loader.weight_validation import (
_validate_sharded_model, _validate_sharded_model,
) )
from sglang.srt.utils import find_local_repo_dir, log_info_on_rank0, print_warning_once from sglang.srt.utils import find_local_repo_dir, log_info_on_rank0, print_warning_once
from sglang.utils import is_in_ci
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -326,8 +327,13 @@ def _find_local_hf_snapshot_dir_unlocked(
if not os.path.isdir(found_local_snapshot_dir): if not os.path.isdir(found_local_snapshot_dir):
return None return None
# Only perform cache validation and cleanup in CI to avoid
# unnecessary overhead for regular users
if is_in_ci():
# Check for incomplete files and clean up if found # Check for incomplete files and clean up if found
repo_folder = os.path.abspath(os.path.join(found_local_snapshot_dir, "..", "..")) repo_folder = os.path.abspath(
os.path.join(found_local_snapshot_dir, "..", "..")
)
blobs_dir = os.path.join(repo_folder, "blobs") blobs_dir = os.path.join(repo_folder, "blobs")
# Check for incomplete download markers # Check for incomplete download markers
@@ -366,6 +372,8 @@ def _find_local_hf_snapshot_dir_unlocked(
) )
local_weight_files = [] local_weight_files = []
# Only perform cache validation and cleanup in CI
if is_in_ci():
# Validate sharded models and check for corruption # Validate sharded models and check for corruption
if local_weight_files: if local_weight_files:
is_valid, error_msg, corrupted_files = _validate_sharded_model( is_valid, error_msg, corrupted_files = _validate_sharded_model(
@@ -380,7 +388,9 @@ def _find_local_hf_snapshot_dir_unlocked(
f"{model_name_or_path}: {error_msg}. " f"{model_name_or_path}: {error_msg}. "
"Will selectively clean and re-download only these files.", "Will selectively clean and re-download only these files.",
) )
_cleanup_corrupted_files_selective(model_name_or_path, corrupted_files) _cleanup_corrupted_files_selective(
model_name_or_path, corrupted_files
)
return None return None
else: else:
# Cannot selectively clean (e.g., missing shards) - remove entire cache # Cannot selectively clean (e.g., missing shards) - remove entire cache
@@ -569,6 +579,8 @@ def download_weights_from_hf(
log_info_on_rank0(logger, f"Using model weights format {allow_patterns}") log_info_on_rank0(logger, f"Using model weights format {allow_patterns}")
# Only perform validation and retry in CI to avoid overhead for regular users
if is_in_ci():
# Retry loop for handling corrupted downloads # Retry loop for handling corrupted downloads
for attempt in range(max_retries): for attempt in range(max_retries):
hf_folder = snapshot_download( hf_folder = snapshot_download(
@@ -606,6 +618,18 @@ def download_weights_from_hf(
# This should never be reached, but just in case # This should never be reached, but just in case
return hf_folder return hf_folder
else:
# Simple download without validation for non-CI environments
hf_folder = snapshot_download(
model_name_or_path,
allow_patterns=allow_patterns,
ignore_patterns=ignore_patterns,
cache_dir=cache_dir,
tqdm_class=DisabledTqdm,
revision=revision,
local_files_only=huggingface_hub.constants.HF_HUB_OFFLINE,
)
return hf_folder
def download_safetensors_index_file_from_hf( def download_safetensors_index_file_from_hf(