Open yqrickw20 opened 1 year ago
Based on my experiments, I also tried to export the model by using following command.
python -m exporters.coreml --model=sentence-transformers/all-MiniLM-L6-v2 --feature=next-sentence-prediction exported/
It works fine which gives me following info.
Some weights of BertForNextSentencePrediction were not initialized from the model checkpoint at sentence-transformers/all-MiniLM-L6-v2 and are newly initialized: [‘cls.seq_relationship.bias’, ‘cls.seq_relationship.weight’]
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
Using framework PyTorch: 1.12.1
Overriding 1 configuration item(s)
- use_cache -> False
Tuple detected at graph output. This will be flattened in the converted model.
Converting PyTorch Frontend ==> MIL Ops: 0%| | 0/338 [00:00<?, ? ops/s]Core ML embedding (gather) layer does not support any inputs besides the weights and indices. Those given will be ignored.
Converting PyTorch Frontend ==> MIL Ops: 99%|█████████████████████████████████████▊| 336/338 [00:00<00:00, 4477.15 ops/s]
Running MIL Common passes: 0%| | 0/40 [00:00<?, ? passes/s]/Users/t_wangyu/miniconda3/envs/coremltools-env/lib/python3.10/site-packages/coremltools/converters/mil/mil/passes/name_sanitization_utils.py:135: UserWarning: Output, ‘548’, of the source model, has been renamed to ‘var_548’ in the Core ML model.
warnings.warn(msg.format(var.name, new_name))
Running MIL Common passes: 100%|████████████████████████████████████████████████████| 40/40 [00:00<00:00, 148.28 passes/s]
Running MIL Clean up passes: 100%|██████████████████████████████████████████████████| 11/11 [00:00<00:00, 115.80 passes/s]
Validating Core ML model...
- Core ML model is classifier, validating output
-[✓] predicted class ‘LABEL_1’ matches ‘LABEL_1’
-[✓] number of classes 2 matches 2
-[✓] all values close (atol: 0.0001)
All good, model saved at: exported/Model.mlpackage
However, it seems that the converted model is a classifier which does not meets my requirement.
When you convert the model without specifying --feature=...
, it uses the "default" task. That seems like what you'd want here, but this does not add the token_type_ids
input to the model.
Try the following to remove token_type_ids
from the inputs before calling the Core ML model:
cml_inputs = {k: v.to(torch.int32).numpy() for k, v in encoded_input.items()}
del cml_inputs["token_type_ids"]
pred_coreml = mlmodel.predict(cml_inputs)
Description
Hi, I encounter following error when exporting sentence-tranformers/all-MiniLM-L6-v2 (a pytroch model) to a Coreml model.
python -m exporters.coreml --model=sentence-transformers/all-MiniLM-L6-v2 exported/
The problem is similar to the problem mentioned in #9. I also tried to use the workaround to fix the problem. However, I got following error when I tried to do the prediction. Note that, "Model.mlpackage" is obtained by using above command.
What I got is following error
KeyError: 'Provided key "token_type_ids", in the input dict, does not match any of the model input name(s), which are: input_ids,attention_mask'