Init pickle (#12567)

* Try to pickle transformers

* Deal with special objs better

* Make picklable
This commit is contained in:
Sylvain Gugger
2021-07-08 07:20:46 -04:00
committed by GitHub
parent b29c394586
commit 0a6b9048d1
72 changed files with 165 additions and 1095 deletions

View File

@@ -18,11 +18,11 @@
from typing import TYPE_CHECKING
{%- if cookiecutter.generate_tensorflow_and_pytorch == "PyTorch & TensorFlow" %}
from ...file_utils import _BaseLazyModule, is_tf_available, is_torch_available, is_tokenizers_available
from ...file_utils import _LazyModule, is_tf_available, is_torch_available, is_tokenizers_available
{%- elif cookiecutter.generate_tensorflow_and_pytorch == "PyTorch" %}
from ...file_utils import _BaseLazyModule, is_torch_available, is_tokenizers_available
from ...file_utils import _LazyModule, is_torch_available, is_tokenizers_available
{%- elif cookiecutter.generate_tensorflow_and_pytorch == "TensorFlow" %}
from ...file_utils import _BaseLazyModule, is_tf_available, is_tokenizers_available
from ...file_utils import _LazyModule, is_tf_available, is_tokenizers_available
{% endif %}
_import_structure = {
"configuration_{{cookiecutter.lowercase_modelname}}": ["{{cookiecutter.uppercase_modelname}}_PRETRAINED_CONFIG_ARCHIVE_MAP", "{{cookiecutter.camelcase_modelname}}Config"],
@@ -148,19 +148,6 @@ if TYPE_CHECKING:
{% endif %}
{% endif %}
else:
import importlib
import os
import sys
class _LazyModule(_BaseLazyModule):
"""
Module class that surfaces all objects but only performs associated imports when the objects are requested.
"""
__file__ = globals()["__file__"]
__path__ = [os.path.dirname(__file__)]
def _get_module(self, module_name: str):
return importlib.import_module("." + module_name, self.__name__)
sys.modules[__name__] = _LazyModule(__name__, _import_structure)
sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure)