mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-09-13 05:01:44 +00:00
[misc] update pre-commit and run all files (#4752)
* [misc] update pre-commit * [misc] run pre-commit * [misc] remove useless configuration files * [misc] ignore cuda for clang-format
This commit is contained in:
@@ -13,35 +13,41 @@ if is_compatible_with_meta():
|
||||
aten = torch.ops.aten
|
||||
|
||||
registered_meta = {
|
||||
('aten.convolution.default', True): [ # (aten ops, requires_backward)
|
||||
("aten.convolution.default", True): [ # (aten ops, requires_backward)
|
||||
(nn.Conv1d(in_channels=3, out_channels=4, kernel_size=2, padding=1, dilation=2), torch.rand(2, 3, 4)),
|
||||
(nn.Conv2d(in_channels=3, out_channels=4, kernel_size=2, padding=1, dilation=2), torch.rand(2, 3, 4, 4)),
|
||||
(nn.Conv3d(in_channels=3, out_channels=4, kernel_size=2, padding=1, dilation=2), torch.rand(2, 3, 4, 4, 4)),
|
||||
(nn.ConvTranspose1d(in_channels=3, out_channels=4, kernel_size=2, padding=1, dilation=2), torch.rand(2, 3, 4)),
|
||||
(nn.ConvTranspose2d(in_channels=3, out_channels=4, kernel_size=2, padding=1,
|
||||
dilation=2), torch.rand(2, 3, 4, 4)),
|
||||
(nn.ConvTranspose3d(in_channels=3, out_channels=4, kernel_size=2, padding=1,
|
||||
dilation=2), torch.rand(2, 3, 4, 4, 4)),
|
||||
(
|
||||
nn.ConvTranspose2d(in_channels=3, out_channels=4, kernel_size=2, padding=1, dilation=2),
|
||||
torch.rand(2, 3, 4, 4),
|
||||
),
|
||||
(
|
||||
nn.ConvTranspose3d(in_channels=3, out_channels=4, kernel_size=2, padding=1, dilation=2),
|
||||
torch.rand(2, 3, 4, 4, 4),
|
||||
),
|
||||
],
|
||||
('aten.native_batch_norm.default', True): [
|
||||
("aten.native_batch_norm.default", True): [
|
||||
(nn.BatchNorm1d(4), torch.rand(2, 4)),
|
||||
(nn.BatchNorm2d(4), torch.rand(1, 4, 4, 4)),
|
||||
(nn.BatchNorm3d(4), torch.rand(1, 4, 4, 4, 4)),
|
||||
],
|
||||
('aten.native_layer_norm.default', True): [(nn.LayerNorm(4), torch.rand(1, 2, 3, 4)),],
|
||||
('aten.avg_pool1d.default', True): [
|
||||
("aten.native_layer_norm.default", True): [
|
||||
(nn.LayerNorm(4), torch.rand(1, 2, 3, 4)),
|
||||
],
|
||||
("aten.avg_pool1d.default", True): [
|
||||
(nn.MaxPool1d(3, stride=2), torch.rand(4, 5, 5)),
|
||||
(nn.AvgPool1d(3, stride=2), torch.rand(4, 5, 5)),
|
||||
(nn.AdaptiveMaxPool1d(3), torch.rand(4, 5, 5)),
|
||||
(nn.AdaptiveAvgPool1d(3), torch.rand(4, 5, 5)),
|
||||
],
|
||||
('aten.avg_pool2d.default', True): [
|
||||
("aten.avg_pool2d.default", True): [
|
||||
(nn.MaxPool2d((3, 2), stride=(2, 1)), torch.rand(2, 4, 5, 5)),
|
||||
(nn.AvgPool2d((3, 2), stride=(2, 1)), torch.rand(2, 4, 5, 5)),
|
||||
(nn.AdaptiveMaxPool2d((3, 2)), torch.rand(2, 4, 5, 5)),
|
||||
(nn.AdaptiveAvgPool2d((3, 2)), torch.rand(2, 4, 5, 5)),
|
||||
],
|
||||
('aten.relu.default', True): [
|
||||
("aten.relu.default", True): [
|
||||
(nn.ReLU(), torch.rand(4, 3, 1, 2)),
|
||||
(nn.LeakyReLU(), torch.rand(4, 3, 1, 2)),
|
||||
(nn.SiLU(), torch.rand(4, 3, 1, 2)),
|
||||
@@ -50,15 +56,20 @@ registered_meta = {
|
||||
(nn.Sigmoid(), torch.rand(4, 3, 1, 2)),
|
||||
(nn.Tanh(), torch.rand(4, 3, 1, 2)),
|
||||
(nn.Hardswish(), torch.rand(4, 3, 1, 2)),
|
||||
]
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def compare_all(tensor: torch.Tensor, meta_tensor: torch.Tensor) -> Any:
|
||||
assert tensor.shape == meta_tensor.shape, f'the shape of tensor ({tensor.shape}) and meta tensor ({meta_tensor.shape}) does not match.'
|
||||
assert tensor.dtype == meta_tensor.dtype, f'the dtype of tensor ({tensor.dtype}) and meta tensor ({meta_tensor.dtype}) does not match.'
|
||||
assert tensor.stride() == meta_tensor.stride(
|
||||
), f'the stride of tensor ({tensor.stride()}) and meta tensor ({meta_tensor.stride()}) does not match.'
|
||||
assert (
|
||||
tensor.shape == meta_tensor.shape
|
||||
), f"the shape of tensor ({tensor.shape}) and meta tensor ({meta_tensor.shape}) does not match."
|
||||
assert (
|
||||
tensor.dtype == meta_tensor.dtype
|
||||
), f"the dtype of tensor ({tensor.dtype}) and meta tensor ({meta_tensor.dtype}) does not match."
|
||||
assert (
|
||||
tensor.stride() == meta_tensor.stride()
|
||||
), f"the stride of tensor ({tensor.stride()}) and meta tensor ({meta_tensor.stride()}) does not match."
|
||||
|
||||
|
||||
def run_and_compare(f: Union[nn.Module, Callable], x: torch.Tensor, requires_backward=False) -> Any:
|
||||
@@ -72,7 +83,7 @@ def run_and_compare(f: Union[nn.Module, Callable], x: torch.Tensor, requires_bac
|
||||
compare_all(x.grad, meta_x.grad)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not is_compatible_with_meta(), reason='torch version is lower than 1.12.0')
|
||||
@pytest.mark.skipif(not is_compatible_with_meta(), reason="torch version is lower than 1.12.0")
|
||||
@clear_cache_before_run()
|
||||
def test_meta_aten():
|
||||
for (aten_op, requires_backward), v in registered_meta.items():
|
||||
@@ -80,5 +91,5 @@ def test_meta_aten():
|
||||
run_and_compare(f, x, requires_backward)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
test_meta_aten()
|
||||
|
@@ -23,31 +23,40 @@ tm_models = [
|
||||
]
|
||||
|
||||
tmm_models = [
|
||||
tmm.resnest.resnest50d, tmm.beit.beit_base_patch16_224, tmm.cait.cait_s24_224, tmm.efficientnet.efficientnetv2_m,
|
||||
tmm.resmlp_12_224, tmm.vision_transformer.vit_base_patch16_224, tmm.deit_base_distilled_patch16_224,
|
||||
tmm.convnext.convnext_base, tmm.vgg.vgg11, tmm.dpn.dpn68, tmm.densenet.densenet121, tmm.rexnet.rexnet_100,
|
||||
tmm.swin_transformer.swin_base_patch4_window7_224
|
||||
tmm.resnest.resnest50d,
|
||||
tmm.beit.beit_base_patch16_224,
|
||||
tmm.cait.cait_s24_224,
|
||||
tmm.efficientnet.efficientnetv2_m,
|
||||
tmm.resmlp_12_224,
|
||||
tmm.vision_transformer.vit_base_patch16_224,
|
||||
tmm.deit_base_distilled_patch16_224,
|
||||
tmm.convnext.convnext_base,
|
||||
tmm.vgg.vgg11,
|
||||
tmm.dpn.dpn68,
|
||||
tmm.densenet.densenet121,
|
||||
tmm.rexnet.rexnet_100,
|
||||
tmm.swin_transformer.swin_base_patch4_window7_224,
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.skipif(not is_compatible_with_meta(), reason='torch version is lower than 1.12.0')
|
||||
@pytest.mark.skipif(not is_compatible_with_meta(), reason="torch version is lower than 1.12.0")
|
||||
@clear_cache_before_run()
|
||||
def test_torchvision_models():
|
||||
for m in tm_models:
|
||||
model = m()
|
||||
data = torch.rand(100000, 3, 224, 224, device='meta')
|
||||
model(MetaTensor(data, fake_device=torch.device('cpu'))).sum().backward()
|
||||
data = torch.rand(100000, 3, 224, 224, device="meta")
|
||||
model(MetaTensor(data, fake_device=torch.device("cpu"))).sum().backward()
|
||||
|
||||
|
||||
@pytest.mark.skipif(not is_compatible_with_meta(), reason='torch version is lower than 1.12.0')
|
||||
@pytest.mark.skipif(not is_compatible_with_meta(), reason="torch version is lower than 1.12.0")
|
||||
@clear_cache_before_run()
|
||||
def test_timm_models():
|
||||
for m in tmm_models:
|
||||
model = m()
|
||||
data = torch.rand(100000, 3, 224, 224, device='meta')
|
||||
model(MetaTensor(data, fake_device=torch.device('cpu'))).sum().backward()
|
||||
data = torch.rand(100000, 3, 224, 224, device="meta")
|
||||
model(MetaTensor(data, fake_device=torch.device("cpu"))).sum().backward()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
test_torchvision_models()
|
||||
test_timm_models()
|
||||
|
@@ -23,31 +23,40 @@ tm_models = [
|
||||
]
|
||||
|
||||
tmm_models = [
|
||||
tmm.resnest.resnest50d, tmm.beit.beit_base_patch16_224, tmm.cait.cait_s24_224, tmm.efficientnet.efficientnetv2_m,
|
||||
tmm.resmlp_12_224, tmm.vision_transformer.vit_base_patch16_224, tmm.deit_base_distilled_patch16_224,
|
||||
tmm.convnext.convnext_base, tmm.vgg.vgg11, tmm.dpn.dpn68, tmm.densenet.densenet121, tmm.rexnet.rexnet_100,
|
||||
tmm.swin_transformer.swin_base_patch4_window7_224
|
||||
tmm.resnest.resnest50d,
|
||||
tmm.beit.beit_base_patch16_224,
|
||||
tmm.cait.cait_s24_224,
|
||||
tmm.efficientnet.efficientnetv2_m,
|
||||
tmm.resmlp_12_224,
|
||||
tmm.vision_transformer.vit_base_patch16_224,
|
||||
tmm.deit_base_distilled_patch16_224,
|
||||
tmm.convnext.convnext_base,
|
||||
tmm.vgg.vgg11,
|
||||
tmm.dpn.dpn68,
|
||||
tmm.densenet.densenet121,
|
||||
tmm.rexnet.rexnet_100,
|
||||
tmm.swin_transformer.swin_base_patch4_window7_224,
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.skipif(not is_compatible_with_meta(), reason='torch version is lower than 1.12.0')
|
||||
@pytest.mark.skipif(not is_compatible_with_meta(), reason="torch version is lower than 1.12.0")
|
||||
@clear_cache_before_run()
|
||||
def test_torchvision_models_trace():
|
||||
for m in tm_models:
|
||||
model = m()
|
||||
data = torch.rand(1000, 3, 224, 224, device='meta')
|
||||
graph = meta_trace(model, torch.device('cpu'), data)
|
||||
data = torch.rand(1000, 3, 224, 224, device="meta")
|
||||
meta_trace(model, torch.device("cpu"), data)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not is_compatible_with_meta(), reason='torch version is lower than 1.12.0')
|
||||
@pytest.mark.skipif(not is_compatible_with_meta(), reason="torch version is lower than 1.12.0")
|
||||
@clear_cache_before_run()
|
||||
def test_timm_models_trace():
|
||||
for m in tmm_models:
|
||||
model = m()
|
||||
data = torch.rand(1000, 3, 224, 224, device='meta')
|
||||
graph = meta_trace(model, torch.device('cpu'), data)
|
||||
data = torch.rand(1000, 3, 224, 224, device="meta")
|
||||
meta_trace(model, torch.device("cpu"), data)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
test_torchvision_models_trace()
|
||||
test_timm_models_trace()
|
||||
|
Reference in New Issue
Block a user