2023-03-17 05:49:04 +00:00
|
|
|
import pytest
|
2023-05-23 03:57:15 +00:00
|
|
|
from lazy_init_utils import SUPPORT_LAZY, check_lazy_init
|
2023-03-17 05:49:04 +00:00
|
|
|
|
2024-01-16 10:55:13 +00:00
|
|
|
from tests.kit.model_zoo import COMMON_MODELS, IS_FAST_TEST, model_zoo
|
2023-03-17 05:49:04 +00:00
|
|
|
|
|
|
|
|
2023-09-19 06:20:26 +00:00
|
|
|
@pytest.mark.skipif(not SUPPORT_LAZY, reason="requires torch >= 1.12.0")
|
2024-01-16 10:55:13 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"subset",
|
2024-04-26 06:03:12 +00:00
|
|
|
(
|
|
|
|
[COMMON_MODELS]
|
|
|
|
if IS_FAST_TEST
|
|
|
|
else ["torchvision", "diffusers", "timm", "transformers", "torchaudio", "deepfm", "dlrm"]
|
|
|
|
),
|
2024-01-16 10:55:13 +00:00
|
|
|
)
|
2023-09-19 06:20:26 +00:00
|
|
|
@pytest.mark.parametrize("default_device", ["cpu", "cuda"])
|
2024-04-26 06:03:12 +00:00
|
|
|
def test_models_lazy_init(subset, default_device):
|
2024-01-16 10:55:13 +00:00
|
|
|
sub_model_zoo = model_zoo.get_sub_registry(subset, allow_empty=True)
|
2023-03-17 05:49:04 +00:00
|
|
|
for name, entry in sub_model_zoo.items():
|
|
|
|
# TODO(ver217): lazy init does not support weight norm, skip these models
|
2023-09-21 08:30:23 +00:00
|
|
|
if name in ("torchaudio_wav2vec2_base", "torchaudio_hubert_base") or name.startswith(
|
2024-04-26 06:03:12 +00:00
|
|
|
("transformers_vit", "transformers_blip2", "transformers_whisper")
|
2023-09-19 06:20:26 +00:00
|
|
|
):
|
2023-03-17 05:49:04 +00:00
|
|
|
continue
|
2023-07-19 08:43:01 +00:00
|
|
|
check_lazy_init(entry, verbose=True, default_device=default_device)
|
2023-03-17 05:49:04 +00:00
|
|
|
|
|
|
|
|
2023-09-19 06:20:26 +00:00
|
|
|
if __name__ == "__main__":
|
2024-04-26 06:03:12 +00:00
|
|
|
test_models_lazy_init("transformers", "cpu")
|