Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nomic-ai/nomic-embed-text-v1.5 model #1874

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
65ad74a
Add nomic-bert config
bhavika May 24, 2024
34f8121
Add config
bhavika May 29, 2024
d55166c
Change opset
bhavika May 29, 2024
eb0f281
Fix typos
bhavika May 29, 2024
e93e359
Merge branch 'huggingface:main' into nomicbert
bhavika May 29, 2024
7b384c8
Merge branch 'nomicbert'
bhavika May 29, 2024
2570a3c
Add test
bhavika Jun 6, 2024
150739f
Add to config
bhavika Jun 8, 2024
985703b
Add nomic-bert to supported architectures
bhavika Jun 25, 2024
82a788f
Add test for exporter
bhavika Jun 26, 2024
06cf77e
Merge branch 'huggingface:main' into main
bhavika Jun 26, 2024
1cadbd3
remove test file
bhavika Jun 26, 2024
977fdbf
Add nomic-bert as a supported arch in test
bhavika Jun 26, 2024
0b7d459
Add nomic-bert to large models tests
bhavika Jun 26, 2024
bf23abf
Merge branch 'huggingface:main' into main
bhavika Jun 27, 2024
9a6cd59
Merge branch 'huggingface:main' into nomicbert
bhavika Jun 27, 2024
e10b3e1
Stray space
bhavika Jun 27, 2024
773c567
Merge remote-tracking branch 'refs/remotes/origin/nomicbert' into nom…
bhavika Jun 27, 2024
4004ec6
Merge remote-tracking branch 'origin/main' into nomicbert
bhavika Jun 27, 2024
506735b
grammar
bhavika Jul 13, 2024
0dea6cd
Add nomic-bert repo
bhavika Jul 13, 2024
f906442
minor grammar fix
bhavika Jul 13, 2024
5ca630e
Remove nomic-bert from tests because we dont have a small version
bhavika Jul 15, 2024
801787b
Add nomic-bert to unsuppored list
bhavika Jul 15, 2024
b25bf32
Remove from unsupported
bhavika Jul 15, 2024
fe38265
Update tests to exclude nomic in tests
bhavika Jul 17, 2024
7f6a562
Modify test-custom-model
bhavika Jul 17, 2024
3fe0e46
Remove debugging statement
bhavika Jul 17, 2024
6252618
Formatting
bhavika Jul 17, 2024
ac533ca
Merge branch 'main' into nomicbert
bhavika Jul 17, 2024
dc948c6
Formatting with black
bhavika Jul 19, 2024
1b26f3f
Ruff formatting
bhavika Aug 4, 2024
35f5ea2
Remove nomic-bert as a supported arch
bhavika Aug 4, 2024
0b6aa14
Fix formatting
bhavika Sep 22, 2024
cdbf5f2
Merge branch 'huggingface:main' into nomicbert
bhavika Oct 21, 2024
974e625
Run black
bhavika Oct 21, 2024
955fb15
Remove test file
bhavika Oct 21, 2024
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
4 changes: 2 additions & 2 deletions optimum/commands/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion optimum/exporters/onnx/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions optimum/exporters/onnx/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ def inputs(self) -> Dict[str, Dict[int, str]]:
}


class NomicBertOnnxConfig(BertOnnxConfig):
DEFAULT_ONNX_OPSET = 14


class AlbertOnnxConfig(BertOnnxConfig):
DEFAULT_ONNX_OPSET = 11

Expand Down
3 changes: 2 additions & 1 deletion optimum/exporters/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,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",
Expand Down Expand Up @@ -1152,7 +1153,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
Expand Down
1 change: 1 addition & 0 deletions optimum/utils/normalized_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ class NormalizedConfigManager:
"mpt": MPTNormalizedTextConfig,
"mt5": T5LikeNormalizedTextConfig,
"m2m-100": BartLikeNormalizedTextConfig,
"nomic-bert": NormalizedTextConfig,
"nystromformer": NormalizedTextConfig,
"opt": NormalizedTextConfig,
"pegasus": BartLikeNormalizedTextConfig,
Expand Down
4 changes: 4 additions & 0 deletions tests/exporters/exporters_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@
"stable-diffusion-xl": "echarlaix/tiny-random-stable-diffusion-xl",
}

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"],
Expand Down
30 changes: 30 additions & 0 deletions tests/exporters/onnx/test_exporters_onnx_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
PYTORCH_TIMM_MODEL,
PYTORCH_TIMM_MODEL_NO_DYNAMIC_AXES,
PYTORCH_TRANSFORMERS_MODEL_NO_DYNAMIC_AXES,
PYTORCH_REMOTE_CODE_MODELS
)


Expand Down Expand Up @@ -730,3 +731,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,
)
5 changes: 4 additions & 1 deletion tests/exporters/onnx/test_onnx_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
PYTORCH_EXPORT_MODELS_TINY,
PYTORCH_SENTENCE_TRANSFORMERS_MODEL,
PYTORCH_STABLE_DIFFUSION_MODEL,
PYTORCH_REMOTE_CODE_MODELS,
PYTORCH_TIMM_MODEL,
TENSORFLOW_EXPORT_MODELS,
VALIDATE_EXPORT_ON_SHAPES_SLOW,
Expand Down Expand Up @@ -197,7 +198,8 @@ def _onnx_export(
return

onnx_config = onnx_config_class_constructor(model.config)

print("Got this ONNX config")
print(onnx_config)
bhavika marked this conversation as resolved.
Show resolved Hide resolved
# We need to set this to some value to be able to test the outputs values for batch size > 1.
if (
isinstance(onnx_config, OnnxConfigWithPast)
Expand Down Expand Up @@ -323,6 +325,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}")
Expand Down
3 changes: 2 additions & 1 deletion tests/onnxruntime/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,7 @@ class ORTModelForFeatureExtractionIntegrationTest(ORTModelTestMixin):
"mpnet",
"roberta",
"xlm_roberta",
"nomic-bert"
]

FULL_GRID = {"model_arch": SUPPORTED_ARCHITECTURES}
Expand Down Expand Up @@ -4703,7 +4704,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,
Expand Down