forked from open-mmlab/mmrazor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] Support litehrnet for ncnn (open-mmlab#316)
* support for litehrnet * support ncnn vulkan * update supported models * add docstring * add one ut and fix wrapper * add test_shuffleunit * add test_stem_forward * add last ut * fix flake8 * fix yapf * fix lint * fix yapf * fix comments * unified chunk * mv adaptive_avg_pool * fix lint * move adaptive_avg_pool_ncnn * fix lint * symbolic rewriter of adaptive_avg_pool2d * fix lint * fix yapf * fix ci
- Loading branch information
1 parent
5cbb065
commit aa85760
Showing
10 changed files
with
127 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
import torch | ||
|
||
from mmdeploy.core import FUNCTION_REWRITER | ||
|
||
|
||
@FUNCTION_REWRITER.register_rewriter( | ||
func_name='torch.Tensor.chunk', backend='ncnn') | ||
def chunk__ncnn(ctx, self, num_chunks: int, dim: int = 0) -> torch.Tensor: | ||
"""Rewrite `chunk` for NCNN backend. | ||
Chunk in ncnn are not supported, so it should be rewritten. | ||
""" | ||
dim_len = self.shape[dim] | ||
# int ceil. | ||
step = dim_len // num_chunks | ||
if dim_len % num_chunks > 0: | ||
step += 1 | ||
index_list = [] | ||
index = 0 | ||
while index < dim_len: | ||
index_list.append(index) | ||
index += step | ||
index_list.append(dim_len) | ||
output = [ | ||
self.index_select( | ||
dim, | ||
torch.tensor([j for j in range(index_list[i], index_list[i + 1])], | ||
dtype=torch.int64)) | ||
for i in range(len(index_list) - 1) | ||
] | ||
|
||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters