[model-loader] Split weight loading from postprocessing (#34981)

Co-authored-by: yangliu991 <yangliu991@fb.com>
This commit is contained in:
Yang Liu
2026-09-14 17:10:19 -07:00
committed by GitHub
co-authored by yangliu991
parent a2b4e8888f
commit 276663a79d
2 changed files with 127 additions and 0 deletions
+7
View File
@@ -994,6 +994,11 @@ class DefaultModelLoader(BaseModelLoader):
@staticmethod
def load_weights_and_postprocess(model, weights, target_device):
DefaultModelLoader.load_weights_only(model, weights, target_device)
DefaultModelLoader.postprocess_weights(model, target_device)
@staticmethod
def load_weights_only(model, weights, target_device):
# Used in tests to verify memory savings when using online quantization.
if is_cuda_alike():
peak_memory = torch.cuda.max_memory_allocated()
@@ -1049,6 +1054,8 @@ class DefaultModelLoader(BaseModelLoader):
f"{memory_start - memory_end:.3f}",
)
@staticmethod
def postprocess_weights(model, target_device):
for _, module in model.named_modules():
quant_method = getattr(module, "quant_method", None)
if quant_method is not None: