Import structure & first three model refactors (#31329)

* Import structure & first three model refactors

* Register -> Export. Export all in __all__. Sensible defaults according to filename.

* Apply most comments from Amy and some comments from Lucain

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
Co-authored-by: Lucain Pouget <lucainp@gmail.com>

* Style

* Add comment

* Clearer .py management

* Raise if not in backend mapping

* More specific type

* More efficient listdir

* Misc fixes

---------

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
Co-authored-by: Lucain Pouget <lucainp@gmail.com>
This commit is contained in:
Lysandre Debut
2024-09-10 11:10:53 +02:00
committed by GitHub
parent 7f112caac2
commit f24f084329
30 changed files with 937 additions and 553 deletions

View File

@@ -0,0 +1,23 @@
# Copyright 2024 The HuggingFace Team. All rights reserved.
#
# Licensed 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.
# fmt: off
from transformers.utils.import_utils import export
@export(backends=("random_item_that_should_not_exist",))
class A0:
def __init__(self):
pass

View File

@@ -0,0 +1,80 @@
# Copyright 2024 The HuggingFace Team. All rights reserved.
#
# Licensed 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.
# fmt: off
from transformers.utils.import_utils import export
@export()
class A0:
def __init__(self):
pass
@export()
def a0():
pass
@export(backends=("torch", "tf"))
class A1:
def __init__(self):
pass
@export(backends=("torch", "tf"))
def a1():
pass
@export(
backends=("torch", "tf")
)
class A2:
def __init__(self):
pass
@export(
backends=("torch", "tf")
)
def a2():
pass
@export(
backends=(
"torch",
"tf"
)
)
class A3:
def __init__(self):
pass
@export(
backends=(
"torch",
"tf"
)
)
def a3():
pass
@export(backends=())
class A4:
def __init__(self):
pass

View File

@@ -0,0 +1,79 @@
# Copyright 2024 The HuggingFace Team. All rights reserved.
#
# Licensed 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.
# fmt: off
from transformers.utils.import_utils import export
@export()
# That's a statement
class B0:
def __init__(self):
pass
@export()
# That's a statement
def b0():
pass
@export(backends=("torch", "tf"))
# That's a statement
class B1:
def __init__(self):
pass
@export(backends=("torch", "tf"))
# That's a statement
def b1():
pass
@export(backends=("torch", "tf"))
# That's a statement
class B2:
def __init__(self):
pass
@export(backends=("torch", "tf"))
# That's a statement
def b2():
pass
@export(
backends=(
"torch",
"tf"
)
)
# That's a statement
class B3:
def __init__(self):
pass
@export(
backends=(
"torch",
"tf"
)
)
# That's a statement
def b3():
pass

View File

@@ -0,0 +1,77 @@
# Copyright 2024 The HuggingFace Team. All rights reserved.
#
# Licensed 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.
# fmt: off
from transformers.utils.import_utils import export
@export(backends=("torch", "torch"))
class C0:
def __init__(self):
pass
@export(backends=("torch", "torch"))
def c0():
pass
@export(backends=("torch", "torch"))
# That's a statement
class C1:
def __init__(self):
pass
@export(backends=("torch", "torch"))
# That's a statement
def c1():
pass
@export(backends=("torch", "torch"))
# That's a statement
class C2:
def __init__(self):
pass
@export(backends=("torch", "torch"))
# That's a statement
def c2():
pass
@export(
backends=(
"torch",
"torch"
)
)
# That's a statement
class C3:
def __init__(self):
pass
@export(
backends=(
"torch",
"torch"
)
)
# That's a statement
def c3():
pass