diff --git a/optimum/commands/env.py b/optimum/commands/env.py index 9b76a9fb69e..ee01ed06016 100644 --- a/optimum/commands/env.py +++ b/optimum/commands/env.py @@ -57,8 +57,8 @@ def run(self): "Platform": platform.platform(), "Python version": platform.python_version(), "Huggingface_hub version": huggingface_hub.__version__, - "PyTorch version (GPU?)": f"{pt_version} (cuda availabe: {pt_cuda_available})", - "Tensorflow version (GPU?)": f"{tf_version} (cuda availabe: {tf_cuda_available})", + "PyTorch version (GPU?)": f"{pt_version} (cuda available: {pt_cuda_available})", + "Tensorflow version (GPU?)": f"{tf_version} (cuda available: {tf_cuda_available})", } print("\nCopy-and-paste the text below in your GitHub issue:\n") diff --git a/optimum/exporters/onnx/base.py b/optimum/exporters/onnx/base.py index 8cd94194ffe..d11d186c156 100644 --- a/optimum/exporters/onnx/base.py +++ b/optimum/exporters/onnx/base.py @@ -373,7 +373,7 @@ def is_transformers_support_available(self) -> bool: Whether the installed version of Transformers allows for the ONNX export. Returns: - `bool`: Whether the install version of Transformers is compatible with the model. + `bool`: Whether the installed version of Transformers is compatible with the model. """ return check_if_transformers_greater(self.MIN_TRANSFORMERS_VERSION) diff --git a/optimum/exporters/onnx/model_configs.py b/optimum/exporters/onnx/model_configs.py index e77f649f69b..b9e0589b929 100644 --- a/optimum/exporters/onnx/model_configs.py +++ b/optimum/exporters/onnx/model_configs.py @@ -118,6 +118,10 @@ def inputs(self) -> Dict[str, Dict[int, str]]: } +class NomicBertOnnxConfig(BertOnnxConfig): + DEFAULT_ONNX_OPSET = 14 + + class AlbertOnnxConfig(BertOnnxConfig): DEFAULT_ONNX_OPSET = 14 # now uses F.scaled_dot_product_attention by default for torch>=2.1.1. diff --git a/optimum/exporters/tasks.py b/optimum/exporters/tasks.py index a489f34fb06..dd1a88cae68 100644 --- a/optimum/exporters/tasks.py +++ b/optimum/exporters/tasks.py @@ -871,6 +871,7 @@ class TasksManager: "text2text-generation-with-past", onnx="M2M100OnnxConfig", ), + "nomic-bert": supported_tasks_mapping("feature-extraction", onnx="NomicBertOnnxConfig"), "nystromformer": supported_tasks_mapping( "feature-extraction", "fill-mask", @@ -1195,7 +1196,7 @@ def create_register( backend (`str`): The name of the backend that the register function will handle. overwrite_existing (`bool`, defaults to `False`): - Whether or not the register function is allowed to overwrite an already existing config. + Whether the register function is allowed to overwrite an already existing config. Returns: `Callable[[str, Tuple[str, ...]], Callable[[Type], Type]]`: A decorator taking the model type and a the diff --git a/optimum/utils/normalized_config.py b/optimum/utils/normalized_config.py index 81207b76496..5ae5310ab13 100644 --- a/optimum/utils/normalized_config.py +++ b/optimum/utils/normalized_config.py @@ -259,6 +259,7 @@ class NormalizedConfigManager: "mpt": MPTNormalizedTextConfig, "mt5": T5LikeNormalizedTextConfig, "m2m-100": BartLikeNormalizedTextConfig, + "nomic-bert": NormalizedTextConfig, "nystromformer": NormalizedTextConfig, "opt": NormalizedTextConfig, "pegasus": BartLikeNormalizedTextConfig, diff --git a/tests/exporters/exporters_utils.py b/tests/exporters/exporters_utils.py index c8a33b0be35..0160fbeb158 100644 --- a/tests/exporters/exporters_utils.py +++ b/tests/exporters/exporters_utils.py @@ -301,6 +301,8 @@ "latent-consistency": "echarlaix/tiny-random-latent-consistency", } +PYTORCH_REMOTE_CODE_MODELS = {"nomic-bert": "nomic-ai/nomic-embed-text-v1.5"} + PYTORCH_TIMM_MODEL = { "default-timm-config": { "timm/inception_v3.tf_adv_in1k": ["image-classification"], diff --git a/tests/exporters/onnx/test_exporters_onnx_cli.py b/tests/exporters/onnx/test_exporters_onnx_cli.py index 9ac7832aa7d..0076049225b 100644 --- a/tests/exporters/onnx/test_exporters_onnx_cli.py +++ b/tests/exporters/onnx/test_exporters_onnx_cli.py @@ -43,6 +43,7 @@ NO_DYNAMIC_AXES_EXPORT_SHAPES_TRANSFORMERS, PYTORCH_DIFFUSION_MODEL, PYTORCH_EXPORT_MODELS_TINY, + PYTORCH_REMOTE_CODE_MODELS, PYTORCH_SENTENCE_TRANSFORMERS_MODEL, PYTORCH_TIMM_MODEL, PYTORCH_TIMM_MODEL_NO_DYNAMIC_AXES, @@ -739,3 +740,32 @@ def test_complex_synonyms(self): model.save_pretrained(tmpdir_in) main_export(model_name_or_path=tmpdir_in, output=tmpdir_out, task="text-classification") + + @parameterized.expand(_get_models_to_test(PYTORCH_REMOTE_CODE_MODELS, library_name="transformers")) + @require_torch + @slow + @pytest.mark.run_slow + def test_custom_model( + self, + test_name: str, + model_type: str, + model_name: str, + task: str, + variant: str, + monolith: bool, + no_post_process: bool, + ): + with TemporaryDirectory() as tmpdirname: + out = subprocess.run( + f"python3 -m optimum.exporters.onnx --trust-remote-code --model {model_name} --task {task} {tmpdirname}", + shell=True, + capture_output=True, + ) + self.assertFalse(out.returncode) + + with TemporaryDirectory() as tmpdirname: + out = subprocess.run( + f"python3 -m optimum.exporters.onnx --trust-remote-code --model {model_name} --task {task} {tmpdirname}", + shell=True, + check=True, + ) diff --git a/tests/exporters/onnx/test_onnx_export.py b/tests/exporters/onnx/test_onnx_export.py index 7671d6cd2e6..1547c96e920 100644 --- a/tests/exporters/onnx/test_onnx_export.py +++ b/tests/exporters/onnx/test_onnx_export.py @@ -50,6 +50,7 @@ from ..exporters_utils import ( PYTORCH_DIFFUSION_MODEL, PYTORCH_EXPORT_MODELS_TINY, + PYTORCH_REMOTE_CODE_MODELS, PYTORCH_SENTENCE_TRANSFORMERS_MODEL, PYTORCH_TIMM_MODEL, TENSORFLOW_EXPORT_MODELS, @@ -318,6 +319,7 @@ def test_all_models_tested(self): - set(PYTORCH_EXPORT_MODELS_TINY.keys()) - set(PYTORCH_TIMM_MODEL.keys()) - set(PYTORCH_SENTENCE_TRANSFORMERS_MODEL.keys()) + - set(PYTORCH_REMOTE_CODE_MODELS.keys()) ) if len(missing_models_set) > 0: self.fail(f"Not testing all models. Missing models: {missing_models_set}") diff --git a/tests/onnxruntime/test_modeling.py b/tests/onnxruntime/test_modeling.py index 33243da278a..7cb6e752f28 100644 --- a/tests/onnxruntime/test_modeling.py +++ b/tests/onnxruntime/test_modeling.py @@ -4919,7 +4919,7 @@ def test_generate_utils(self, test_name: str, model_arch: str, use_cache: str): @parameterized.expand(grid_parameters(FULL_GRID)) def test_compare_to_transformers(self, test_name: str, model_arch: str, use_cache: bool, use_merged: bool): if use_cache is False and use_merged is True: - self.skipTest("use_cache=False, use_merged=True are uncompatible") + self.skipTest("use_cache=False, use_merged=True are incompatible") model_args = { "test_name": test_name,