[Bugfix] Avoid repeated layerwise reload warning scans (#49505)
Signed-off-by: aoshen02 <aoshen@inferact.ai> Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -2,12 +2,14 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
import gc
|
||||
import inspect
|
||||
from unittest.mock import Mock
|
||||
from weakref import WeakKeyDictionary, ref
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
from torch.nn.parameter import UninitializedParameter
|
||||
|
||||
import vllm.model_executor.model_loader.reload.layerwise as reload_layerwise
|
||||
import vllm.model_executor.model_loader.reload.meta as reload_meta
|
||||
from vllm.config import ModelConfig
|
||||
from vllm.model_executor.layers.attention import MMEncoderAttention
|
||||
@@ -571,6 +573,35 @@ def test_get_numel_loaded_caps_at_param_size():
|
||||
assert num_loaded == 10
|
||||
|
||||
|
||||
def test_layerwise_loading_warning_only_checks_new_layers(monkeypatch):
|
||||
layers = [torch.nn.Linear(16, 1, bias=False) for _ in range(2)]
|
||||
|
||||
def partial_weight_loader(param, loaded_weight):
|
||||
param.view(-1)[: loaded_weight.numel()].copy_(loaded_weight)
|
||||
|
||||
for layer in layers:
|
||||
layer.weight.requires_grad_(False)
|
||||
layer.weight.weight_loader = partial_weight_loader
|
||||
reload_layerwise.initialize_online_processing(layer)
|
||||
|
||||
monkeypatch.setattr(reload_layerwise, "has_device_tensors", lambda _: True)
|
||||
get_info_size = Mock(return_value=0)
|
||||
warning_once = Mock()
|
||||
monkeypatch.setattr(reload_layerwise, "get_info_size", get_info_size)
|
||||
monkeypatch.setattr(reload_layerwise.logger, "warning_once", warning_once)
|
||||
|
||||
reload_layerwise.LOADING_LAYERS.clear()
|
||||
try:
|
||||
for layer in layers:
|
||||
for _ in range(3):
|
||||
layer.weight.weight_loader(layer.weight, torch.ones(1))
|
||||
finally:
|
||||
reload_layerwise.LOADING_LAYERS.clear()
|
||||
|
||||
assert get_info_size.call_count == 2
|
||||
warning_once.assert_called_once()
|
||||
|
||||
|
||||
class _ComposedLoaderLayer(torch.nn.Module):
|
||||
"""Mimics a Mamba2 mixer's equal-numel direct params (A, D, dt_bias).
|
||||
|
||||
|
||||
@@ -200,9 +200,9 @@ def make_online_process_loader(layer: torch.nn.Module, param_name: str) -> Calla
|
||||
return ret
|
||||
|
||||
# Log warnings allocating excessive buffers on device
|
||||
if has_device_tensors(bound_args):
|
||||
if has_device_tensors(bound_args) and layer not in LOADING_LAYERS:
|
||||
LOADING_LAYERS.add(layer)
|
||||
if len(LOADING_LAYERS) >= 2:
|
||||
if len(LOADING_LAYERS) == 2:
|
||||
names = sorted([layer.__class__.__name__ for layer in LOADING_LAYERS])
|
||||
mem_used = sum(
|
||||
get_info_size(LAYERWISE_INFO[layer]) for layer in LOADING_LAYERS
|
||||
|
||||
Reference in New Issue
Block a user