Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add LeViT #177

Merged
merged 12 commits into from Mar 16, 2022
Merged

add LeViT #177

merged 12 commits into from Mar 16, 2022

Conversation

kaijieshi7
Copy link
Contributor

@kaijieshi7 kaijieshi7 commented Mar 15, 2022

Add LeViT

  • build model
  • update init.py in models
  • convert pretrained weight
  • inference test on imagenet and update model_zoo
  • update docs
  • update readme
  • update changelog
  • pytorch speed comparison

@kaijieshi7
Copy link
Contributor Author

OneFlow LeViT_128S time: 34.5ms (= 3447.5ms / 100, input_shape=[16, 3, 224, 224])
PyTorch LeViT_128S time: 40.7ms (= 4071.0ms / 100, input_shape=[16, 3, 224, 224])
✔️ Relative speed: 1.18 (= 40.7ms / 34.5ms)

OneFlow LeViT_128 time: 45.5ms (= 4551.8ms / 100, input_shape=[16, 3, 224, 224])
PyTorch LeViT_128 time: 45.8ms (= 4576.1ms / 100, input_shape=[16, 3, 224, 224])
✔️ Relative speed: 1.01 (= 45.8ms / 45.5ms)

OneFlow LeViT_192 time: 56.6ms (= 5663.3ms / 100, input_shape=[16, 3, 224, 224])
PyTorch LeViT_192 time: 49.0ms (= 4904.7ms / 100, input_shape=[16, 3, 224, 224])
❌ Relative speed: 0.87 (= 49.0ms / 56.6ms)

OneFlow LeViT_256 time: 60.8ms (= 6081.3ms / 100, input_shape=[16, 3, 224, 224])
PyTorch LeViT_256 time: 49.4ms (= 4942.2ms / 100, input_shape=[16, 3, 224, 224])
❌ Relative speed: 0.81 (= 49.4ms / 60.8ms)

OneFlow LeViT_384 time: 89.8ms (= 8976.2ms / 100, input_shape=[16, 3, 224, 224])
PyTorch LeViT_384 time: 55.5ms (= 5551.0ms / 100, input_shape=[16, 3, 224, 224])
❌ Relative speed: 0.62 (= 55.5ms / 89.8ms)

OneFlow LeViT_128S time: 15.2ms (= 1517.8ms / 100, input_shape=[16, 3, 224, 224], backward is disabled, ddp, world size=2)
PyTorch LeViT_128S time: 9.7ms (= 967.1ms / 100, input_shape=[16, 3, 224, 224], backward is disabled, ddp, world size=2)
❌ Relative speed: 0.64 (= 9.7ms / 15.2ms)


Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed.


OneFlow LeViT_128 time: 15.4ms (= 1544.3ms / 100, input_shape=[16, 3, 224, 224], backward is disabled, ddp, world size=2)
PyTorch LeViT_128 time: 10.1ms (= 1011.0ms / 100, input_shape=[16, 3, 224, 224], backward is disabled, ddp, world size=2)
❌ Relative speed: 0.65 (= 10.1ms / 15.4ms)


Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed.


OneFlow LeViT_192 time: 19.2ms (= 1918.2ms / 100, input_shape=[16, 3, 224, 224], backward is disabled, ddp, world size=2)
PyTorch LeViT_192 time: 9.8ms (= 975.5ms / 100, input_shape=[16, 3, 224, 224], backward is disabled, ddp, world size=2)
❌ Relative speed: 0.51 (= 9.8ms / 19.2ms)


Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed.


OneFlow LeViT_256 time: 22.5ms (= 2250.0ms / 100, input_shape=[16, 3, 224, 224], backward is disabled, ddp, world size=2)
PyTorch LeViT_256 time: 12.2ms (= 1216.7ms / 100, input_shape=[16, 3, 224, 224], backward is disabled, ddp, world size=2)
❌ Relative speed: 0.54 (= 12.2ms / 22.5ms)


Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed.


OneFlow LeViT_384 time: 31.9ms (= 3191.4ms / 100, input_shape=[16, 3, 224, 224], backward is disabled, ddp, world size=2)
PyTorch LeViT_384 time: 11.8ms (= 1177.6ms / 100, input_shape=[16, 3, 224, 224], backward is disabled, ddp, world size=2)
❌ Relative speed: 0.37 (= 11.8ms / 31.9ms)


Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed.


@kaijieshi7
Copy link
Contributor Author

这个速度误差好大啊,大家有没有什么想法

@rentainhe
Copy link
Contributor

这个速度误差好大啊,大家有没有什么想法

我看看,你搬的速度有点快233

README.md Outdated Show resolved Hide resolved
docs/source/flowvision.models.rst Outdated Show resolved Hide resolved

def forward(self, x):
if self.training and self.drop > 0:
return x + self.m(x) * (flow.rand(x.size(0), 1, 1, device=x.device)>self.drop).div(1 - self.drop).detach()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.div的速度可能有问题


def forward(self, x):
B, N, C = x.shape
x = x.view(B, self.resolution, self.resolution, C)[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.view还有一些slice的操作速度上可能也有差距

results/results_imagenet.md Outdated Show resolved Hide resolved
flowvision/models/levit.py Outdated Show resolved Hide resolved
rentainhe
rentainhe previously approved these changes Mar 16, 2022
@rentainhe
Copy link
Contributor

修复一下冲突就可以合并了 @kaijieshi7

@kaijieshi7
Copy link
Contributor Author

修复一下冲突就可以合并了 @kaijieshi7

OK

@rentainhe rentainhe merged commit 43c8057 into main Mar 16, 2022
@rentainhe rentainhe deleted the levit branch March 16, 2022 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants