2023-03-10 02:23:26 +00:00
|
|
|
from typing import List, Tuple
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import torch
|
|
|
|
|
|
|
|
try:
|
|
|
|
from timm.models.vision_transformer import vit_large_patch16_384 as vit
|
2023-09-19 06:20:26 +00:00
|
|
|
|
2023-03-10 02:23:26 +00:00
|
|
|
MODELS = [vit]
|
|
|
|
HAS_REPO = True
|
|
|
|
except:
|
|
|
|
MODELS = []
|
|
|
|
HAS_REPO = False
|
|
|
|
|
|
|
|
from test_autochunk_vit_utils import run_test
|
|
|
|
|
|
|
|
from colossalai.autochunk.autochunk_codegen import AUTOCHUNK_AVAILABLE
|
2023-04-06 06:51:35 +00:00
|
|
|
from colossalai.testing import clear_cache_before_run, parameterize, spawn
|
2023-03-10 02:23:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_data() -> Tuple[List, List]:
|
|
|
|
data = torch.rand(1, 3, 384, 384)
|
2023-09-19 06:20:26 +00:00
|
|
|
meta_args = {"x": data}
|
2023-03-10 02:23:26 +00:00
|
|
|
return data, meta_args
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(
|
|
|
|
not (AUTOCHUNK_AVAILABLE and HAS_REPO),
|
|
|
|
reason="torch version is lower than 1.12.0",
|
|
|
|
)
|
2023-04-06 06:51:35 +00:00
|
|
|
@clear_cache_before_run()
|
|
|
|
@parameterize("model", MODELS)
|
|
|
|
@parameterize("max_memory", [None, 32, 40])
|
2023-03-10 02:23:26 +00:00
|
|
|
def test_evoformer_block(model, max_memory):
|
2023-04-06 06:51:35 +00:00
|
|
|
spawn(
|
2023-03-10 02:23:26 +00:00
|
|
|
run_test,
|
2023-04-06 06:51:35 +00:00
|
|
|
1,
|
2023-03-10 02:23:26 +00:00
|
|
|
max_memory=max_memory,
|
|
|
|
model=model,
|
|
|
|
data=get_data(),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
run_test(
|
|
|
|
rank=0,
|
|
|
|
data=get_data(),
|
|
|
|
max_memory=None,
|
|
|
|
model=vit,
|
|
|
|
print_code=False,
|
|
|
|
print_mem=False,
|
|
|
|
print_est_mem=False,
|
|
|
|
print_progress=False,
|
|
|
|
)
|