Skip to content

Commit

Permalink
[Frontend] Translator / Legalizer (apache#14)
Browse files Browse the repository at this point in the history
* Initialize translator

Co-authored-by: Bohan Hou <[email protected]>
Co-authored-by: Hongyi Jin <[email protected]>

* relax.sqrt

* Fix two bugs of BlockBuilder

* Update translator

* Legalizer

* relax.nn.matmul

* Use `call_te` for non-intermediate result

* Translator and legalizer for matmul

* Use dispatch table for legalizer

* Use `call_te` for non-intermediate result

* Move legalizer to relax.transform

* Rename to fx translator

* Minor fix

* Unit tests for legalizer

* Fix legalizer for reshape inference

Co-authored-by: Bohan Hou <[email protected]>
Co-authored-by: Hongyi Jin <[email protected]>
  • Loading branch information
3 people committed Nov 19, 2022
1 parent a9c29e6 commit c19878a
Show file tree
Hide file tree
Showing 14 changed files with 2,551 additions and 1 deletion.
4 changes: 3 additions & 1 deletion python/tvm/relax/block_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ def _convert_te_arg(self, te_args: Any) -> typing.Tuple[Any, List[tvm.te.Tensor]
te_args_list = []

def _convert_te_arg_helper(arg):
if isinstance(arg, Expr): # type: ignore
if isinstance(arg, ShapeExpr): # type: ignore
return [_convert_te_arg_helper(x) for x in arg.values]
elif isinstance(arg, Expr): # type: ignore
arg = te_tensor(arg)
te_args_list.append(arg)
return arg
Expand Down
23 changes: 23 additions & 0 deletions python/tvm/relax/frontend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""
Frontends for constructing Relax programs.
Contains the model importers currently defined for Relax.
"""
from .pytorch_fx import TorchFXTranslator

Loading

0 comments on commit c19878a

Please sign in to comment.