[diffusion] feat: respect component weight overrides for upsamplers (#36874)

This commit is contained in:
Mick
2026-08-29 14:23:11 +08:00
committed by GitHub
parent f93b48c627
commit 3c1d77be21
2 changed files with 34 additions and 2 deletions
@@ -197,6 +197,7 @@ def _load_explicit_config(
class UpsamplerLoader(PlainStateDictComponentLoader):
component_names = ["spatial_upsampler"]
expected_library = "diffusers"
supports_component_weight_override = True
def load_customized(
self,
@@ -204,7 +205,10 @@ class UpsamplerLoader(PlainStateDictComponentLoader):
server_args: ServerArgs,
component_name: str,
):
safetensors_path = _find_safetensors_file(component_model_path)
component_weights_path = self.resolve_component_weights_path(
component_model_path, server_args, component_name
)
safetensors_path = _find_safetensors_file(component_weights_path)
raw_config = _load_explicit_config(safetensors_path, component_model_path)
if raw_config is not None:
self.ensure_plain_state_dict_checkpoint(raw_config, component_name)
@@ -141,6 +141,7 @@ class TestComponentQuantizationAdmission(unittest.TestCase):
"_class_name": "LatentUpsampler",
"quantization_config": {"quant_method": "bitsandbytes"},
}
server_args = SimpleNamespace(component_weights_paths={})
with (
patch(
@@ -160,11 +161,38 @@ class TestComponentQuantizationAdmission(unittest.TestCase):
self.assertRaises(ComponentCheckpointUnsupportedError),
):
UpsamplerLoader().load_customized(
"/model/spatial_upsampler", None, "spatial_upsampler"
"/model/spatial_upsampler", server_args, "spatial_upsampler"
)
load_weights.assert_not_called()
def test_upsampler_uses_exact_component_weight_override(self):
self.assertTrue(UpsamplerLoader.supports_component_weight_override)
server_args = SimpleNamespace(
component_weights_paths={"spatial_upsampler": "owner/repo/upsampler"}
)
with (
patch.object(
UpsamplerLoader,
"resolve_component_weights_path",
return_value="/cache/upsampler.safetensors",
) as resolve_weights,
patch(
"sglang.multimodal_gen.runtime.loader.component_loaders."
"upsampler_loader._find_safetensors_file",
side_effect=RuntimeError("stop after routing"),
) as find_weights,
self.assertRaisesRegex(RuntimeError, "stop after routing"),
):
UpsamplerLoader().load_customized(
"/base/spatial_upsampler", server_args, "spatial_upsampler"
)
resolve_weights.assert_called_once_with(
"/base/spatial_upsampler", server_args, "spatial_upsampler"
)
find_weights.assert_called_once_with("/cache/upsampler.safetensors")
if __name__ == "__main__":
unittest.main()