[Hardware][Ascend] Add Wan2.2 MXFP4 UOS, Smooth and W4A8 fallback (#7210)

Signed-off-by: HAAZZZEEEE <wang-taicheng@qq.com>
This commit is contained in:
HAAZZZEEEE authored and GitHub committed 2026-09-17 03:11:40 +00:00
1 parent 4fab34c8f4
commit becfefd440
20 files changed
+2435 -184

No files matched your search

@@ -7,7 +7,7 @@ import json
import os
import re
import time
from collections.abc import Generator, Iterable, Sequence
from collections.abc import Callable, Generator, Iterable, Sequence
from pathlib import Path
from typing import cast
@@ -481,8 +481,14 @@ class DiffusersPipelineLoader(HWRLoaderMixin):
)
def _get_expected_parameter_names(self, model: nn.Module) -> set[str]:
"""Return parameter names that should be covered by strict load checks."""
all_parameter_names = {name for name, _ in model.named_parameters()}
"""Return parameter names that should be covered by strict load checks.
A parameter with an initialized checkpoint default can explicitly set
``is_checkpoint_optional``. It is still loaded when present on disk.
"""
all_parameter_names = {
name for name, param in model.named_parameters() if not getattr(param, "is_checkpoint_optional", False)
}
sources = self._get_weight_sources(model)
# Keep strict behavior if no source metadata exists.
@@ -853,9 +859,24 @@ class DiffusersPipelineLoader(HWRLoaderMixin):
del model
return self.load_fresh_canonical_model()
raise
self._log_w4a8_fallback_load_summaries(model)
self._attach_offload_startup_state(model)
return model
@staticmethod
def _log_w4a8_fallback_load_summaries(model: nn.Module) -> None:
"""Ask discovered DiTs to report W4A8 state at the common load exit.
Each DiT derives readiness from its processed layers, so a deferred
weight plan cannot be mistaken for the ordinary or HSDP load path.
"""
components = ModuleDiscovery.discover(model)
for component_name, dit in zip(components.dit_names, components.dits):
candidate = getattr(dit, "_log_w4a8_fallback_load_summary", None)
if callable(candidate):
reporter = cast(Callable[[str], None], candidate)
reporter(component_name)
@staticmethod
def _request_offload_after_quant(model: nn.Module) -> int:
"""Ask online-quant layers to return to host memory once quantized.
@@ -1065,6 +1086,16 @@ class DiffusersPipelineLoader(HWRLoaderMixin):
# that have loaded weights tracking currently.
if loaded_weights is not None:
weights_not_loaded = weights_to_load - loaded_weights
# Offline formats can require scales that older online loaders
# were allowed to synthesize. Do not apply that legacy tolerance
# to an explicitly required checkpoint tensor.
required_missing = {
name
for name, param in model.named_parameters()
if name in weights_not_loaded and getattr(param, "is_checkpoint_required", False)
}
if required_missing:
raise ValueError(f"Required weights were not initialized from checkpoint: {required_missing}")
# NOTE: if the model is quantized, ignore not_loaded check for scale
# weights. ModelOpt FP8 carries a per-tensor `weight_scale` and a
# static activation `input_scale`, which the quant method may