[Quantization] Redo Z-Image text encoder FP8 online quantization (#3279)

Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn>
Signed-off-by: Isotr0py <2037008807@qq.com>
Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
Co-authored-by: SYLAR <125541396+lishunyang12@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-05-06 16:37:36 +00:00
1 parent b8bd75837e
commit 0a8204cb81
5 files changed
+191 -36

No files matched your search

@@ -26,6 +26,7 @@ from vllm.model_executor.model_loader.weight_utils import (
multi_thread_safetensors_weights_iterator,
safetensors_weights_iterator,
)
from vllm.transformers_utils.repo_utils import file_exists
from vllm.utils.import_utils import resolve_obj_by_qualname
from vllm.utils.torch_utils import set_default_torch_dtype
@@ -49,6 +50,8 @@ def _natural_sort_key(filepath: str) -> list:
MODEL_INDEX = "model_index.json"
DIFFUSION_MODEL_WEIGHTS_INDEX = "diffusion_pytorch_model.safetensors.index.json"
TRANSFORMER_WEIGHTS_INDEX = "model.safetensors.index.json"
INDEX_FILES = [DIFFUSION_MODEL_WEIGHTS_INDEX, TRANSFORMER_WEIGHTS_INDEX]
class DiffusersPipelineLoader:
@@ -99,8 +102,17 @@ class DiffusersPipelineLoader:
is_local = os.path.isdir(model_name_or_path)
load_format = self.load_config.load_format
use_safetensors = False
index_file = DIFFUSION_MODEL_WEIGHTS_INDEX
index_file_with_subfolder = f"{subfolder}/{index_file}" if subfolder else index_file
possible_index_files = [
f"{subfolder}/{index_file}" if subfolder is not None else index_file for index_file in INDEX_FILES
]
available_index_file = [
f for f in possible_index_files if file_exists(model_name_or_path, f, revision=revision)
]
if len(available_index_file) > 1:
raise ValueError(
f"Multiple index files found in {model_name_or_path} with subfolder {subfolder}: {available_index_file}"
)
index_file = available_index_file[0] if available_index_file else ""
# only hf is supported currently
if load_format == "auto":
@@ -118,20 +130,21 @@ class DiffusersPipelineLoader:
if allow_patterns_overrides is not None:
allow_patterns = allow_patterns_overrides
if subfolder is not None:
allow_patterns = [f"{subfolder}/{pattern}" for pattern in allow_patterns]
if not is_local:
hf_folder = download_weights_from_hf(
model_name_or_path,
self.load_config.download_dir,
allow_patterns,
revision,
subfolder=subfolder,
ignore_patterns=self.load_config.ignore_patterns,
)
else:
hf_folder = model_name_or_path
if subfolder is not None:
hf_folder = os.path.join(hf_folder, subfolder)
hf_weights_files: list[str] = []
for pattern in allow_patterns:
hf_weights_files += glob.glob(os.path.join(hf_folder, pattern))
@@ -149,22 +162,12 @@ class DiffusersPipelineLoader:
if not is_local:
download_safetensors_index_file_from_hf(
model_name_or_path,
index_file_with_subfolder,
self.load_config.download_dir,
revision,
index_file,
cache_dir=self.load_config.download_dir,
subfolder=subfolder,
revision=revision,
)
# Some diffusers pipelines keep component weights under a
# subfolder (e.g. "transformer/") and the corresponding index file
# uses filenames relative to that subfolder. vLLM's
# `filter_duplicate_safetensors_files` expects weight_map entries
# to be relative to the `hf_folder` we pass in, so we point it to
# the component subfolder to avoid filtering out all shards.
filter_folder = os.path.join(hf_folder, subfolder) if subfolder is not None else hf_folder
hf_weights_files = filter_duplicate_safetensors_files(
hf_weights_files,
filter_folder,
index_file,
)
hf_weights_files = filter_duplicate_safetensors_files(hf_weights_files, hf_folder, index_file)
else:
hf_weights_files = filter_files_not_needed_for_inference(hf_weights_files)