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

Support Mistral #62

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions MODELS.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ Does not work with flexible sequence length and therefore does not support `use_
- ✅ GPT2ForTokenClassification
- ⚠️ GPT2LMHeadModel (no `use_past`)

**Llama**

- ✅ LlamaForCausalLM

**M2M100**

- ⚠️ M2M100Model (currently supports only `use_past=False`)
Expand All @@ -132,6 +136,10 @@ Does not work with flexible sequence length and therefore does not support `use_
- ? MarianForCausalLM
- ⚠️ MarianMTModel (currently supports only `use_past=False`)

**Mistral**

- ✅ MistralForCausalLM

**MobileBERT**

- ✅ MobileBertModel
Expand Down
6 changes: 6 additions & 0 deletions src/exporters/coreml/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ class FeaturesManager:
"text2text-generation",
coreml_config_cls="models.marian.MarianMTCoreMLConfig",
),
"mistral": supported_features_mapping(
"feature-extraction",
"text-generation",
"text-classification",
coreml_config_cls="models.mistral.MistralCoreMLConfig",
),
"mobilebert": supported_features_mapping(
"feature-extraction",
"fill-mask",
Expand Down
18 changes: 18 additions & 0 deletions src/exporters/coreml/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,24 @@ class MarianMTCoreMLConfig(CoreMLConfig):
modality = "text"


class MistralCoreMLConfig(CoreMLConfig):
modality = "text"

def patch_pytorch_ops(self):
# Workaround for https://github.com/apple/coremltools/pull/2017
def log(context, node):
from coremltools.converters.mil import Builder as mb
from coremltools.converters.mil.mil import types

a = context[node.inputs[0]]
if types.is_int(a.dtype):
a = mb.cast(x=a, dtype="fp32")
x = mb.log(x=a, name=node.name)
context.add(x)

return {"log": log}


class MobileBertCoreMLConfig(CoreMLConfig):
modality = "text"

Expand Down