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

Fix emb model export and load with trfrs #756

Merged
merged 3 commits into from
Jan 9, 2025
Merged

Conversation

JingyaHuang
Copy link
Collaborator

What does this PR do?

Fixes #744

With the PR, we should be once again able to export embedding model via transformers library or sentence transformer library depending on the class called:

  • With Transformers
import torch
from optimum.neuron import NeuronModelForFeatureExtraction
from transformers import AutoConfig, AutoTokenizer

compiler_args = {"auto_cast": "matmul", "auto_cast_type": "fp16"}
input_shapes = {"batch_size": 4, "sequence_length": 512}
model = NeuronModelForFeatureExtraction.from_pretrained(
    model_id="TaylorAI/bge-micro-v2", # BERT SMALL
    export=True,
    disable_neuron_cache=True,
    **compiler_args,
    **input_shapes,
)
  • With Sentence Transformers
import torch
from optimum.neuron import NeuronModelForSentenceTransformers
from transformers import AutoConfig, AutoTokenizer

compiler_args = {"auto_cast": "matmul", "auto_cast_type": "fp16"}
input_shapes = {"batch_size": 4, "sequence_length": 512}
model = NeuronModelForSentenceTransformers.from_pretrained(
    model_id="TaylorAI/bge-micro-v2", # BERT SMALL
    export=True,
    disable_neuron_cache=True,
    **compiler_args,
    **input_shapes,
)

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@JingyaHuang JingyaHuang requested a review from dacorvo January 9, 2025 12:26
Copy link
Collaborator

@dacorvo dacorvo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks ! We got hub errors on some of the CI jobs, but it is completely unrelated.

@JingyaHuang JingyaHuang merged commit fe71b3c into main Jan 9, 2025
7 of 10 checks passed
@JingyaHuang JingyaHuang deleted the fix-emb-model-with-trfrs branch January 9, 2025 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loading compiled fails: model_type=bert -> transformers being used in compiled config.
3 participants