Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

feat(tailor): add high-level framework-agnostic convert #97

Merged
merged 2 commits into from
Oct 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions finetuner/tailor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from typing import overload, Optional, Tuple

from ..helper import get_framework, AnyDNN


# Keras Tailor
@overload
def convert(
model: AnyDNN,
freeze: bool = False,
embedding_layer_name: Optional[str] = None,
output_dim: Optional[int] = None,
) -> AnyDNN:
...


# Pytorch and Paddle Tailor
@overload
def convert(
model: AnyDNN,
input_size: Tuple[int, ...],
freeze: bool = False,
embedding_layer_name: Optional[str] = None,
output_dim: Optional[int] = None,
input_dtype: str = 'float32',
) -> AnyDNN:
...


def convert(model: AnyDNN, **kwargs) -> AnyDNN:
f_type = get_framework(model)

if f_type == 'keras':
from .keras import KerasTailor

ft = KerasTailor
elif f_type == 'torch':
from .pytorch import PytorchTailor

ft = PytorchTailor
elif f_type == 'paddle':
from .paddle import PaddleTailor

ft = PaddleTailor

return ft(model, **kwargs)().model